UyAb
Junior Member level 2
- Joined
- Mar 6, 2013
- Messages
- 20
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Location
- Tacloban City, Philippines
- Activity points
- 1,416
I'm making a timer in which I can input time using keypad and the numbers I pressed should appear in the the LCD..
And when I press ( * ),the countdown will start..Also the countdown timer should appear in the LCD..
Please help me with this..here's my code..
And when I press ( * ),the countdown will start..Also the countdown timer should appear in the LCD..
Please help me with this..here's my code..
Code:
unsigned short kp;
unsigned short cnt;
int hour_ones,min_ones,min_tens;
char code[3],code1[1],digit[3];
int i=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_minutesT()
{
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_minutesO()
{
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,"Enter Time");
enter_hours();
delay_ms(500);
enter_minutesT();
enter_minutesO();
delay_ms(1000);
}
void code_read()
{
delay_ms(20);
digit[0]=EEPROM_Read(0x00);
delay_ms(20);
digit[1]=EEPROM_Read(0x01);
delay_ms(20);
digit[2]=EEPROM_Read(0x02);
delay_ms(20);
digit[3]=EEPROM_Read(0x03);
delay_ms(20);
}
void code_write()
{
delay_ms(20);
EEPROM_Write(0x00,code[0]);
delay_ms(20);
EEPROM_Write(0x01,code[1]);
delay_ms(20);
EEPROM_Write(0x02,code[2]);
delay_ms(20);
EEPROM_Write(0x03,code[3]);
delay_ms(20);
}
void display_digits()
{
code[2]=min_ones;
code[1]=min_tens;
code[0]=hour_ones;
Lcd_Cmd(Lcd_Clear);
Lcd_Out(1,1,"Time Left:");
IntToStr(code,digit);
Lcd_Out(2,8,digit);
Lcd_Out(2,14,"H:M");
}
void countdown_timer()
{
Lcd_Cmd(Lcd_Clear);
Lcd_Out(1,1,"Time Left:");
Lcd_Out(2,8,code);
Lcd_Out(2,14,"H:M");
min_ones--;
cnt--;
Vdelay_ms(delay);
display_digits();
if(min_ones==-1)
{
min_ones=9;
min_tens--;
cnt=0;
if(min_tens==-1)
{
min_tens=9;
hour_ones--;
if(hour_ones==0&&min_tens==0&&min_ones==0)
{
PortC.f7=1;
}
}
}
}
void main()
{
Keypad_Init(&PORTD);
Lcd_Init(&PORTB);
Lcd_Cmd(Lcd_Clear);
Lcd_Cmd(Lcd_Cursor_Off);
Lcd_Out(1,2,"WELCOME USER");
delay_ms(3000);
Start:
Lcd_Cmd(Lcd_clear);
input_time();
Lcd_Cmd(Lcd_clear);
Lcd_Out(1,1,"Press * or #");
Lcd_Out(2,1,"*:Start #:Cancel");
{
do
{
i=0;
select();
if(code1[0]==42)goto Start1
if(code1[0]==35)
{
input_time();
}
}while(1);
}
Start1:
Lcd_Cmd(Lcd_Clear);
delay_ms(500);
Lcd_Out(1,4,"CLASSROOM");
Lcd_Out(2,2,"POWER CONTROL");
countdown_timer();
}