Presentation is loading. Please wait.

Presentation is loading. Please wait.

Timer Source: http://www.edsim51.com/8051Notes/8051/timers.html under http://www.edsim51.com/8051Notes/index.html.

Similar presentations


Presentation on theme: "Timer Source: http://www.edsim51.com/8051Notes/8051/timers.html under http://www.edsim51.com/8051Notes/index.html."— Presentation transcript:

1 Timer Source: http://www.edsim51.com/8051Notes/8051/timers.html
under

2 The basic 8051 has two 16-bit on-chip timers: Timer 1 (TH1TL1) & Timer 0 (TH0TL0)
They can be used for timing durations or for counting external events.

3 Timer Mode Register (TMOD)
TMOD (Timer Mode Register ) Bit Name Timer Description 7 Gate 1 Gate bit; when set, timer only runs while INT-bar is high. This bit is used in conjunction with interrupts and will be dealt with later. 6 C/T-bar Counter/timer select bit; when set timer is an event counter, when cleared timer is an interval timer. 5 M1 Mode bit 1 4 M0 Mode bit 0 3 Gate bit; when set, timer only runs while INT-bar is high. 2

4 Timer Modes M1 M0 Mode Description
13-bit timer mode (this mode exists simply to keep the 8051 backwards compatible with its predecessor, the 8048, which had a 13-bit timer) - we will not be using mode 0. 1 16-bit timer mode 2 8-bit auto-reload mode 3 Split timer mode - this mode will be dealt with at a later stage X = 1 for Timer 1 X = 0 for Timer 0

5 Timer Control Register
TCON (Timer Control Register) Bit Symbol Bit Address Description 7 TF1 8FH Timer 1 overflow flag; set by hardware upon overflow, cleared by software. 6 TR1 8EH Timer 1 run-control bit; manipulated by software - setting starts timer 1, resetting stops timer 1. 5 TF0 8DH Timer 0 overflow flag; set by hardware upon overflow, cleared by software. 4 TR0 8CH Timer 0 run-control bit; manipulated by software - setting starts timer 0, resetting stops timer 0. 3 IE1 8BH The bottom four bits of TCON are used in conjunction with interrupts. ITx controls the triggering condition of external x interrupt. = 1: negative-edge triggering = 0: low-level triggering IEx is the interrupt flag for external interrupt x , where x = 0 or 1 2 IT1 8AH 1 IE0 89H IT0 88H SETB TR0; start timer 0 SETB TR1; start timer 1 CLR TR0; stop timer 0 CLR TR1; stop timer 1

6 Clock Source When the timer is operating as an interval timer it is being clocked by the internal clock. This internal clock, usually 12MHz, is actually divided by twelve to yield a reasonable clock frequency for most applications - therefore, the internal clocking signal is usually 1MHz). When the timer is operating as an event counter it is triggered by an external source connected to pin T0 (port 3, pin 4) for timer 0 and pin T1 (port 3, pin 5) for timer 1.

7 begins.


Download ppt "Timer Source: http://www.edsim51.com/8051Notes/8051/timers.html under http://www.edsim51.com/8051Notes/index.html."

Similar presentations


Ads by Google