Serial Comm in 8051

download Serial Comm in 8051

of 21

Transcript of Serial Comm in 8051

  • 8/3/2019 Serial Comm in 8051

    1/21

    Serial

    Communication

  • 8/3/2019 Serial Comm in 8051

    2/21

    Basics of serial communicationParallel: expensive - short distance

    fast

    no modulation

    Serial :cheaper long (two different cities by modem)-slow

  • 8/3/2019 Serial Comm in 8051

    3/21

  • 8/3/2019 Serial Comm in 8051

    4/21

    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

  • 8/3/2019 Serial Comm in 8051

    5/21

    2 methods, asynchronous and synchronous

    synchronousmethod transfers a block of data

    (characters) at a time

    asynchronousmethod transfers a single byteat a time

    Uses special IC chips called UART (universalasynchronous receiver-transmitter) andUSART (universal synchronousasynchronous

    receiver-transmitter) 8051 chip has a built-in UART

  • 8/3/2019 Serial Comm in 8051

    6/21

    RS232 pins

  • 8/3/2019 Serial Comm in 8051

    7/21

    Data communicationclassification

  • 8/3/2019 Serial Comm in 8051

    8/21

    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 rate0 0 0 shift register fixed (xtal/12)0 1 1 8 bit UART variable (timer1)

    1 0 2 9 bit UART fixed (xtal/32 orxtal/64)1 1 3 9 bit UART variable (timer1)

    SM0: mode specifierSM1: mode specifier

  • 8/3/2019 Serial Comm in 8051

    9/21

    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

    RXD Shift registerclk

    data

  • 8/3/2019 Serial Comm in 8051

    10/21

    Timing of send in mode 0One machine cycle

    oscillator cycle

    RXD (data)

    TXD (clock pulse)

    MOVSCON,#0001xxxxBWait: JNB RI,WAIT

    CLR RIMOV A,SBUF

    MOV

    SCON,#0001xxxxBWait: JNB TI,WAITCLR TIMOV SBUF,A

  • 8/3/2019 Serial Comm in 8051

    11/21

    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 asa destination register.

  • 8/3/2019 Serial Comm in 8051

    12/21

    Mode of operation Mode 2 :

    Eleven bits are transmitted (through TxD), received (throughRxD) 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.

  • 8/3/2019 Serial Comm in 8051

    13/21

    Mode of operation

  • 8/3/2019 Serial Comm in 8051

    14/21

    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

  • 8/3/2019 Serial Comm in 8051

    15/21

    Power control register

  • 8/3/2019 Serial Comm in 8051

    16/21

    Power control

    A standard for applications where powerconsumption is critical

    two power reducing modes Idle

    Power down

  • 8/3/2019 Serial Comm in 8051

    17/21

    Baud rate in the 8051

    serial communications of the 8051 withthe COM port of the PC

    must make sure that the baud rate of the8051 system matches the baud rate of the

    PC's COM port can use Windows HyperTerminal

    program

  • 8/3/2019 Serial Comm in 8051

    18/21

    PC Baud Rates

  • 8/3/2019 Serial Comm in 8051

    19/21

    Baud rate in the 8051

    baud rate in the 8051 is programmable

    done with the help of Timer 1

    relationship between the crystal frequency and thebaud rate in the 8051

    8051 divides the crystal frequency by 12 to get themachine cycle frequency

    XTAL = 11.0592 MHz, the machine cycle frequency is921.6 kHz

    8051's UART divides the machine cycle frequency of921.6 kHz by 32 once more before it is used by Timer

    1 to set the baud rate

    921.6 kHz divided by 32 gives 28,800 Hz

    Timer 1 must be programmed in mode 2, that is 8-bit,auto-reload

  • 8/3/2019 Serial Comm in 8051

    20/21

    Table 104 Timer 1 TH1 Register Values for Various Baud Rates

  • 8/3/2019 Serial Comm in 8051

    21/21

    Example:

    With XTAL = 11.0592 MHz, find the TH1

    value needed to have the following baud

    rates. (a) 9600 (b) 2400 (c) 1200 machine cycle frequency

    = 11.0592 MHz / 12 = 921.6 kHz

    Timer 1 frequency provided by 8051UART= 921.6 kHz / 32 = 28,800 Hz

    (a) 28,800 / 3 = 9600 where -3 = FD (hex)

    (b) 28,800 / 12 = 2400 where -12 = F4 (hex)

    (c) 28,800 / 24 = 1200 where -24 = E8 (hex)