0% found this document useful (0 votes)
44 views9 pages

Timers

The document discusses timers in the 8051 microcontroller. It describes that the 8051 has two 16-bit timers, timer 0 and timer 1. It explains the TMOD and TCON registers that are used to configure the timers and their modes. The document outlines the steps to use a timer, which includes loading the TMOD register, loading a value into TH and TL, starting the timer, monitoring the flag, clearing the flag, and repeating. It provides an example code to generate a delay using timer 1.

Uploaded by

Praveen Singh
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views9 pages

Timers

The document discusses timers in the 8051 microcontroller. It describes that the 8051 has two 16-bit timers, timer 0 and timer 1. It explains the TMOD and TCON registers that are used to configure the timers and their modes. The document outlines the steps to use a timer, which includes loading the TMOD register, loading a value into TH and TL, starting the timer, monitoring the flag, clearing the flag, and repeating. It provides an example code to generate a delay using timer 1.

Uploaded by

Praveen Singh
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Timers in 8051

Contents
About timers.

Registers regarding timers.

Modes of timer.

Steps to use a timer.


Timers
Timers are used

1.To generate time delay.


2.To generate baud rate.
3.To count an event(timer as a counter).
In 8051 we have two Timers.

1.Timer 0 16 bit
2. Timer 1 16 bit
TMOD Register:

• Gate : When set, timer only runs while INT(0,1) is high.


• C/T : Counter/Timer select bit.

• M1 : Mode bit 1.
• M0 : Mode bit 0.
TCON Register:

• TF1: Timer 1 overflow flag.


• TR1: Timer 1 run control bit.
• TF0: Timer 0 overflag.
• TR0: Timer 0 run control bit.
• IE1: External interrupt 1 edge flag.
• IT1: External interrupt 1 type flag.
• IE0: External interrupt 0 edge flag.
• IT0: External interrupt 0 type flag.
Steps to use Timers:-

1.Load TMOD register


(to select particular timer in particular mode).
2.Load the value in TH and TL.
3.Start Timer (TR = 1).
4.Monitor timer flag.
5.Clear timer flag.
6.Repeat 3rd step.
/**delay with timers **/

#include<reg51.h>

void timerdelay_delay()
void main()
{
{
TMOD=0x60;
TH1=0xf1;
P0=0x00;
TL1=0x03;
timer_delay();
TR1=1;
P0=0xff;
while(TF==0);
timer_delay();
TR1=0;
}
}
}

You might also like