Beruflich Dokumente
Kultur Dokumente
OCEAN UNIVERSITY
國立台灣海洋大學
Chapter 9
COUNTER/TIMER
PROGRAMMING IN THE 8051
Mode 2 Programming
1.Loaded value into TH (8-bit timer)
2.”SETB TR0” for timer 0 ;”SETB TR1” for timer 1
3.If TF (timer flag) = high “CLR TR0” or “CLR TR1”
4.Reloaded TL value kept by TH
SM0 SM1:
– 00: Mode 0, Shift register, fosc//12
– 01: Mode 1, 8-bit UART, variable
– 10: Mode 2, 9-bit UART, fosc//32 or fosc//64
– 11: Mode 3, 9-bit UART, variable
SM2: Enables multiprocessor features in Mode 2 and Mode 3
– When the stop bit is received,
the interrupt will be activated only if RB8=1 (9th bit =1)
REN: Enables serial reception when set to 1 (i.e enables RXD pin ) reset to
zero to disable reception. Set/Clear by software
45/175
2002 MuDer Jeng
Part 3
TB8(Transmit bit 8) 9th data bit that will be transmitted in Mode2 and Mode3
– Set/Clear by software
RB8: 9th data bit that was received in Mode2 and Mode3
In Mode 1, if SM2=0, is the stop bit that was received
TI: Transmit interrupt flag
– Set by hardware. Must be cleared by software
RI: Receive interrupt flag
– Set by hardware. Must be cleared by software
46/175
2002 MuDer Jeng
Part 4
Intel 8051: Serial Port Interface
MODE 0:
– Serial data enters and exits through RXD
– TXD outputs shift clock
– 8 bits are transmitted/received: 8 data bits (LSB first)
– The baud rate is fixed at 1/12 oscillator frequency
MODE 1:
– Serial data enters through RXD, exits through TXD
– 10 bits are transmitted/received:
start bit(0), 8 data bits (LSB first), stop bit(1)
- On receive the stop bit TI/RI flag is raised in SCON register
The baud rate is variable
50/175
2002 MuDer Jeng
Part 5
Programming 8051to transfer
data
TMOD is initialized with 20h (Timer 1 in mode 2)
– TH1 is loaded with the reqd baud rate for serial data transmission
– Initialise SCON register with 50h
Start the timer1 by setting TR1
– * Transfer the character byte to SBUF register
– Monitor for TI flag(JNB TI, label)
Clear TI flag & repeat step *