Professional Documents
Culture Documents
The 8051 Microcontroller and Embedded Systems, 2e By Muhammad Ali Mazidi, Janice Gillispie Mazidi, and Rolin D. McKinlay
2006 Pearson Education, Inc. Pearson Prentice Hall Upper Saddle River, NJ 07458
The 8051 Microcontroller and Embedded Systems, 2e By Muhammad Ali Mazidi, Janice Gillispie Mazidi, and Rolin D. McKinlay
2006 Pearson Education, Inc. Pearson Prentice Hall Upper Saddle River, NJ 07458
Figure 91
Timer 0 Registers
The 8051 Microcontroller and Embedded Systems, 2e By Muhammad Ali Mazidi, Janice Gillispie Mazidi, and Rolin D. McKinlay
2006 Pearson Education, Inc. Pearson Prentice Hall Upper Saddle River, NJ 07458
Figure 92
Timer 1 Registers
The 8051 Microcontroller and Embedded Systems, 2e By Muhammad Ali Mazidi, Janice Gillispie Mazidi, and Rolin D. McKinlay
2006 Pearson Education, Inc. Pearson Prentice Hall Upper Saddle River, NJ 07458
TMOD
Timer mode register M1, M0 : select timer modes C/T : clock / timer Gate :
1 : need an INTx to work with TRx 0 : only TRx controls the timer x
The 8051 Microcontroller and Embedded Systems, 2e By Muhammad Ali Mazidi, Janice Gillispie Mazidi, and Rolin D. McKinlay
2006 Pearson Education, Inc. Pearson Prentice Hall Upper Saddle River, NJ 07458
Figure 93
TMOD Register
The 8051 Microcontroller and Embedded Systems, 2e By Muhammad Ali Mazidi, Janice Gillispie Mazidi, and Rolin D. McKinlay
2006 Pearson Education, Inc. Pearson Prentice Hall Upper Saddle River, NJ 07458
Table 92
The 8051 Microcontroller and Embedded Systems, 2e By Muhammad Ali Mazidi, Janice Gillispie Mazidi, and Rolin D. McKinlay
2006 Pearson Education, Inc. Pearson Prentice Hall Upper Saddle River, NJ 07458
Ex. 9.2
Find the timers clock frequency and its period for various 8051-based systems with the following crystal frequencies (a) 12 MHz (b) 16 MHz (c) 11.0592 MHz
2006 Pearson Education, Inc. Pearson Prentice Hall Upper Saddle River, NJ 07458
The 8051 Microcontroller and Embedded Systems, 2e By Muhammad Ali Mazidi, Janice Gillispie Mazidi, and Rolin D. McKinlay
NOTE:
The 8051 timers use 1/12 of XTAL frequency, regardless of machine cycle time.
The 8051 Microcontroller and Embedded Systems, 2e By Muhammad Ali Mazidi, Janice Gillispie Mazidi, and Rolin D. McKinlay
2006 Pearson Education, Inc. Pearson Prentice Hall Upper Saddle River, NJ 07458
Figure 82a
The 8051 Microcontroller and Embedded Systems, 2e By Muhammad Ali Mazidi, Janice Gillispie Mazidi, and Rolin D. McKinlay
2006 Pearson Education, Inc. Pearson Prentice Hall Upper Saddle River, NJ 07458
Figure 82b
The 8051 Microcontroller and Embedded Systems, 2e By Muhammad Ali Mazidi, Janice Gillispie Mazidi, and Rolin D. McKinlay
2006 Pearson Education, Inc. Pearson Prentice Hall Upper Saddle River, NJ 07458
Mode 1
16-bit timer, values from 0000 to FFFFH After TH and TL are loaded, the timer must be started.
Done by SETB TR0 or SETB TR1
It starts to count up until FFFFH. When it rolls over from FFFFH to 0000, it sets high a flag bit called TF.
TFx can be monitored or used as an interrupt source
After TFx is set, the timer must be RELOADED for a new round ot timing.
The 8051 Microcontroller and Embedded Systems, 2e By Muhammad Ali Mazidi, Janice Gillispie Mazidi, and Rolin D. McKinlay 2006 Pearson Education, Inc. Pearson Prentice Hall Upper Saddle River, NJ 07458
The 8051 Microcontroller and Embedded Systems, 2e By Muhammad Ali Mazidi, Janice Gillispie Mazidi, and Rolin D. McKinlay
2006 Pearson Education, Inc. Pearson Prentice Hall Upper Saddle River, NJ 07458
Figure 94
The 8051 Microcontroller and Embedded Systems, 2e By Muhammad Ali Mazidi, Janice Gillispie Mazidi, and Rolin D. McKinlay
2006 Pearson Education, Inc. Pearson Prentice Hall Upper Saddle River, NJ 07458
Ex. 9-4
MOV HERE: MOV MOV CPL CALL JMP TMOD,#01
TH0,#0F2H TL0,#0FFH P1.5 DELAY HERE
DELAY: SETB TR0 AGAIN: JNB TF0, AGAIN CLR TR0 CLR TF0 RET
2006 Pearson Education, Inc. Pearson Prentice Hall Upper Saddle River, NJ 07458
The 8051 Microcontroller and Embedded Systems, 2e By Muhammad Ali Mazidi, Janice Gillispie Mazidi, and Rolin D. McKinlay
Ex. 9-5
Assume we use 11.0592 MHz as input signal, find the amount of time in the DELAY subroutine
11.0592 MHz 921.6 KHz 12 FFFFH - FFF2H =0DH (13+1)x1.085 s 15.19 s 15.19 sx2=30.38 s
2006 Pearson Education, Inc. Pearson Prentice Hall Upper Saddle River, NJ 07458
The 8051 Microcontroller and Embedded Systems, 2e By Muhammad Ali Mazidi, Janice Gillispie Mazidi, and Rolin D. McKinlay
Ex. 9-7
HERE:
AGAIN:
CLR P2.3 MOV TMOD,#01 MOV TL0,#03EH MOV TH0,#0B8H SETB P2.3 SETB TR0 JNB TF0, AGAIN JNB TF0,$ CLR TR0 CLR TF0 CLR P2.3
2006 Pearson Education, Inc. Pearson Prentice Hall Upper Saddle River, NJ 07458
The 8051 Microcontroller and Embedded Systems, 2e By Muhammad Ali Mazidi, Janice Gillispie Mazidi, and Rolin D. McKinlay
Ex. 9-7
HERE:
AGAIN:
CLR P2.3 MOV TMOD,#01 MOV TL0,#0 MOV TH0,#0 SETB P2.3 SETB TR0 JNB TF0, AGAIN JNB TF0,$ CLR TR0 CLR TF0 CLR P2.3
2006 Pearson Education, Inc. Pearson Prentice Hall Upper Saddle River, NJ 07458
The 8051 Microcontroller and Embedded Systems, 2e By Muhammad Ali Mazidi, Janice Gillispie Mazidi, and Rolin D. McKinlay
Ex. 9-9
AGAIN: BACK:
The 8051 Microcontroller and Embedded Systems, 2e By Muhammad Ali Mazidi, Janice Gillispie Mazidi, and Rolin D. McKinlay
The 8051 Microcontroller and Embedded Systems, 2e By Muhammad Ali Mazidi, Janice Gillispie Mazidi, and Rolin D. McKinlay
Ex. 9-10
Assuming Xtal=11.0592MHz Design a time delay of 5ms Create a pulse width of 5 ms on P2.3 with T0
The 8051 Microcontroller and Embedded Systems, 2e By Muhammad Ali Mazidi, Janice Gillispie Mazidi, and Rolin D. McKinlay
2006 Pearson Education, Inc. Pearson Prentice Hall Upper Saddle River, NJ 07458
Sol:
HERE:
AGAIN:
CLR MOV MOV MOV SETB SETB JNB CLR CLR CLR
P2.3 TMOD,#01 TL0,#0 TH0,#Oeeh P2.3 TR0 TF0,$ P2.3 TR0 TF0
2006 Pearson Education, Inc. Pearson Prentice Hall Upper Saddle River, NJ 07458
The 8051 Microcontroller and Embedded Systems, 2e By Muhammad Ali Mazidi, Janice Gillispie Mazidi, and Rolin D. McKinlay
Ex. 9-11
Assume XTAL=11.0592MHz Generate a square wave of 2 kHz on P1.5
The 8051 Microcontroller and Embedded Systems, 2e By Muhammad Ali Mazidi, Janice Gillispie Mazidi, and Rolin D. McKinlay
2006 Pearson Education, Inc. Pearson Prentice Hall Upper Saddle River, NJ 07458
Sol:
1. T=1/f=1/(2 kHz)=500s 2. of T is 250s 3. 250s/1.085s=230 and 65536230=65306 ( FF1AH ) 4. TL=1AH, and TH=FFH
The 8051 Microcontroller and Embedded Systems, 2e By Muhammad Ali Mazidi, Janice Gillispie Mazidi, and Rolin D. McKinlay
2006 Pearson Education, Inc. Pearson Prentice Hall Upper Saddle River, NJ 07458
Sol (cont)
AGAIN: BACK:
TMOD,#10H TL1,#1AH TH1,#0FFH TR1 TF1, BACK TR1 P1.5 TF1 AGAIN
2006 Pearson Education, Inc. Pearson Prentice Hall Upper Saddle River, NJ 07458
The 8051 Microcontroller and Embedded Systems, 2e By Muhammad Ali Mazidi, Janice Gillispie Mazidi, and Rolin D. McKinlay
Ex. 9-12
1. 2. 3. 50Hz on P2.3 with 11.0592 MHz T=1/f=1/( 50 Hz)=20 ms of T is 10 ms 10 ms/1.085s=9216 and 655369216=56320 ( DC00H ) 4. TL=00H, and TH=DCH
2006 Pearson Education, Inc. Pearson Prentice Hall Upper Saddle River, NJ 07458
The 8051 Microcontroller and Embedded Systems, 2e By Muhammad Ali Mazidi, Janice Gillispie Mazidi, and Rolin D. McKinlay
Sol
AGAIN: BACK:
TMOD,#10H TL1,#00H TH1,#0DCH TR1 TF1, BACK TR1 P2.3 TF1 AGAIN
2006 Pearson Education, Inc. Pearson Prentice Hall Upper Saddle River, NJ 07458
The 8051 Microcontroller and Embedded Systems, 2e By Muhammad Ali Mazidi, Janice Gillispie Mazidi, and Rolin D. McKinlay
Ex. 9-13
MOV TMOD, #10H MOV R3, #200 MOV TL1,#08H MOV TH1,#01H SETB TR1 JNB TF1,$ CLR TR1 CLR TF1 DJNZ R3, AGAIN
2006 Pearson Education, Inc. Pearson Prentice Hall Upper Saddle River, NJ 07458
AGAIN:
BACK:
The 8051 Microcontroller and Embedded Systems, 2e By Muhammad Ali Mazidi, Janice Gillispie Mazidi, and Rolin D. McKinlay
Sol :
TH-TL = 0108H = 264 65536-264=65272 65272 X 1.085 s = 70.82 ms 200 X 70.82 ms = 14.164024 seconds
The 8051 Microcontroller and Embedded Systems, 2e By Muhammad Ali Mazidi, Janice Gillispie Mazidi, and Rolin D. McKinlay
2006 Pearson Education, Inc. Pearson Prentice Hall Upper Saddle River, NJ 07458
Mode 2 Programming
8-bit timers TH is loaded with the beginning value, then it is COPIED to TL the moment the timer starts When TL is rolled from FFH to 00H, the starting value in TH is loaded AUTOMATICALLY to TL and the counting continues
The 8051 Microcontroller and Embedded Systems, 2e By Muhammad Ali Mazidi, Janice Gillispie Mazidi, and Rolin D. McKinlay 2006 Pearson Education, Inc. Pearson Prentice Hall Upper Saddle River, NJ 07458
Ex. 9-14
XTAL=11.0592 MHz MOV TMOD,#20H MOV TH1,#5 SETB TR1 BACK: JNB TF1,$ CPL P1.0 CLR TF1 JMP BACK
The 8051 Microcontroller and Embedded Systems, 2e By Muhammad Ali Mazidi, Janice Gillispie Mazidi, and Rolin D. McKinlay 2006 Pearson Education, Inc. Pearson Prentice Hall Upper Saddle River, NJ 07458
Ex. 9-15
MOV MOV AGAIN: MOV CALL CPL JMP
The 8051 Microcontroller and Embedded Systems, 2e By Muhammad Ali Mazidi, Janice Gillispie Mazidi, and Rolin D. McKinlay
(CONT)
DELAY: BACK: SETB JNB CLR CLR DJNZ RET TR0 TF0,$ TR0 TF0 R5,DELAY
The 8051 Microcontroller and Embedded Systems, 2e By Muhammad Ali Mazidi, Janice Gillispie Mazidi, and Rolin D. McKinlay
2006 Pearson Education, Inc. Pearson Prentice Hall Upper Saddle River, NJ 07458
Ex. 9-16
MOV MOV MOV MOV MOV TH1,#-200 TH0,#-60 TH1,#-3 TH1,#-12 TH0,#-48
The 8051 Microcontroller and Embedded Systems, 2e By Muhammad Ali Mazidi, Janice Gillispie Mazidi, and Rolin D. McKinlay
2006 Pearson Education, Inc. Pearson Prentice Hall Upper Saddle River, NJ 07458
The 8051 Microcontroller and Embedded Systems, 2e By Muhammad Ali Mazidi, Janice Gillispie Mazidi, and Rolin D. McKinlay
2006 Pearson Education, Inc. Pearson Prentice Hall Upper Saddle River, NJ 07458
Figure 95a
The 8051 Microcontroller and Embedded Systems, 2e By Muhammad Ali Mazidi, Janice Gillispie Mazidi, and Rolin D. McKinlay
2006 Pearson Education, Inc. Pearson Prentice Hall Upper Saddle River, NJ 07458
Figure 95b
The 8051 Microcontroller and Embedded Systems, 2e By Muhammad Ali Mazidi, Janice Gillispie Mazidi, and Rolin D. McKinlay
2006 Pearson Education, Inc. Pearson Prentice Hall Upper Saddle River, NJ 07458
Figure 96
The 8051 Microcontroller and Embedded Systems, 2e By Muhammad Ali Mazidi, Janice Gillispie Mazidi, and Rolin D. McKinlay
2006 Pearson Education, Inc. Pearson Prentice Hall Upper Saddle River, NJ 07458
Figure 97
The 8051 Microcontroller and Embedded Systems, 2e By Muhammad Ali Mazidi, Janice Gillispie Mazidi, and Rolin D. McKinlay
2006 Pearson Education, Inc. Pearson Prentice Hall Upper Saddle River, NJ 07458
Figure 98
Timer/Counter 0
The 8051 Microcontroller and Embedded Systems, 2e By Muhammad Ali Mazidi, Janice Gillispie Mazidi, and Rolin D. McKinlay
2006 Pearson Education, Inc. Pearson Prentice Hall Upper Saddle River, NJ 07458
Figure 99
Timer/Counter 1
The 8051 Microcontroller and Embedded Systems, 2e By Muhammad Ali Mazidi, Janice Gillispie Mazidi, and Rolin D. McKinlay
2006 Pearson Education, Inc. Pearson Prentice Hall Upper Saddle River, NJ 07458
Table 91
The 8051 Microcontroller and Embedded Systems, 2e By Muhammad Ali Mazidi, Janice Gillispie Mazidi, and Rolin D. McKinlay
2006 Pearson Education, Inc. Pearson Prentice Hall Upper Saddle River, NJ 07458