You are on page 1of 21

Serial Communication Interface

Chapter 3

Objectives
Upon completion of this chapter, you will be able to:
Explain serial communication protocol Describe the serial communication features of the PIC18 Program the PIC18 serial port in C

Basics of Serial Communication


Asynchronous Synchronous

Serial versus Parallel Data Transfer

Basics of Serial Communication (contd)

Start and Stop Bits

Framing ASCII A (41H)

RS-232 Standards
Standard for serial comm (COM port)
1: -3V to -25V; 0: +3V to +25V Reason: for long distance wired line

Connectors
Minimally, 3 wires: RxD, TxD, GND Could have 9-pin or 25-pin

Standard baud rates:


1200, 2400, 4800, 9600, 14.4k, 19.2k, 28.8k..

RS232 Connector

DB-25 25-Pin Connector

DB-9 9-Pin Connector

RS232 Connector (contd)


IBM PC DB-9 Signals Data in Data out Pin 1 Data Carrier Detect (DCD) Pin 2 Received Data (RxD) Pin 3 Transmitted Data (TxD) Pin 4 Data Terminal Ready (DTR) Pin 5 Signal Ground (GND) Pin 6 Data Set Ready (/DSR) Pin 7 Request to Send (/RTS) Pin 8 Clear to Send (/CTS) Pin 9 Ring Indicator (RI)

DB-9 9-Pin Connector

PIC18 Connection to RS232

(a) Inside MAX232

(b) its Connection to the PIC18

PIC18 Connection to RS232 (contd)

(a) Inside MAX233

(b) Its Connection to the PIC18

Selecting Baud Rates


Baud rate in PIC18 is programmable The value loaded into the SPBRG decides the baud rate SPBRG Baud Rate (Hex Value) 38400 19200 9600 4800 2400 1200
*For XTAL = 10MHz only!

3 7 F 20 40 81

TXSTA: Transmit Status and Control Register

RCSTA: Receive Status and Control Register

PIR: Peripheral Interrupt Register 1

Example1
Write a C program to transfer the letter G serially at 9600, continuously. Use 8-bit data and 1 stop bit. Assume XTAL = 10MHz.

Example 1 (contd)

Example2
Write a C program to transfer the message YES serially at 9600, continuously. Use 8-bit data and 1 stop bit. Assume XTAL = 10MHz.

Example2 (contd)

Example 3
Write a C program to receive bytes of data serially and put them on PORTB. Set the baud rate at 9600, 8-bit data and 1 stop bit.

Example 3 (contd)

End of Chapter 3

You might also like