16th April 8051 Serial Comm
16th April 8051 Serial Comm
Checksum Checker
A Checksum is verified at the receiving side. The receiver subdivides the incoming data
into equal segments of n bits each, and all these segments are added together, and then
this sum is complemented. If the complement of the sum is zero, then the data is
accepted otherwise data is rejected.
8051
• Application
TXD clk
• Port expansion RXD data
Shift register
Mode of operation
• Mode 1
• Ten bits are transmitted (through TxD) or received (through RxD)
• A start bit (0), 8 data bits (LSB first), and a stop bit (1)
• On receive, the stop bit goes into RB8 in SCON
• the baud rate is determined by the Timer 1 overflow rate.
• Timer1 clock is 1/32 machine cycle (MC=1/12 XTAL)
• Timer clock can be programmed as 1/16 of machine cycle
• Transmission is initiated by any instruction that uses SBUF as a
destination register.
Mode of operation
Mode of operation
• Mode 2 :
• Eleven bits are transmitted (through TxD), received (through RxD)
• A start bit (0)
• 8 data bits (LSB first)
• A programmable 9th data bit
• and a stop bit (1)
• On transmit, the 9th bit (TB8) can be assigned 0 or 1.
• On receive, the 9the data bit goes into RB8 in SCON.
• the 9th can be parity bit
• The baud rate is programmable to 1/32 or 1/64 the oscillator frequency in
Mode 2 by SMOD bit in PCON register
• Mode 3
• Same as mode 2
• But may have a variable baud rate generated from Timer 1.
What is SMOD
Bit 7 of PCON register
If SMOD=1 double baud rate
PCON is not bit addressable
How to set SMOD
MOV A, PCON
SETB A.7
MOV PCON,A
How to communicate 8051 to PC
Connect TXD to RXD and RXD to TXD from pc to 8051
Use max232 to transform signal from TTL level to RS232 level
The baud rate of the 8051 must matched the baud rate of the pc
PC standard baud rate
2400-4800-9600-14400-19200-28800-33600-57600
Serial mode 1 is used
Timer 1 is used
The 8051 UART divides the machine cycle frequency by 32
Machine cycle is 1/12 XTAL frequency
We use timer1 in mode 2 (auto reload)
See example 10-1
RxD and TxD pins in the 8051
• TxD pin 11 of the 8051 (P3.1)
• RxD pin 10 of the 8051 (P3.0)
SBUF register
MOV SBUF,#’D’ ;load SBUF=44H, ASCII for ‘D’
MOV SBUF,A ;copy accumulator into SBUF
MOV A,SBUF ;copy SBUF into accumulator
MAX232
Power control
• Controlling Power Consumption
• Two power reducing modes Power control register PCON
Idle
Power down
Idle mode
• An instruction that sets PCON.0 causes Idle mode
Last instruction executed before going into the Idle mode
the internal CPU clock is gated off
Interrupt, Timer, and Serial Port functions act normally.
All of registers, ports and internal RAM maintain their data during
Idle
ALE and PSEN hold at logic high levels
• Any interrupt
• will cause PCON.0 to be cleared by HW (terminate Idle mode)
• then execute ISR
• with RETI return and execute next instruction after Idle instruction.
• RST signal clears the IDL bit directly
Power-Down Mode
An instruction that sets PCON.1 causes power-dowm mode
Last instruction executed before going into the power down mode
all functions are stopped, the contents of the on-chip RAM and
Special Function Registers are maintained.
Org 0000h
Ljmp main
Org 0003h
Orl pcon,#02h ;power down mode
Reti
Org 0030h
Main:
……
……
……
Orl pcon,#01h ;Idle mode
end