Académique Documents
Professionnel Documents
Culture Documents
8051 timers:
The 8051 comes equipped with two timers, both of which may be controlled, set, read, and
configured individually. The 8051 timers have three general functions: 1) Keeping time and/or
calculating the amount of time between events, 2) Counting the events themselves, or 3)
Generating baud rates for the serial port. one of the primary uses of timers is to measure time. We
will discuss this use of timers first and will subsequently discuss the use of timers to count
events. When a timer is used to measure time it is also called an "interval timer" since it is
measuring the time of the interval between two events.
8051 timer
TIMER 0
TIMER 1
MODE 0
MODE 0
MODE 1
MODE 1
MODE 2
MODE 2
MODE 3
KARTHIK. S
GATE:
When set, timer/counter x is enabled, if INTx pin is high and TRx is set.
When cleared, timer/counter x is enabled, if TRx bit set.
C/T*:
When set(1), counter operation (input from Tx input pin).
When clear(0), timer operation (input from internal clock).
KARTHIK. S
KARTHIK. S
TIMER 0:
MODE 0:
13-bit Time Mode (mode 0)
Timer mode "0" is a 13-bit timer. This is a relic that was kept around in the 8051 to maintain
compatibility with its predecessor, the 8048. Generally the 13-bit timer mode is not used in new
development. When the timer is in 13-bit mode, TLx will count from 0 to 31. When TLx is
incremented. It will "reset" to 0 and increment THx. Thus, effectively, only 13 bits of the two
timer bytes are being used: bits 0-4 of TLx and bits 0-7 of THx. This also means, in essence, the
timer can only contain 8192 values. If you set a 13-bit timer to 0, it will overflow back to zero
8192 machine cycles later.
KARTHIK. S
KARTHIK. S
KARTHIK. S
2.
Timer Mode 1:
In following, we all use timer 0 as an example.
16-bit timer (TH0 and TL0)
TH0-TL0 is incremented continuously when TR0 is set to 1. And the 8051 stops to
increment TH0-TL0 when TR0 is cleared.
KARTHIK. S
KARTHIK. S
KARTHIK. S
Example 2:
;generate delay using timer 0
DELAY:
SETB TR0
AGAIN:JNB TF0,AGAIN
CLR TR0
;stop timer 0
CLR TF0
RET
Solution:
KARTHIK. S
3.
Parallel Vs Serial:
KARTHIK. S
Mode 1:
Mode 2:
Mode 3:
SCON Register:
KARTHIK. S
8051
Serial Port Mode 0
The Serial Port in Mode-0 has the following features:
1. Serial data enter and exits through RXD
2. TXD outputs the clock
3. 8 bits are transmitted / received
4. The baud rate is fixed at (1/12) of the oscillator frequency
8051 Serial Port Mode 1
The Serial Port in Mode-1 has the following features:
1. Serial data enters through RXD
2. Serial data exits through TXD
3. On receive, the stop bit goes into RB8 in SCON
4. 10 bits are transmitted / received
1. Start bit (0)
2. Data bits (8)
3. Stop Bit (1)
5. Baud rate is determined by the Timer 1 over flow rate
8051 Serial Port Mode 2
The Serial Port in Mode-2 has the following features:
1. Serial data enters through RXD
KARTHIK. S
KARTHIK. S
KARTHIK. S
KARTHIK. S
Write a program for the 8051 to transfer letter A serially at 4800 baud rate, continuously.
KARTHIK. S
Program the 8051 to receive bytes of data serially, and put them in P1. Set the baud rate at
4800.
KARTHIK. S