char message1[]="INSERT BARCODE";
char message2[]="WELCOME USER";
char message3[]="Enter Time(Hr/s)";
char message4[]="CLASSROOM";
char message5[]="POWER CONTROL";
char message6[]="Press * or #";
char message7[]="*:Start #:Cancel";
unsigned short kp;
char code[3],code1[1];
short i=0,h=0,m2=0,m1=0;
unsigned int delay=60000;
void enter_hours()
{
kp=0; //reset key code variable
do
kp= Keypad_Released(); //store key code in variable
while (!kp); //prepare value for output,transform key to it's ASCII value
switch(kp)
{
case 1: kp=49;break; //1
case 2: kp=50;break; //2
case 3: kp=51;break; //3
case 5: kp=52;break; //4
case 6: kp=53;break; //5
case 7: kp=54;break; //6
case 9: kp=55;break; //7
case 10: kp=56;break;//8
case 11: kp=57;break;//9
case 14: kp=48;break;//0
}
code[i]=kp;
Lcd_Chr(2,i+1,code[i]);
Lcd_Chr_Cp(':');
i++;
}
void enter_min10s()
{
kp=0; //reset key code variable
do
kp= Keypad_Released(); //store key code in variable
while (!kp); //prepare value for output,transform key to it's ASCII value
switch(kp)
{
case 1: kp=49;break; //1
case 2: kp=50;break; //2
case 3: kp=51;break; //3
case 5: kp=52;break; //4
case 6: kp=53;break; //5
case 14: kp=48;break;//0
}
code[i]=kp;
Lcd_Chr(2,3,code[i]);
i++;
}
void enter_min1s()
{
kp=0; //reset key code variable
do
kp= Keypad_Released(); //store key code in variable
while (!kp); //prepare value for output,transform key to it's ASCII value
switch(kp)
{
case 1: kp=49;break; //1
case 2: kp=50;break; //2
case 3: kp=51;break; //3
case 5: kp=52;break; //4
case 6: kp=53;break; //5
case 7: kp=54;break; //6
case 9: kp=55;break; //7
case 10: kp=56;break;//8
case 11: kp=57;break;//9
case 14: kp=48;break;//0
}
code[i]=kp;
Lcd_Chr(2,4,code[i]);
i++;
}
void select()
{
kp=0; //reset key code variable
do
kp= Keypad_Released(); //store key code in variable
while (!kp); //prepare value for output,transform key to it's ASCII value
switch(kp)
{
case 13: kp=42;break;//*
case 15: kp=35;break;//#
}
code1[i]=kp;
}
void input_time()
{
Lcd_Cmd(Lcd_Clear);
Lcd_Out(1,1,message3);
enter_hours();
enter_min10s();
enter_min1s();
delay_ms(500);
}
void display_time()
{
Lcd_Chr(2,8,h+48);
Lcd_Chr(2,9,':');
Lcd_Chr(2,10,m2+48);
Lcd_Chr(2,11,m1+48);
}
void buzzer()
{PORTC.F7=1;
delay_ms(10000);
}
void countdown_timer()
{
Lcd_Cmd(Lcd_Clear);
Lcd_Out(1,1,"Time Left:");
Lcd_Out(2,14,"H:M");
for(h=code[0]-48;h>-1;h--)
{display_time();
for(m2=code[1]-48;m2>-1;m2--)
{display_time();
for(m1=code[2]-48;m1>-1;m1--)
{display_time();
delay_ms(1000);
}
}
}
}
void main()
{ADCON1=1;
TRISA=1;
TRISC=0;
PORTA=0;
PORTC=0;
Keypad_Init(&PORTD);
Lcd_Init(&PORTB);
Preload:
Lcd_Cmd(Lcd_Clear);
Lcd_Cmd(Lcd_Cursor_Off);
Lcd_Out(1,2,message1);
delay_ms(3000);
{
do
{PORTA=0;
if(PORTA.F2==1&&PORTA.F3==1&&PORTA.F4==1)goto Start
}while(1);
}
Start:
Lcd_Cmd(Lcd_clear);
Lcd_Out(1,2,message2);
delay_ms(2000);
input_time();
Lcd_Cmd(Lcd_clear);
Lcd_Out(1,1,message6);
Lcd_Out(2,1,message7);
{
do
{
i=0;
select();
if(code1[0]==42)goto Start1
if(code1[0]==35)goto Start
}while(1);
}
Start1:
Lcd_Cmd(Lcd_Clear);
Lcd_Out(1,4,message4);
Lcd_Out(2,2,message5);
delay_ms(1500);
countdown_timer();
buzzer();
}