pic18 serial comm 2

Upload: adamwaiz

Post on 04-Apr-2018

238 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/30/2019 pic18 serial comm 2

    1/21

    Serial CommunicationInterface

    Chapter 3

  • 7/30/2019 pic18 serial comm 2

    2/21

    Objectives Upon completion of this chapter, you will

    be able to: Explain serial communication protocol

    Describe the serial communication features ofthe PIC18

    Program the PIC18 serial port in C

  • 7/30/2019 pic18 serial comm 2

    3/21

  • 7/30/2019 pic18 serial comm 2

    4/21

    Basics of Serial Communication

    (contd)

  • 7/30/2019 pic18 serial comm 2

    5/21

    Start and Stop Bits

    Framing ASCII A (41H)

  • 7/30/2019 pic18 serial comm 2

    6/21

    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..

  • 7/30/2019 pic18 serial comm 2

    7/21

    RS232 Connector

    DB-25

    25-Pin Connector

    DB-9

    9-Pin Connector

  • 7/30/2019 pic18 serial comm 2

    8/21

    RS232 Connector (contd)

    IBM PC DB-9 Signals

    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

    Data in Data out

  • 7/30/2019 pic18 serial comm 2

    9/21

    PIC18 Connection to RS232

    (a) Inside MAX232 (b) its Connection to the PIC18

  • 7/30/2019 pic18 serial comm 2

    10/21

    PIC18 Connection to RS232

    (contd)

    (a) Inside MAX233 (b) Its Connection to the PIC18

  • 7/30/2019 pic18 serial comm 2

    11/21

    Selecting Baud Rates Baud rate in PIC18 is

    programmable The value loaded into

    the SPBRG decides

    the baud rate

    338400

    719200F9600

    811200

    402400

    204800

    SPBRG

    (Hex Value)Baud Rate

    *For XTAL = 10MHz only!

  • 7/30/2019 pic18 serial comm 2

    12/21

    TXSTA: Transmit Status and

    Control Register

  • 7/30/2019 pic18 serial comm 2

    13/21

    RCSTA: Receive Status and

    Control Register

  • 7/30/2019 pic18 serial comm 2

    14/21

    PIR: Peripheral Interrupt Register 1

  • 7/30/2019 pic18 serial comm 2

    15/21

    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.

  • 7/30/2019 pic18 serial comm 2

    16/21

    Example 1 (contd)

  • 7/30/2019 pic18 serial comm 2

    17/21

    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.

  • 7/30/2019 pic18 serial comm 2

    18/21

    Example2 (contd)

  • 7/30/2019 pic18 serial comm 2

    19/21

    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.

  • 7/30/2019 pic18 serial comm 2

    20/21

    Example 3 (contd)

  • 7/30/2019 pic18 serial comm 2

    21/21

    End of Chapter 3