Beruflich Dokumente
Kultur Dokumente
Bit Addressable
F8
F0 B
E8
E0 ACC
D8
D0 PSW
C8
C0
B8 IP
B0 P3
A8 IE
A0 P2
98 SCON SBUF
90 P1
88 TCON TMOD TL0 TL1 TH0 TH1
80 P0 SP DPH DPL PCON
TImers:
TMOD : Timer mode.
TCON : Timer control.
TH0 : Timer 0 high byte.
TL0 : Timer 0 low byte.
TH1 : Timer 1 high byte.
TL1 : Timer 1 low byte.
Counts:
- CPU cycles (crystal/12). “Timer”.
- External input (max. half CPU rate). “Counter”.
- Timer Mode 1 :
Simple 16-bit counter.
- Timer Mode 2 :
8-bit auto-reload.
Counter in TL0 or TL1.
Reload value in TH0 or TH1.
Provides a periodic flag or interrupt.
Osc. ÷12
Interrupt
TL1 TH1 TF1
8-bits 8-bits
T1 (Pin)
Control
TR1
Gate
INT1 (Pin)
The Gate input controls whether the Counter runs while gated by the interrupt signal or not.
Timer 1 Timer 0
- TR1, TR0 : Run control bits for Timer 1 and Timer 0. Set to run, reset to hold.
- 0 = Disabled.
- 1 = Enabled.
Source Address
IE0 03H
TF0 0BH
IE1 13H
TF1 1BH
RI&TI 23H
- PS : Serial interface.
- PT1 : Timer 1.
- PX1 : External interrupt 1.
- PT0 : Timer 0.
- PX0 : External interrupt 0.
- 0 = Low priority.
- 1 = High priority.
ReadTimer: MOV ValH,TH0 ;Read initial timer high and low values.
MOV ValL,TL0
MOV A,TH0 ;Read timer high byte again.
CJNE A,ValH,ChkHigh ;Has it changed?
SJMP RTEX ;If not, first sample is OK.
Assumption: use external interrupt 0 for Note: to measure pulse low time in this
the pulse input. Use timer 0 in gated manner, the input must be inverted
mode. externally.
Assumption: use external interrupt 0 for Note: this method may entail some loss of
the pulse input. precision due to the possibility of
variable interrupt latency.
Setup: (same as previous example, but leave timer gate function turned off)
MOV TMOD,#01h ;Timer 0 in mode 1.
timer
Assumption: use any spare port bit for Note: the precision of pulses generated using
the output. this method will vary depending on the
interrupt latency of the timer interrupt.