Вы находитесь на странице: 1из 4

//---------------------------------------------//Variables decleration

const unsigned char LCD_position[] = {7,4,1,9,4,1}; //that is 1=S,2=S, 3=:, 4=


M,5=M, 6=:, 7=H,8=H
const unsigned char tcompare[]= {59,59,23,99,12,31,6};
//S:M:H Y:M:D W
unsigned char tord,i;
signed char tset[8];
//Used while setting time
unsigned char alarm_check[] = {255,1,6,11,16,21,26,31,36,41,46,51,56,61,66,71,76
,81,86,91,96,101,106,111,116,121,126,131,136,141,146,151,156}; //255 is not vali
d
//---------------------signed char aset[4];//variable to store number of alarms entered
unsigned char ii;
//---------------------------------------------//PORT PIN DEFINITIONS
//---------------------------------------------//Definitions
#define up_sw
RD0
#define down_sw
RD1
#define time_sw
RD2
#define alarm_sw
RA4
#define alarm_onoff RD4
#define Relay1
RA0
#define Relay2
RA1
#define Relay3
RA2
#define Relay4
RA3
#define Relay5
RD3
#define Relay6
RA5
#define Relay7
RD5
#define Relay8
RD6
//--------------------------------------------//PROCEDURE TO SET ALARM
//--------------------------------------------void set_alarm()
{
unsigned char rly_no=1,rly_data=1,ee_location=0,alarmc=0;
while(alarm_sw==0);//To prevent errors
beginn:
alarmc++;
LCD_command(LCD_clear);
LCD_string(" : :SS AN:");
LCD_gotoxy(3,2);LCD_data(':');//This os for symbols//////////
LCD_gotoxy(6,2);LCD_data(':');
//////////
LCD_timeset(0x00,1);//This is for starting numbers//////////
LCD_timeset(0x00,4);
//////////
LCD_timeset(0x00,7);
/////////
LCD_gotoxy(15,1);LCD_send_packedbcd(hex2bcd(alarmc));//This line
m no u r setting
while(1) //WHILE 1
{
if(alarm_sw==0) //MAIN ALARM SW MONITORING
{while(alarm_sw==0);//Wait for release of button
++ii ;//because first itself ii will be 0;
switch(ii)
{
case 1 : {LCD_gotoxy(1,1);LCD_string(setstring[0]);break;} //For
case 2 : {LCD_gotoxy(1,1);LCD_string(setstring[1]);break;} //For
case 3 ://That h:m:s is set
LCD_command(LCD_clear);

by user

sets which alar

minutes string
hours string

LCD_string("Relay No= ");LCD_send_packedbcd(rly_no);LCD_gotoxy(1,2);


LCD_string("Status= ");LCD_string(rlyonoff[rly_data]);
while(alarm_sw==1) //WHILE 2 //LOOP UNTILL ALARM_SW IS PRESSED BY USER
{
if(down_sw==0)
{while(down_sw==0);
if(rly_data==0){rly_data=1;}else{rly_data=0;}
LCD_gotoxy(9,2);
LCD_string(rlyonoff[rly_data]);
}
if(up_sw==0)
{while(up_sw==0);
if((++rly_no)>8){rly_no=1;}
LCD_gotoxy(11,1);
LCD_send_packedbcd(rly_no);
}
}//WHILE 2
//TO STORE DATA TO EEPROM
while(alarm_sw==0);
ee_location = alarm_check[alarmc]; // Get the location of eeprom to store
Eeprom_write(ee_location,hex2bcd(aset[2]));//First store hour
Eeprom_write(++ee_location,hex2bcd(aset[1]));
Eeprom_write(++ee_location,hex2bcd(aset[0]));
Eeprom_write(++ee_location,rly_no);//At last sore relay data //STORING FINISHED
Eeprom_write(++ee_location,rly_data);//At last sore relay data //STORING FINISHE
D
LCD_command(LCD_clear);LCD_string("Saved to eeprom");//Indicate it to user
Eeprom_write(0,alarmc);
ii=0; //Must
ee_location=0;
aset[0]=0;aset[1]=0;aset[2]=0;rly_data=1;rly_no=1;//Reset all register
if(alarmc>=30){LCD_command(LCD_clear);LCD_string("Alarms Excedded");DelayS(2);go
to finish;}//TO CHECK MAXIMUM ALARMS SET
goto beginn;
}//SWITCH
}//IF LOOP OF ALARM SW BUTTON
if(time_sw==0)
{
while(time_sw==0);//wait to release the switch
finish:
LCD_command(LCD_clear);LCD_string("Number of alarms");LCD_gotoxy(1,2);
LCD_string("is");LCD_gotoxy(5,2);
LCD_send_packedbcd(hex2bcd(eeprom_read(0)));
DelayS(1);
LCD_command(LCD_clear);
return;
}
if(up_sw==0) //MAIN UP_SW MONITORING
{
if((aset[ii]++)>=tcompare[ii]){aset[ii]=0;}
LCD_timeset(hex2bcd(aset[ii]),LCD_position[ii]);//This is for up switch
}
if(down_sw==0) //MAIN DOWN_SW MONITORING
{
if((aset[ii]--)<=0){aset[ii]=tcompare[ii];}

LCD_timeset(hex2bcd(aset[ii]),LCD_position[ii]); //This is for down switch


}
DelayMs(150);
}// WHILE 1 LOOP
while(1);////////////////////////
}
//---------------------------------------------//PROCEDURE TO SET TIME
//---------------------------------------------void set_time()
{
char week;
while(time_sw==0); //FOR user errors
LCD_command(LCD_clear);
//Clear the lcd
LCD_string(" : :SS");
LCD_gotoxy(14,1);LCD_string("Set");LCD_gotoxy(13,2);LCD_string("Time");
LCD_gotoxy(3,2);LCD_data(':');
LCD_gotoxy(6,2);LCD_data(':');
LCD_timeset(0x00,1);
LCD_timeset(0x00,4);
LCD_timeset(0x00,7);
i=0; //Set i to seconds first
tord=0;week=0;
while(1)
{
//-------------if(alarm_sw==0)
{
while(alarm_sw==0);
LCD_command(LCD_clear);
LCD_string("Time Date Not");
LCD_gotoxy(1,2);
LCD_string("Set Correctly");
DelayS(1);
LCD_command(LCD_clear);
return;} //Return with out setting alarm
//-----------if(time_sw==0)
{
DelayMs(50);
while(time_sw==0); // waits for button to be released
++i;
//Because i will already pointing to seconds register so now p
oints to minutes register
switch(i)
{
case 1 : {LCD_gotoxy(1,1);LCD_string(setstring[0]);break;}
ing i.e for above line
case 2 : {LCD_gotoxy(1,1);LCD_string(setstring[1]);break;}
g
case 4 : {LCD_gotoxy(1,1);LCD_string(setstring[2]);break;}
g
case 5 : {LCD_gotoxy(1,1);LCD_string(setstring[3]);break;}
ing

//For minutes indicat


//For hours indicatin
//For month indicatin
//For minutes indicat

case 3 : //Set time and display date setting


LCD_command(LCD_clear);
//Clear the LCD
rtc_settime(hex2bcd(tset[2]),hex2bcd(tset[1]),hex2bcd(tset[0]));
LCD_string("Time is Set");
DelayBigMs(1000);
LCD_command(LCD_clear);
//Clear the LCD
LCD_gotoxy(14,1);LCD_string("Set");LCD_gotoxy(13,2);LCD_string("Date");
LCD_gotoxy(1,1);LCD_string(" / /YY");
LCD_gotoxy(3,2);LCD_data('/');
LCD_gotoxy(6,2);LCD_string("/20");
LCD_timeset(0x01,1);
LCD_timeset(0x01,4);
LCD_timeset(0x01,9);
tset[3]=1;tset[4]=1;tset[5]=1; //Because month date and year should first be 1;
0 means invalid
tord=1;break; //This is for date
case 6 : //Set Date and return
LCD_command(LCD_clear);
//Clear the LCD
LCD_string("Set week=");
LCD_gotoxy(14,1);
LCD_string(week_strings[tset[i]]);
tord=0; //Because week is 0 to 6
week=1;break;
case 7 : //For week
LCD_command(LCD_clear);
//Clear the LCD
rtc_setdate(hex2bcd(tset[3]),hex2bcd(tset[4]),hex2bcd(tset[5]),tset[6]);
//10
:12:02(yy:mm:dd),week
LCD_string("Date is Set");
DelayBigMs(1000);
LCD_command(LCD_clear);
return;
default: break;//If nothing then break
}//SWITCH LOOP
}
//-----------if(up_sw==0)
{
if((tset[i]++)>=tcompare[i]){tset[i]=tord;} //tord can be 0 or 1 0 for time 1 fo
r date cause date cant start from 0
if(week==1){LCD_gotoxy(14,1);LCD_string(week_strings[tset[i]]);}//Point to parti
cular week string
else{LCD_timeset(hex2bcd(tset[i]),LCD_position[i]);}
} //First increment seconds and so on
//-----------if(down_sw==0)
{
if((tset[i]--)<=tord){tset[i]=tcompare[i];}
if(week==1){LCD_gotoxy(14,1);LCD_string(week_strings[tset[i]]);}
else{LCD_timeset(hex2bcd(tset[i]),LCD_position[i]);}
}
//-------------DelayMs(150);
//For user delay //For while loop
}
}//while
//------------------------------------------------

Вам также может понравиться