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.

Timer 0 and Timer 1 of the AT89S52

Status
Not open for further replies.

Ogu Reginald

Full Member level 6
Joined
Oct 7, 2011
Messages
369
Helped
46
Reputation
92
Reaction score
45
Trophy points
1,308
Location
Nigeria
Activity points
3,391
I want to use either Timer0 or Timer1 of the AT89S52 microcontroller to measure external pulse. While reading, I came across an example that tries to set up timer0.

The example is using a frequency of 24MHz.
Below is a part of the code.
TMOD=0x52; // timer 0 mode 2, counter 1 mode 1
THO=5;//makes the timer to overflow every 125 uS (divide by 250).

Please can someone help me and explain the two lines above.
If there are equations to help me, please attach. I want the timer to reload every second and I want to use 12MHz.
If I want to use Timer 1 Mode 2, what will I use.
 

Ogu Reginald

Full Member level 6
Joined
Oct 7, 2011
Messages
369
Helped
46
Reputation
92
Reaction score
45
Trophy points
1,308
Location
Nigeria
Activity points
3,391
Thank you very much.
I will upload the code I am writing after reading and watching the video very soon.
 

Ogu Reginald

Full Member level 6
Joined
Oct 7, 2011
Messages
369
Helped
46
Reputation
92
Reaction score
45
Trophy points
1,308
Location
Nigeria
Activity points
3,391
This a part of my entire code.
The timer 1 is intended to generate a 1sec delay,
during the 1 sec delay,
timer 0 will be counting the frequency of the pulse connected to it.
When TF1 is raised (after 1 sec),
The number of pulse (frequency) is displayed on an LCD.
Please don't bother on the timer0 and display sub programs, they have been well written.
My concern and problem is to generate 1 sec delay (I don't know the exact value to load to the TL1 and TH1).
Please carefully check the code for me, Thanks.
Below is the code:

Timer1 ()
{
TR1=0;
TMOD &=0x01; // timer 1 set to mode 1
TL0=0x00;
TH0=0x00;
TF1=0;
TR1=1;
while (TF1==0)
{
timer0 (); //count the frequency of the pulse connected timer 0
}
if (TF1==1)
{
Display (); //displays the d (d= Frequency/7)
}
}
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top