This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to use time0 as event counter on AT89S52 ?

Guys,

I'm trying to count a pulse from T0 input on P3.4,

Here's the code :
sbit counter_input=P3^4; //input pulse from op-amp
 void init_timer()
{
   TL0=0x00;
   //TH0=0x00;

   counter_input = 1; //set it as input to read a pulse from op-amp
   counter_input = 0x00; //clear the counter

   TMOD=0x05;
   P0=0x00;
}
main :
.
.
.
unsigned int counter=0,d1,d2,d3,dx,dy,dz,x;
  lcd_ini(); //init LCD
  init_timer();//init timer0
  TR0=1;

   while (1)
    {
      counter=TL0;
      P0=TL0;
      x=counter/10;
      d1=counter%10;
      d2=x%10;
      d3=x/10;

      dx=d1+48;
      dy=d2+48;
      dz=d3+48;
   lcd_data(dx); lcd_data(dy);     lcd_data(dz);

}


I got the output already, but it's not consistent yet,
781, 881,321, 050...etc,
I tested with putting input to the sensor it's responding on the display according to the input, but...it's not yet displaying for example 000, 030, 050,090, etc...

Any ideas on this case ?
I'm abit confuse on using timer and counter ....

Thanks for the ideas

Parents Reply Children
No data