Beruflich Dokumente
Kultur Dokumente
Timer 0
External 1 Timer 1 Serial
TF0
IE1 TF1 RI/TI
000Bh
0013h 001Bh 0023h
Explana tion
Un defined
Un defined
SETB AB
D7
D6
D5
D4
BC
D3
BB PT1
D2
BA PX1
D1
B9 PT0
D0
B8 PX0
EA
PS
Un define d
Un defined
D7
8F TF1
D6
8E TR1 Timer 1 run control bit. Set to 1 by software to run.
D5
8D TF0
D4
8C TR0
D3
8B IE1
D2
8A IT1
D1
89 IE0
D0
88 IT0
Explanation
Interrupt Interrupt 0 Timer 0 1 type type run External External control. control. control Interrupt Interrupt bit. 0 1 1 - edge 1 - edge Set to triggering triggering 1 by edge edge and and soft detect detect bit ware to bit 0- level 0- level run. triggering triggering
INT0
0 TF0 1 INT1 0 TF1 RI TI
IT0
IE0
IT1
Interrupt enabled
Timing of Interrupts
8051 micro-controller samples the hardware signal level on its pins once in every machine cycle. As 8051 takes 12 clock cycles to complete one machine cycle, the interrupt signal applied at the pins of 8051 must be available for at least 12 clock periods. External interrupts are applied at the pins INT0 and INT1. The sensing of voltage level applied to this pin can also programmed in 8051. The interrupts can be either level triggered or edge triggered as set by the IT0 and IT1 bits of the SFR TCON A 0 on these bit positions will make both the hardware interrupts to be level triggered. Level triggered means a low level voltage on the interrupt pins will activate the interrupts.
D1
D0
TI
RI
99h
98h
Transmit Interrupt Flag. Set when a byte has been completely transmitted.
Receive Interrupt Flag. Set when a byte has been completely received.
OPERATING MODES
Bits SM0 and SM1 are used to set the serial mode to a value between 0 and 3. Selecting the Serial Mode selects the mode of operation (8-bit/9-bit, UART or Shift Register) and also determines how the baud rate will be calculated. In modes 0 and 2 the baud rate is fixed based on the oscillators frequency. In modes 1 and 3 the baud rate is variable based on Timer 1 overflows.
SBUF
SBUF is physically two registers with the same address. When data to be transmitted is written to the SBUF register, then it will be shifted bit by bit into the TXD line of 8051. The port 3 pin 3.1 acts as the TXD line. The shifting is done by the transmit clock which determines the baud rate. Similarly, when the data bits are received on the RXD line (Pin 3.0 of port 3), the bits are shifted serially into the shift register according to the Receive clock. After the reception is complete, the data received will be placed on SBUF from where it can be read by the programmer through the internal bus.
Reception / Transmission
Mode 0: In this mode serial data is entering and exiting through RxD pin. So, in mode 0, Full duplex is not possible meaning that both transmission and reception cannot take place simultaneously. TxD pin outputs the shift clock. 8 bits are transmitted/received (LSB first). The baud rate is fixed at 1/12 the oscillator frequency. Transmission is started by writing a data byte to the SBUF register and once the transmission is complete, TI flag is set The reception is started by enabling REN in SCON register. Once the data reception is complete, the RI flag is set The baud rate in Mode 0 is fixed at one twelfth of the clock frequency. Baud rate= (Clock frequency/12)
Oxford University Press 2013
Reception / Transmission
Mode 1: In this mode, 10 bits are transmitted through TxD and simultaneously 10 bits can be received through RxD. The 10 bits are made up of a start bit (0), 8 data bits (LSB first), and a stop bit (1). On completion of reception, the stop bit goes into RB8 in Special Function Register SCON. The baud rate is variable and is set by the Timer 1 overflow rate. The baud rate for mode 1 is fixed at the following rate.
Reception / Transmission
Baud rate= (Timer 1 overflow rate /16) if SMOD bit in PCON SFR is set to 1. Baud rate= (Timer 1 overflow rate /32) if SMOD bit in PCON SFR is set to 0. Note that PCON is a special Function Register described in chapter 25. The MSB of PCON register can be set or reset by the programmer. The baud rate can be doubled by setting the MSB of PCON.
Reception / Transmission
In order to generate the baud rate clock from timer 1, Timer 1 can be configured to act as timer in auto reload mode with the timer 1 interrupt disabled. As in mode 0, the transmission is initiated by writing a data to SBUF register. Reception is initiated by a 1 to 0 transition that is the start bit received and also when REN of SCON SFR is 1.
Reception / Transmission
Mode 2: In this mode, 11 bits are transmitted through TxD or received through RxD. The 11 bits are made up of one start bit (always 0), 8 data bits (LSB first), a programmable 9th data bit, and a stop bit (always 1). The 9th data bit transmitted is same as TB8 bit in SCON special function register. It can be assigned the value of 0 or 1 by the programmer. Or, for example, the parity bit (P, in the PSW) could be moved into TB8. On reception, the 9th data bit goes into RB8 in Special Function Register SCON, while the stop bit is ignored. The baud rate is programmable to either 1/32 or 1/64 of the oscillator clock frequency. Baud rate= (Clock frequency /32) if SMOD bit in PCON SFR is set to 1. Baud rate= (Clock frequency /64) if SMOD bit in PCON SFR is set to 0.
Oxford University Press 2013
Reception / Transmission
Mode 3: In this mode, 11 bits are transmitted through TxD and simultaneously 11 bits are received through RxD. The 11bits are made up of a start bit (0), 8 data bits (LSB first), a programmable 9th data bit, and a stop bit (1). In fact, Mode 3 is the same as Mode 2 in all respects except baud rate. The baud rate in Mode 3 is variable. The baud rate for mode 3 is fixed at the following rate similar to mode1. Baud rate= (Timer 1 overflow rate /16) if SMOD bit in PCON SFR is set to 1. Baud rate= (Timer 1 overflow rate /32) if SMOD bit in PCON SFR is set to 0.
Oxford University Press 2013
Reception / Transmission
In all four modes, transmission is initiated by any instruction that uses SBUF as a destination register. Reception is initiated in Mode 0 by the condition RI = 0 and REN = 1. Reception is initiated in the other modes by the incoming start bit when REN = 1. The flow chart 11.20 shows the steps in programming the serial port of 8051. These steps are detailed in the following sections and also in the example programs.
2400
9600
FAh
FDh
Baud Rate Following set of instructions will set the timer for the baud
rate of 9600.
MOV TMOD, #00100000B ;timer/counter 1 set for mode 2, 8-bit TIMER ;operation MOV TH1, #0FDh ; timer/counter 1 is timed for 9600 baud SETB TR1 ; timer/counter 1 is enabled for free run
For initializing the serial port for mode 3 operation, the following instruction can be used.
MOV SCON, #11010000B