chap9 - Chapter 9 Counter/Timer Programming in the 8051 1...

This preview shows page 1 - 14 out of 87 pages.

The preview shows page 12 - 14 out of 87 pages.
1Chapter 9Counter/Timer Programming in the8051
2Objective8051has 2 Timer/Counter mechanism and thischapter is to understandWhat does Timer/Counter mean?How to use Timer 。How to useCounter 。
3Sections9.1Programming 8051 Timers9.2Counter Programming
4Section 9.1Programming 8051 Timers
5Figure 4-1. 8051 Pin DiagramPDIP/Cerdip12345678910111213141516171819204039383736353433323130292827262524232221P1.0P1.1P1.2P1.3P1.4P1.5P1.6P1.7RST(RXD)P3.0(TXD)P3.1(T0)P3.4(T1)P3.5XTAL2XTAL1GND(INT0)P3.2(INT1)P3.3(RD)P3.7(WR)P3.6VccP0.0(AD0)P0.1(AD1)P0.2(AD2)P0.3(AD3)P0.4(AD4)P0.5(AD5)P0.6(AD6)P0.7(AD7)EA/VPPALE/PROGPSENP2.7(A15)P2.6(A14)P2.5(A13)P2.4(A12)P2.3(A11)P2.2(A10)P2.1(A9)P2.0(A8)8051(8031)
6Inside Architecture of 8051CPUOn-chipRAMOn-chipROM forprogramcode4 I/O PortsTimer 0SerialPortFigure 1-2. Inside the 8051 Microcontroller Block DiagramOSCInterruptControlExternal interruptsTimer 1Timer/CounterBusControlTxDRxDP0 P1 P2 P3Address/DataCounterInputs
7Timers /CountersThe 8051 has 2 timers/counters: timer/counter 0 andtimer/counter 1. They can be used as1.Thetimeris used as a time delay generator.The clock source is theinternalcrystal frequency of the8051.1.An eventcounter.External inputfrom input pin to count the number ofevents on registers.These clock pulses cold represent the number of peoplepassing through an entrance, or the number of wheelrotations, or any other event that can be converted topulses.
8TimerSet the initial value of registersStart the timer and then the 8051 counts up.Input from internal system clock (machine cycle)When the registers equal to 0 and the 8051 sets abit to denote time outtoLCDP18051TL0TH0P2SetTimer 0
9CounterCount the number of eventsShow the number of events on registersExternal input from T0 input pin (P3.4) for Counter 0External input from T1 input pin (P3.5) for Counter 1External inputfrom Tx input pin.We use Tx to denote T0 or T1.T0toLCDP3.4P18051a switchTL0TH0
10Registers Used in Timer/CounterTH0, TL0, TH1, TL1TMOD (Timer mode register)TCON (Timer control register)You can see Appendix H (pages 413-415) for details.Since 8052 has 3 timers/counters, the formats of thesecontrol registers are different.T2CON (Timer 2 control register), TH2 and TL2 used for8052 only.
11Basic Registers of the TimerBoth timer 0 and timer 1 are 16 bits wide.These registers storesthe time delay as a timerthe number of events as a counterTimer 0:TH0&TL0Timer 0 high byte, timer 0 low byteTimer 1:TH1&TL1Timer 1 high byte, timer 1 low byteEach 16-bit timer can be accessed as two separate registersof low byte and high byte.
12TimerRegistersD15D8D9D10D11D12D13D14D7D0D1D2D3D4D5D6TH0TL0D15D8D9D10D11D12D13D14D7D0D1D2D3D4D5D6TH1TL1Timer 0Timer 1
13TMOD RegisterTimer mode register:TMODMOV TMOD,#21HAn 8-bit registerSet the usage mode for two timersSet lower 4 bits for Timer 0(Set to 0000 if not used)

Upload your study docs or become a

Course Hero member to access this document

Upload your study docs or become a

Course Hero member to access this document

End of preview. Want to read all 87 pages?

Upload your study docs or become a

Course Hero member to access this document

Term
Fall
Professor
cheung
Tags
Hertz, Square wave, Clock signal, timer, TMOD

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture