Continue to Site

Welcome to

Welcome to our site! 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.

i want to know the usage of timer (in 89s52) @ keil

Not open for further replies.


Advanced Member level 5
Jan 7, 2010
Reaction score
Trophy points
Activity points
Hi experts , I want to know the usage of timer / counter (am using keil) .i had already readed the basics of timer /counter .that is TH,TL ,tmod gate etc .But i dont know how it can use please help me throug examples written i C .thank in advance

1. write a simple program to monitor the timer interrupt and when timer interrupt occurs write an ISR routing and toggle a port pin....

or when timer overflows write a code to transmit the data...

disable the ISR and again when it enters disable the port pin which was enabled in the previous ISR routine.......

2. Write an program to transmit an data.. run the tmer and transmit the data from UART.. then when timer overflow then stop the transmission of data and again transmit the data after you exit ISR of timer...

but what you want to achieve by doing this,,,

Its better you do blinking of LED on hardware using timer interrupt...
yes sir i actually need it , sir can you provide some simple example to understand the same

Any body give the sample program to blink the Led by using timer with explanation

void delay() // Delay generation using Timer 0 mode 1
TMOD = 0x01; // Mode1 of Timer0
TH0= 0xFC; // FC66 evaluated hex value for 1millisecond delay
TL0 = 0x66;
TR0 = 1; // Start Timer
while(TF0 == 0); // Using polling method
TR0 = 0; // Stop Timer
TF0 = 0; // Clear flag
Any please describe the above program 's working
TMOD = 0x01; //what happens ? please explain

Have you read the datasheet of your mcu?
It is the most useful thing you can read, the meaning of every register and peripheral operation is explained there.

Hi finally i got .
TMOD means .It decides the source of clock for the timer. it has certain register which decide the working of timer see Ali Mazdi's text page number 255.
to take Timer we need to clear it first that is TR0 (one of the timer in 8051) ie TR0 =0000h;
in .ASM it is ,SETB TR0 .(0000h)
The timer register value counts up or increase in accordance with its machine cycle that is 0001,0010,0011 (binary)etc
atlast it will reach FFFF again it go to 0000h while the flag register will set ,so we can count TF register as a counter or else .

Not open for further replies.

Part and Inventory Search

Welcome to