sereial com. ppt

26
SERIAL COMMUNICATION Presented by:- Gaurav Saraswat Associate Designing Engineer at Tevatron Technology

Upload: gaurav5345

Post on 26-Dec-2014

58 views

Category:

Documents


1 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Sereial com. ppt

SERIAL COMMUNICATIONPresented by:-

Gaurav SaraswatAssociate Designing Engineer at Tevatron

Technology

Page 2: Sereial com. ppt

Basics of serial CommunicationParallel: expensive - short distance – fast – no modulationSerial :cheaper– long (two different cities by modem)-slow

Page 3: Sereial com. ppt

Basics of serial communication

Page 4: Sereial com. ppt

Packaging DataStart and stop bits

In asynchronous transmissionWhen there is no transfer the signal is highTransmission begins with a start (low) bitLSB firstFinally 1 stop bit (high)Data transfer rate (baud rate) is stated in bps

Page 5: Sereial com. ppt

RS232 Standard

1 DCD

2 RD

3 TD

4 DTR

5 GND

6 DSR

7 RTS

8 CTS

9 RI

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 convert 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 (see hyper terminal configuration) 2400-4800-9600-14400-19200-28800-

33600-57600

Page 6: Sereial com. ppt

MAX232 or MAX233

Page 7: Sereial com. ppt

SBUF registerMOV SBUF,#’D’ ;load SBUF=44H, ASCII for ‘D’MOV SBUF,A ;copy accumulator into SBUFMOV A,SBUF ;copy SBUF into accumulator

Page 8: Sereial com. ppt

Serial control (SCON) Register

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

SM0 RITIRB8TB8RENSM2SM1

7 6 5 4 3 2 1 0

SM0 SM1 MODE operation transmit rate 0 0 0 shift register fixed

(xtal/12) 0 1 1 8 bit UART variable

(timer1) 1 0 2 9 bit UART fixed (xtal/32

or xtal/64) 1 1 3 9 bit UART variable

(timer1)

SM0 : mode specifierSM1 : mode specifier

Page 9: Sereial com. ppt

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

TXDRXD Shift register

clkdata

Page 10: Sereial com. ppt

Timing of send in mode 0

One machine cycle

oscillator cycle

RXD (data)

TXD (clock pulse)

MOV SCON,#0001xxxxBWait: JNB RI,WAIT

CLR RIMOV A,SBUF

MOV SCON,#0001xxxxBWait: JNB TI,WAIT CLR TI MOV SBUF,A

Page 11: Sereial com. ppt

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.

Page 12: Sereial com. ppt

Timer modes

GATE C/T M1 M0 GATE C/T M1 M0Timer 1 Timer 0

(MSB) (LSB)

Page 13: Sereial com. ppt
Page 14: Sereial com. ppt

Programming for sending data( in mode 1 )

4. SETBTR1

5. MOVSBUF, DATA

6. WAIT: JNB TI,WAIT

7. CLR TI

BAUD RATE VALUE IN TH VALUE IN HEX

9600 -3 FD

4800 -6 FA

2400 -12 F4

1200 -24 E8

XTAL=11.0592 MHz

GATE C/T M1 M0 GATE C/T M1 M0Timer 1 Timer 0

(MSB)

(LSB)1. MOV TMOD,#20H

2. MOV TH1,# baud rate

3. MOV SCON,#50H

SM0 RITIRB8TB8RENSM2SM1

Page 15: Sereial com. ppt

Programming for sending data( in mode 1 )

MOV TMOD,#20H ;TIMER 1 MODE 2

MOV TH1,#-3 ;9600 BAUD

MOV SCON,#50H ;REN enableSETB TR1 ;start timer1

AGAIN: MOV SBUF, # “A”WAIT: JNB TI,WAIT

CLR TISJMP AGAIN

Serial example(1)

Page 16: Sereial com. ppt

Programming for recieving data

( in mode 1 )

MOV TMOD,#20H ;TIMER 1 MODE 2

MOV TH1,#-3 ;9600 BAUD

MOV SCON,#50H ;REN enableSETB TR1 ;start timer1

WAIT: JNB RI,WAITMOV A,SBUF

CLR RISJMP WAIT

Serial example(2)

Page 17: Sereial com. ppt

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.

Page 18: Sereial com. ppt

Mode of operation

Page 19: Sereial com. ppt

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

Page 20: Sereial com. ppt

Power control register

Page 21: Sereial com. ppt

Power control

A standard for applications where power consumption is critical

two power reducing modes Idle Power down

Page 22: Sereial com. ppt

Idle modeAn 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 IdleALE 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

Page 23: Sereial com. ppt

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 lowThe reset that terminates Power Down

Page 24: Sereial com. ppt

Power control example

Org 0000hLjmp main

Org 0003hOrl pcon,#02h ;power down modeReti

Org 0030hMain:

………………Orl pcon,#01h ;Idle modeend

Page 25: Sereial com. ppt

example

Page 26: Sereial com. ppt