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 8051 timer in mode 0 in programming?

Status
Not open for further replies.

electroboy

Member level 5
Joined
Dec 30, 2010
Messages
86
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,879
hi,

how can i use mode 0 of timer in programming? for eg: if i want to produce a delay of 10 micro seconds in mode 0, what should i give in TH0 and TL0 registers?
please explain...
 

Re: 8051 timer in mode 0

if you only need 10 us delay, you probably can't use timer, because time to call, initiate timer, wait timer overflow and return more than 10 us. Just use very short delay sub routine, and you maybe can not get precision result if use C programming to do it.

This is example if you use 12 MHz crystal.
;12 MHz / 12 = 1 us, 1 us / cycle

........
Lcall Delay_10us ;(2 us)
........

Delay_10us:
Push Acc ;(2 us)
Nop ;(1 us)
Nop ;(1 us)
Pop Acc ;(2 us)
Ret ;(2 us)



I'm sorry, you mean 10 us just for example, right? I miss it. You can use timer mode 0. If you want to use it as timer it becomes 13-bit timer if you configure it as counter, counting will be divide by 32.
if you want to make 5 ms delay. Crystal 12 MHz, 1 us / cycle. 5 ms = 5000 cycles. 2^13 = 8192. 8192 - 5000 = 3192 = 0x0C78 = 0000 1100 0111 1000.
put 5 bit lower on TL0 and the rest on TH0.
TL0 = xxx1 1000
TH0 = 0110 0011

.......
Lcall Delay_5ms
.......

Delay_5ms:
Mov tmod,#00h ;timer 0 is as a timer mode 0
Mov Th0,#63h
Mov Tl0,#18h
Set Tr0
Jnb Tf0,$
Clr Tr0
Clr Tf0
Ret

The result is not real 5 ms delay because there are some instructions to initiate the timer. To get accurate result please calculate time of each instruction as i mention at delay_10us.

Thanks.

Arch Zone
 
Last edited:
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top