Alarm

download Alarm

of 4

description

Alarm Subroutine

Transcript of Alarm

  • //----------------------------------------------//Variables declerationconst 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 Wunsigned char tord,i;signed char tset[8]; //Used while setting timeunsigned 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 valid

    //----------------------signed char aset[4];//variable to store number of alarms entered by user 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 errorsbeginn: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 sets which alarm no u r settingwhile(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 minutes stringcase 2 : {LCD_gotoxy(1,1);LCD_string(setstring[1]);break;} //For hours stringcase 3 ://That h:m:s is setLCD_command(LCD_clear);

  • 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 EEPROMwhile(alarm_sw==0);ee_location = alarm_check[alarmc]; // Get the location of eeprom to storeEeprom_write(ee_location,hex2bcd(aset[2]));//First store hourEeprom_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 FINISHEDEeprom_write(++ee_location,rly_data);//At last sore relay data //STORING FINISHEDLCD_command(LCD_clear);LCD_string("Saved to eeprom");//Indicate it to userEeprom_write(0,alarmc);ii=0; //Mustee_location=0;aset[0]=0;aset[1]=0;aset[2]=0;rly_data=1;rly_no=1;//Reset all registerif(alarmc>=30){LCD_command(LCD_clear);LCD_string("Alarms Excedded");DelayS(2);goto finish;}//TO CHECK MAXIMUM ALARMS SETgoto beginn;

    }//SWITCH}//IF LOOP OF ALARM SW BUTTON

    if(time_sw==0){while(time_sw==0);//wait to release the switchfinish: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]--)

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

    }// WHILE 1 LOOPwhile(1);////////////////////////

    }

    //----------------------------------------------//PROCEDURE TO SET TIME//----------------------------------------------void set_time(){char week;

    while(time_sw==0); //FOR user errorsLCD_command(LCD_clear); //Clear the lcdLCD_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 firsttord=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 points to minutes register

    switch(i){case 1 : {LCD_gotoxy(1,1);LCD_string(setstring[0]);break;} //For minutes indicating i.e for above linecase 2 : {LCD_gotoxy(1,1);LCD_string(setstring[1]);break;} //For hours indicatingcase 4 : {LCD_gotoxy(1,1);LCD_string(setstring[2]);break;} //For month indicatingcase 5 : {LCD_gotoxy(1,1);LCD_string(setstring[3]);break;} //For minutes indicating

  • case 3 : //Set time and display date settingLCD_command(LCD_clear); //Clear the LCDrtc_settime(hex2bcd(tset[2]),hex2bcd(tset[1]),hex2bcd(tset[0]));LCD_string("Time is Set");DelayBigMs(1000);LCD_command(LCD_clear); //Clear the LCDLCD_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 invalidtord=1;break; //This is for datecase 6 : //Set Date and returnLCD_command(LCD_clear); //Clear the LCDLCD_string("Set week=");LCD_gotoxy(14,1);LCD_string(week_strings[tset[i]]);tord=0; //Because week is 0 to 6week=1;break;case 7 : //For weekLCD_command(LCD_clear); //Clear the LCDrtc_setdate(hex2bcd(tset[3]),hex2bcd(tset[4]),hex2bcd(tset[5]),tset[6]); //10:12:02(yy:mm:dd),weekLCD_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 for date cause date cant start from 0if(week==1){LCD_gotoxy(14,1);LCD_string(week_strings[tset[i]]);}//Point to particular week stringelse{LCD_timeset(hex2bcd(tset[i]),LCD_position[i]);}} //First increment seconds and so on

    //------------if(down_sw==0){if((tset[i]--)