Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Hello sir..need help to finish my program about Timers using MicroC..in PIC16F877A..

Status
Not open for further replies.

UyAb

Junior Member level 2
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
Visit site
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..

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();
}
 

the first one is for the first digit for the hours,the second is for the tens-digit minutes(as you can see there are just 0-5),and the third is for the ones-digit minutes..

- - - Updated - - -

the first one is for the first digit for the hours,the second is for the tens-digit minutes(as you can see there are just 0-5),and the third is for the ones-digit minutes..
 

Yes sir, I already did that..my problem now is how to automatically display the time every time it changes..every minute actually..
I think I need sample codes or something I can compare my program with..a guide,or something..

- - - Updated - - -

sorry sir,I miss read your reply..yes,I also did that..I used 3 keypad routines to control the input for every digits..
I don't know how to do it in just ones routine,that's why I used 3..
But if you know how to do so,can you please show me the codes for that?
Please bare with me sir for I am just a newbie in programming..
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top