8051 timer de
TRANSCRIPT
-
8/3/2019 8051 timer DE
1/12
ED501/801 1
8051 Timers
Design Exercise
-
8/3/2019 8051 timer DE
2/12
ED501/801 2
Timer Registers
TL0 Timer0 low byte
TH0 Timer0 high byte
TL1 Timer1 low byte
TH1 Timer1 high byte
TMOD Timer Mode Register
-
8/3/2019 8051 timer DE
3/12
ED501/801 3
TMOD Register
Lower 4bits for timer0 & upper 4bits for timer1
In each case lower 2 bits to specify timer mode &
upper 2 bits to specify the operation
GATE:- Gating control (h/wor s/w control) C/T:- Timer or Counter operation
M0:- Mode bit0
M1:- Mode bit1
-
8/3/2019 8051 timer DE
4/12
ED501/801 4
TMOD Register
Gate= 0 Timer is enabledwhen TRx bit is set (SETB TR0)
Gate= 1 Timer is enabledonly while the INTx pin is high and
TRx control pin is set
C/T= 0-Timer Operation
C/T= 1-Counter Operation
M1 M0
0 0 -Mode0
0 1 -Mode1
1 0 -Mode2
1 1 -Mode3
-
8/3/2019 8051 timer DE
5/12
ED501/801 5
Timer in Mode-1 Programming Steps
Load TMOD register with value for selecting mode1 of timer0 or
timer1 or both
Load TL and TH with initial values
Start timer (SETB TR0, TR1)
Incase of polling
Keep Monitoring Timer Status
If Flag is high
Reload TL and TH
Else Keep Monitoring Timer Status
Incase of interrupt
Configure for interrupt detection and service (Configure IE)
wait in infinite loop
If interrupted
Reload TL and TH & return
-
8/3/2019 8051 timer DE
6/12
ED501/801 6
Finding values to be loaded into Timer
1. Convert the time to microsecond range. Divide the
desired time by 1 microseconds (12 MHz) or 1.085
microseconds (11.0592 MHz usedwith SBC-51)
and set it as n2. If the value is less than 16 bit maximum value then
perform 65536-n
3. Convert result of step2 to hex
4. Set TL=xx and TH=yy,where the result of step3 isyyxx
-
8/3/2019 8051 timer DE
7/12
Finding values to be loaded into Timer
For example if 50 milliseconds delay is
required then
Convert to microseconds (50 x1000) = 50000 s Divide by 1.085 s = 46083
65536- 46083 = 19453
Convert 19453 to hex -> 4BFD
TH0 = 4B and TL0 = FD
ED501/801 7
-
8/3/2019 8051 timer DE
8/12
ED501/801 8
Mode-0 Programming
Same as Mode1 except that it is a 13-bit timer instead
of 16-bit
13-bit can hold values up to 1FFFH
When timer reaches 1FFFH it rolls over to 0000H
TF flag is set or overflow interrupt will be occurring
at this event
-
8/3/2019 8051 timer DE
9/12
ED501/801 9
Mode2 Programming
It is a 8-bit Timer
allows values up to FFH to be loaded into TH register
Load the TMOD value register indicating which timer
is to be used, and the timer mode is selected
Load TH register with the initial count value
Start the timer (SETB TRx)
Keep monitoring TF or wait for interrupt
-
8/3/2019 8051 timer DE
10/12
ED501/801 10
; one second delay counter
org 8000h
start: mov tmod,#01h ;timer 0 mode 1 setup
mov a,#00hmov r0,#00h
mov ie,#82h
setb tr0 ;set tcon register( tr0=1)
back: sjmp back
-
8/3/2019 8051 timer DE
11/12
ED501/801 11
t_isr:
Loop1: inc r0
cjne r0,#0bh,rtnmov dptr,#7e00h
movx @dptr,a
inc a
mov r0,#00h
cjne a,#0ah,rtn
mov a,#00h
rtn: setb tr0
reti
org 0ffe4h
ljmp t_isr end
-
8/3/2019 8051 timer DE
12/12
I request Electronics and communication
ENGINEERING students to visit my blog
for more
abhishek1ek.blogspot.com
awhengineering.blogspot.com
ED501/801 12