Serial Comm+Adc

download Serial Comm+Adc

of 29

Transcript of Serial Comm+Adc

  • 8/8/2019 Serial Comm+Adc

    1/29

    Serial

    communication

  • 8/8/2019 Serial Comm+Adc

    2/29

    Contents

    Types of communication.

    UART in 8051.

    Max circuitry.

    Baud rate in 8051.

    Registers regarding serial communication.

    Programming steps.

  • 8/8/2019 Serial Comm+Adc

    3/29

    Serial Communication

    1.Parallel

    2.Serial

    Type of Communication

  • 8/8/2019 Serial Comm+Adc

    4/29

    Parallel transmission

  • 8/8/2019 Serial Comm+Adc

    5/29

    Serial transmission

  • 8/8/2019 Serial Comm+Adc

    6/29

    Synchronous transmission

  • 8/8/2019 Serial Comm+Adc

    7/29

    Asynchronous transmission

  • 8/8/2019 Serial Comm+Adc

    8/29

    An UART, universal asynchronous receiver /transmitteris responsible forperforming the main

    taskin serial communications with computers.

    The device changesincoming parallelinformation toserial data which can be sent on a communication

    line. A second UART can be used to receive the

    information.

    To communicate with pc orother devices we needsome standardslike RS232.

    A driver(MAX232) is used to convert TTL level to

    RS232 voltage level.

    UART in 8051

  • 8/8/2019 Serial Comm+Adc

    9/29

    Value of capacitors is 10uF

    Max circuitry

    Controller

    section

    RS232

    section

  • 8/8/2019 Serial Comm+Adc

    10/29

    BaudRates in the 8051

    The 8051 transfers and receives data serially at many

    different baud rates by using UART.

    UARTdivides the machine cycle frequency by 32 and

    sends it to Timer 1 to set the baud rate.

    Signal change for each roll over of timer 1

    XTAL

    oscillator 12

    32

    By UART

    Machine cycle

    frequency28800 Hz

    To timer 1

    To set the

    Baud rate

    921.6 kHz

    11.0592 MHz

    Timer 1

  • 8/8/2019 Serial Comm+Adc

    11/29

    BaudRates in the 8051

    Timer 1, mode 2 (8-bit, auto-reload)

    Define TH1 to set the baud rate.

    XTAL = 11.0592 MHz The system frequency = 11.0592 MHz / 12 = 921.6

    kHz

    Timer 1 has 921.6 kHz/ 32 = 28,800 Hz as source.

    TH1=FDH means that UARTsends a bit every 3

    timer source.

    Baud rate = 28,800/3= 9,600 Hz

  • 8/8/2019 Serial Comm+Adc

    12/29

    SCONRegister

    Serial control register: SCON

    SM0, SM1 Serial port mode specifier

    REN (Receive enable) set/cleared by softwareto enable/disable reception.

    TI Transmit interrupt flag.

    RI Receive interrupt flag.

    SM2 = TB8= TB8=0 (not widely used)

    SM0 SM1 SM2 REN TB8 RB8 TI RI

    * SCON is bit-addressable.

  • 8/8/2019 Serial Comm+Adc

    13/29

    SM0, SM1

    SM1 and SM0 determine the framing of data.

    SCON.6 (SM1) and SCON.7 (SM0)

    Only mode 1 is compatible with

    COM port of PC.SM1SM0 Mode Operating Mode BaudRate

    0 0 0 Shift register Fosc./12

    0 1 1 8-bit UART Variable by timer1

    1 0 2 9-bit UART Fosc./64 or Fosc./32

    1 1 3 9-bit UART Variable

  • 8/8/2019 Serial Comm+Adc

    14/29

    REN (Receive Enable)

    SCON.4

    Set/cleared by software to enable/disable reception.

    REN=1

    If we want the 8051 to both transfer and

    receive data, REN must be set to 1.

    REN=0

    The receiver is disabled.

    The 8051 can not receive data.

  • 8/8/2019 Serial Comm+Adc

    15/29

    TI (Transmit Interrupt Flag)

    SCON.1

    When the 8051 finishes the transfer of the 8-

    bit ch

    aracter, it raises th

    eT

    I flag. TI is raised byhardware at the beginning of

    the stop bit in mode 1.

    Must be cleared by software.

  • 8/8/2019 Serial Comm+Adc

    16/29

    RI (Receive Interrupt)

    SCON.0

    Receive interrupt flag. Set byhardware

    halfway t

    hroug

    hth

    e stop bit time in mode 1.Must be cleared by software.

    When the 8051 receives data serially via RxD,

    it gets rid of the start and stop bits and place

    the byte in the SBUF register.

    Then 8051 rises RI to indicate that a byte.

    RI is raised at the beginning of the stop bit.

  • 8/8/2019 Serial Comm+Adc

    17/29

    Transfer Data with the TI flag

    The following sequence is the steps that the 8051

    goes through in transmitting a character via TxD:

    1. The byte character to be transmitted is written into the

    SBUF register.2. It transfers the start bit.

    3. The 8-bit characteris transferred one bit at a time.

    4. The stop bitis transferred.

    SBUF

    TxD

    bit by bit

    8-bit char

    UARTTI

  • 8/8/2019 Serial Comm+Adc

    18/29

    1.Load SCON register.

    2.Laod TMOD register(select timer mode 2).

    3. Load baud rate in TH.4. Start the timer.

    5. Place character in SBUF.

    6. Monitor TI flag.

    7. Clear TI flag.

    Steps to transmit data

    from uc to pc

  • 8/8/2019 Serial Comm+Adc

    19/29

    1.Load SCON register.

    2.Laod TMOD register(select timer mode 2).

    3. Load baud rate in TH.4. Start the timer.

    5. Monitor RI flag.

    7. Read SBUF.

    8. Clear RI.

    Steps to Receive data

    from pc to uc

  • 8/8/2019 Serial Comm+Adc

    20/29

    #include

    void main()

    {

    int i;

    char arr[]="Advance Technology;

    TMOD=0x20;

    SCON=0x50;

    TH1=0xFD;

    TR1=1;

    while(1)

    {

    for(i=0;i

  • 8/8/2019 Serial Comm+Adc

    21/29

    Analog to digital

    converter (ADC)

  • 8/8/2019 Serial Comm+Adc

    22/29

    Contents

    About ADC(0809).

    Pin description of 0809 ADC.

    Interfacing with 8051.

    Programming steps.

  • 8/8/2019 Serial Comm+Adc

    23/29

    An analog-to-digital converter is a device which

    converts continuous signals to discrete digital

    numbers. The reverse operation is performed by

    a digital-to-analog converter (DAC).

    Typically, an ADC is an electronic device that

    converts an input analog voltage (or current) toa digital number proportional to the magnitude

    of the voltage or current.

    Analog to DigitalConverter

  • 8/8/2019 Serial Comm+Adc

    24/29

  • 8/8/2019 Serial Comm+Adc

    25/29

    ADC 0809

    8 analog

    Channelmultiplexing.

  • 8/8/2019 Serial Comm+Adc

    26/29

    Interfacing ofADC with 8051

  • 8/8/2019 Serial Comm+Adc

    27/29

    1.Set initial values of SOC,EOC and OE.

    2.Set ADD A, ADD B,ADD C.

    3.Low to high pulse on ALE.

    4.Low to high pulse on SOC with clock.

    5.Monitor EOC bit.

    6.Read data.7.Repeat the steps.

    Steps to interface 0809 ADC

    with 8051 uc

  • 8/8/2019 Serial Comm+Adc

    28/29

    #include

    sbit ALE=P1^3;sbit SOC=P0^0;

    sbit OE=P0^2;

    sbit EOC=P0^1;

    sbit SET0=P1^0;sbit SET1=P1^1;

    sbit SET2=P1^2;

    sbit CLOCK=P0^3;

    void clock(void);

    void delay(int x);

    void main(void)

    {

    while(1)

    {

  • 8/8/2019 Serial Comm+Adc

    29/29

    SET0=1;

    SET1=1; //for the select line

    SET2=1;

    ALE=1;SOC=1;

    clock();

    ALE=0;

    SOC=0;clock();

    while(!EOC);

    OE=1;

    P3=P2;

    }

    }

    void clock(void)

    {int a,b;

    for(b=0;b