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