89S52 countdown timer

Status
Not open for further replies.

mentoz

Junior Member level 1
Joined
Nov 25, 2012
Messages
15
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,366
I want to build a countdown timer using 89s52 set by 3x4 keypad and display it in LCD, but I don't have idea how to build so that the timer will decrement every 1second.. I already

can anyone help me in to program in C code especially with Keil..
thanks..
 

LCD and 3X4 key pad interfacing and programming is ready, tested and working ??
If so make a delay routine for one second. if Timer is used, nested loop calling will be needed, even otherwise, time wasting routines will also require nested loops. The delays generated in either case will depend on the crystal frequency used and thus on the machine cycle.
 

hi,

void Timer0_ISR() interrupt 1
{
TF0 = 0;
if(count>0)
{
count = 1000;
downcounter--;
}
if(downcounter<=0)
{
downcounter=0;
count = 0;
}
TR0 = 1;
// consider timer is for 1 msec
}

regards
Sreekanth
 
Reactions: mentoz

    mentoz

    Points: 2
    Helpful Answer Positive Rating
How about the main body? I already built something like this

TMOD=0x01;
EA=0;
TH0=50621/256;TL0=50621%256;
ET0=1;
EX0=1;
IT0=1;
PX0=1;
TF0=0;
EA=1;
//TR0=1;

countvalue=300; //initial count value

int input,hours,minutes,seconds;
col1=col2=col3=1;
out=0;
lcd_cmd(0x38);
lcd_cmd(0x0e);
lcd_cmd(0x01);
delay(100);

count=0;
lcd_cmd(0x01);
lcd("Enter time interval(second):");
lcd_cmd(0xc5);
check=0;
digit[0]=0;
digit[1]=0;
digit[2]=0;
while(check!=10)
{
row1=row2=row3=row4=0;
while(col1==1 && col2==1 && col3==1);
keypad();
}
time=(digit[0]+(digit[1]*10)+(digit[2]*100));
lcd_cmd(0xc4);
lcd_cmd(0x01);
lcd(time);
delay(100);
lcd_cmd(0x01);
lcd("counting down ...");
time--;

is there something wrong??
thanks
 

I am working on a similar project, but i use 7 seg display for the digits.
I used min2, min1, sec2, sec1 as variables for my timer(mm:ss). First i initialized all the val = 0. I have a funtion for incrementing the val when a button is pressed. If the val are not = 0 the countdown starts.
Code:
if ( (min2 != 0) || (min1 != 0) || (sec2 != 0) || (sec1 != 0)) // checks if modification are made to the initial values
        {
        countdown(); // start countdown  
        }

and the countdown():
Code:
void countdown(void)  // the countdown
{
  while ( min2 >= 0)
  {
    while (min1 >= 0)
    {
      while (sec2 >= 0)
      {
        while ( sec1 >=0)
        {
          sec1--;
          delay_1s();//one second delay
          if(sec1 == 0) break;
         }
	sec2--;
	if((sec1 == 0) && (sec2 == 0)) break;
        sec1 = 9;
       }
       min1--;
       if((min1 == 0) && (sec1 == 0) && (sec2 == 0)) break;
       sec2 = 5;
      }
      min2--;
      if((min2 == 0) && (min1 == 0) && (sec1 == 0) && (sec2 == 0)) break;
      min1 = 9;
    }
}

I hope it helps you.
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…