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.

How to use time0 as event counter on AT89S52 ?

Status
Not open for further replies.

bianchi77

Advanced Member level 4
Advanced Member level 4
Joined
Jun 11, 2009
Messages
1,313
Helped
21
Reputation
44
Reaction score
20
Trophy points
1,318
Location
California
Visit site
Activity points
9,442
Guys,

How can I use timer0 on AT89S52 as event counter ?
Is it related with interrupt ?

I have made some configuration but it doesn't work yet ?
Is my input voltage too low ?
I got 1.7V for high level on it...

Any ideas will be appreaciated,

Thanks a lot
 

Guys,

How can I use timer0 on AT89S52 as event counter ?
Is it related with interrupt ?

I have made some configuration but it doesn't work yet ?
Is my input voltage too low ?
I got 1.7V for high level on it...

Any ideas will be appreaciated,

Thanks a lot

hai there,

I uploaded your code with correction with proteus design, check with that

thank you,
 

Attachments

  • Counter.rar
    33.9 KB · Views: 92

I did :
Code:
sbit counter_input=P3^4;	 //input pulse from op-amp

void init_timer()
{
	TL0=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;
}

void main() //main program

{ 
unsigned char serial_char;

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

It's displaying a value alredy on LCD, but it's not synchronized with the input P3.4, do I missing something here ?
I want to display per second and then per minute ? Do I need interrupt for it ? how to use it ?

Thanks
 
Last edited:

update :
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
Code:
 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
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top