0% found this document useful (0 votes)
71 views

7 Serial Port

The document discusses serial communication and the 8051 microcontroller. It describes: - Serial communication is cheaper and can operate over longer distances than parallel communication, though it is slower. - In asynchronous serial transmission, data is packaged with start and stop bits for transmission. The baud rate indicates the data transfer speed. - The RS-232 standard defines the voltage levels for logic 1 and 0 and was created in 1960. It is commonly used for serial communication between devices. - The 8051 has registers for serial communication like SBUF for sending/receiving data and SCON for serial control settings. Modes 0-3 define the frame format and baud rate generation.

Uploaded by

Shamir
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
71 views

7 Serial Port

The document discusses serial communication and the 8051 microcontroller. It describes: - Serial communication is cheaper and can operate over longer distances than parallel communication, though it is slower. - In asynchronous serial transmission, data is packaged with start and stop bits for transmission. The baud rate indicates the data transfer speed. - The RS-232 standard defines the voltage levels for logic 1 and 0 and was created in 1960. It is commonly used for serial communication between devices. - The 8051 has registers for serial communication like SBUF for sending/receiving data and SCON for serial control settings. Modes 0-3 define the frame format and baud rate generation.

Uploaded by

Shamir
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 27

Serial

Communication

M_Nokhodchian @ yahoo.com Microprocessors 1-1


Basics of serial communication
Parallel: expensive - short distance – fast – no modulation
Serial :cheaper– long (two different cities by modem)-slow

M_Nokhodchian @ yahoo.com Microprocessors 1-2


Basics of serial communication

M_Nokhodchian @ yahoo.com Microprocessors 1-3


Packaging Data
Start and stop bits

In asynchronous transmission


When there is no transfer the signal is high
Transmission begins with a start (low) bit
LSB first
Finally 1 stop bit (high)
Data transfer rate (baud rate) is stated in bps

M_Nokhodchian @ yahoo.com Microprocessors 1-4


RS232 Standard

 Create in 1960 and updated in 1969


 Logic 1 : -3 to -25 volt
 Logic 0 : 3 to 25 volt
 To Connect TXD to RXD and RXD to TXD
from pc to 8051 you must use max232 to 1 DCD
convert signal from TTL level to RS232 2 RD
level 3 TD
 The baud rate of the 8051 must matched 4 DTR
the baud rate of the pc 5 GND
6 DSR
 PC standard baud rate (see hyper terminal
7 RTS
configuration)
8 CTS
 2400-4800-9600-14400-19200-28800- 9 RI
33600-57600

M_Nokhodchian @ yahoo.com Microprocessors 1-5


MAX232 or MAX233

M_Nokhodchian @ yahoo.com Microprocessors 1-6


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

M_Nokhodchian @ yahoo.com Microprocessors 1-7


Serial control (SCON) Register
7 6 5 4 3 2 1 0
SM0 SM1 SM2 REN TB8 RB8 TI RI

SM0 SM1 MODE operation transmit rate

SM0 : mode specifier 0 0 0 shift register fixed (xtal/12)


0 1 1 8 bit UART variable (timer1)
SM1 : mode specifier 1 0 2 9 bit UART fixed (xtal/32 or xtal/64)
1 1 3 9 bit UART variable (timer1)

SM2 : used for multi processor communication


REN : receive enable (by software enable/disable)
TB8 : transmit bit8
RB8 : receive bit 8
TI : transmit interrupt flag set by HW after send , clear by SW
RI : receive interrupt flag set by HW after received ,clear by SW

M_Nokhodchian @ yahoo.com Microprocessors 1-8


Mode of operation
 Mode 0 :
 Serial data enters and exits through RxD
 TxD outputs the shift clock.
 8 bits are transmitted/received(LSB first)
 The baud rate is fixed a 1/12 the oscillator frequency.

 Application
 Port expansion

8051
TXD clk
RXD Shift register
data

M_Nokhodchian @ yahoo.com Microprocessors 1-9


Timing of send in mode 0
One machine cycle

oscillator cycle

RXD (data)

TXD (clock pulse)

MOV SCON,#0001xxxxB
Wait: JNB TI,WAIT
CLR TI
MOV SBUF,A MOV SCON,#0001xxxxB
Wait: JNB RI,WAIT
CLR RI
MOV A,SBUF

M_Nokhodchian @ yahoo.com Microprocessors 1-10


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.
M_Nokhodchian @ yahoo.com Microprocessors 1-11
Timer modes

(MSB) (LSB)
GATE C/T M1 M0 GATE C/T M1 M0
Timer 1 Timer 0
M_Nokhodchian @ yahoo.com Microprocessors 1-12
M_Nokhodchian @ yahoo.com Microprocessors 1-13
Programming for sending data
( in mode 1 )
1. MOV TMOD,#20H
(MSB (LSB)
GATE
) C/T M1 M0 GATE C/T M1 M0
Timer 1 Timer 0

2. MOV TH1,# baud rate BAUD RATE VALUE IN TH VALUE IN HEX

9600 -3 FD

3. MOV SCON,#50H 4800 -6 FA

2400 -12 F4

1200 -24 E8

XTAL=11.0592 MHz

SM0 SM1 SM2 REN TB8 RB8 TI RI

4. SETB TR1
5. MOV SBUF, DATA
6. WAIT: JNB TI,WAIT
7. CLR TI
M_Nokhodchian @ yahoo.com Microprocessors 1-14
Programming for sending data
( in mode 1 )

Serial example(1)

MOV TMOD,#20H ;TIMER 1 MODE 2


MOV TH1,#-3 ;9600 BAUD
MOV SCON,#50H ;REN enable
SETB TR1 ;start timer1
AGAIN: MOV SBUF, # “A”
WAIT: JNB TI,WAIT
CLR TI
SJMP AGAIN

M_Nokhodchian @ yahoo.com Microprocessors 1-15


Programming for recieving data
( in mode 1 )

Serial example(2)

MOV TMOD,#20H ;TIMER 1 MODE 2


MOV TH1,#-3 ;9600 BAUD
MOV SCON,#50H ;REN enable
SETB TR1 ;start timer1
WAIT: JNB RI,WAIT
MOV A,SBUF
CLR RI
SJMP WAIT

M_Nokhodchian @ yahoo.com Microprocessors 1-16


Serial example(3)
An example of sending a message.
;initialization
MOV TMOD,#20H
MOV TH1,#-12
MOV SCON,#50H
;begin to trnasmit
SETB TR1
AGAIN1: MOV A,#‘G'
CALL TRANSS
MOV A,#‘O'
CALL TRANSS
MOV A,#‘O'
CALL TRANSS
MOV A,#‘D'
CALL TRANSS
SJMP AGAIN1
;seial transmiting subroutine
TRANSS: MOV SBUF,A
AGAIN2: JNB TI,AGAIN2
CLR TI
RET
END

M_Nokhodchian @ yahoo.com Microprocessors 1-17


Serial example(4)
ORG 0
MOV TMOD,#20H
MOV TH1,#0FAH ;4800
MOV SCON,#50H
SETB TR1
MOV DPTR,#MYDATA
LOOP: CLR A
MOVC A,@A+DPTR
JZ EXIT
ACALL SEND
INC DPTR
SJMP LOOP
;----------------------------------
SEND: MOV SBUF,A
WAIT: JNB TI,WAIT
CLR TI
RET
;----------------------------------
MYDATA: DB “THIS IS A SAMPLE TEST”,0
EXIT: END

M_Nokhodchian @ yahoo.com Microprocessors 1-18


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.

M_Nokhodchian @ yahoo.com Microprocessors 1-19


Mode of operation

M_Nokhodchian @ yahoo.com Microprocessors 1-20


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 acc.7
Mov pcon,a

M_Nokhodchian @ yahoo.com Microprocessors 1-21


Power control register

M_Nokhodchian @ yahoo.com Microprocessors 1-22


Power control

 A standard for applications where power


consumption is critical
 two power reducing modes
 Idle
 Power down

M_Nokhodchian @ yahoo.com Microprocessors 1-23


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

M_Nokhodchian @ yahoo.com Microprocessors 1-24


Power-Down Mode
 An instruction that sets PCON.1 causes power dowm
mode
 Last instruction executed before going into the power
down mode
 the on-chip oscillator is stopped.
 all functions are stopped,the contents of the on-chip
RAM and Special Function Registers are maintained.
 The ALE and PSEN output are held low
 The reset that terminates Power Down

M_Nokhodchian @ yahoo.com Microprocessors 1-25


Power control example
Org 0000h
Ljmp main

Org 0003h
Orl pcon,#02h ;power down mode
Reti

Org 0030h
Main:
……
……
……
Orl pcon,#01h ;Idle mode
end

M_Nokhodchian @ yahoo.com Microprocessors 1-26


example

M_Nokhodchian @ yahoo.com Microprocessors 1-27

You might also like