Evert Haywood

Embed Size (px)

Citation preview

  • 8/8/2019 Evert Haywood

    1/14

    Evert Haywood

    207139920

    Logic design 3

    Assignment 1

  • 8/8/2019 Evert Haywood

    2/14

    Index:

    1. Introduction2. Objective of assignment3. Block Diagram & Operation4. Circuit Diagrams5. Program6. Conclusion7. Appendix

  • 8/8/2019 Evert Haywood

    3/14

    1. Introduction

    Serial communication is a popular means of transmitting data between a computer and a peripheral

    device such as a programmable instrument or even another computer. Serial communication uses atransmitter to send data, one bit at a time, over a single communication line to a receiver. You can use

    this method when data transfer rates are low or you must transfer data over long distances. Serial

    communication is popular because most computers have one or more serial ports, so no extra

    hardware is needed other than a cable to connect the instrument to the computer or two computerstogether.

    Figure 1: 1: RS-232 Instrument,2: RS-232 Cable, 3: Serial Port

    Serial communication requires that you specify the following four parameters:

    y The baud rate of the transmissiony T

    he number of data bits encoding a charactery The sense of the optional parity bity The number of stop bits

    Each transmitted character is packaged in a character frame that consists of a single start bit followed

    by the data bits, the optional parity bit, and the stop bit or bits. Figure 2 shows a typical character

    frame encoding the letterm.

    Figure 2

  • 8/8/2019 Evert Haywood

    4/14

    DB9 connector

    DB 25 connector

  • 8/8/2019 Evert Haywood

    5/14

    2. Objective of assignmentDevelop a microprocessor module to transmit and receive data between a micro and PC using

    RS232. Data received from the PC must be displayed on a LCD display driven by the selectedmicro. Data sent to the PC must be displayed On the PC screen using terminal software. A keypadconnected to your microprocessor module will supply the data that is sent to the PC.

    3. Block diagram and operationBlock diagram:

    RS232 Block diagram

  • 8/8/2019 Evert Haywood

    6/14

    Operation:

    A serial protocol is used to transmit and receive data one bit at a time between

    the microprocessor and PC.Data received from the PC is displayed on a 16 X 2

    LCD display driven by the 80C31 microprocessor. Data sent to the PC is

    displayed on the PC screen using terminal (Real Terminal) software. A 4 X 4keypad connected to the microprocessor module supplys the data that is sent

    to the PC.

    4. Circuit DiagramsGreen board

    4. Program:

    /*****************************************

    **

    Evert Haywood

  • 8/8/2019 Evert Haywood

    7/14

    207139920

    ******************************************************/

    #include

    #include

    #include

    #include

    #define LCDlen 16

    #define DataAddr 0x6001

    #define CommAddr 0x6000

    #define Time5ms 50

    #define Time20ms 220

    #define Time1s 21800

    unsigned char ValIn, ValOut;

    void ISR_Serial_RX(void) interrupt 4

    {

    Tl = 0; //Transmit int flag

    if(RI){

    ValIn = SBUF;

    RI = 0; // receive interrupt flag

    }

    }

    //***********************************************

    //*********************************************

  • 8/8/2019 Evert Haywood

    8/14

    /*************************************************/

    void ISR_Keypad(void) interrupt 0{ //EXTERNAL0{

    unsigned char Lookup[16] = {'1','4','7','#','2','5','8','0','3','6','9','*','A','B','C','D'};

    static unsigned char Buffer;

    Buffer = XBYTE[0X2000] & 0X0F; //Read and mask data from 922

    ValOut = Lookup[Buffer]; //Display on port P1

    while(!P3_2){;} //Wait for key to be released

    }

    /*************************************************/

    const unsigned char clear[LCDlen+1]=" ";

    /********************************

    Delay Routine

    ********************************/

    void Delay(unsigned long TimeCnt){

    unsigned long Cntr;

    for (Cntr = 0; Cntr < TimeCnt; Cntr++){;}

    }

    void Init_Serial(void)

    { //INITIALIZE SERIAL COMMS

    SCON = 0x50; //Serial port control register Sm=1 Ren =1

    TMOD = 0X20; // 8bit auto reload timer

  • 8/8/2019 Evert Haywood

    9/14

    TH1 = 253; // Load timer hi for baud rate

    PCON = 0X00; // Program counter reset

    TR1 = 1; //Timer 1 enable

    }

    /***************************************

    LCD write Command from LCD.C

    **************************************/

    void LCD_Command_Wr(unsigned char Command){

    XBYTE[CommAddr] = Command;

    Delay(Time5ms); // Delay 5ms

    }

    /******************************************************

    Initialise LCD Display on Data Bus from LCD.C

    RW must be grounded RS connected to A0

    ******************************************************/

    void Init_LCD(void){

    unsigned char Teller;

    Delay(Time20ms); // 20 msec

    for(Teller = 3; Teller > 0; Teller--)

    {

    LCD_Command_Wr(0x30); // Function set

    }

    LCD_Command_Wr(0x3C);

    LCD_Command_Wr(0x08); // Display off

  • 8/8/2019 Evert Haywood

    10/14

    LCD_Command_Wr(0x01); // Display on

    LCD_Command_Wr(0x06); // Entry mode set

    LCD_Command_Wr(0x0C);

    Delay(Time20ms); // Delay 20ms

    }

    /****************************************************

    Write a Single ASCII Character to a 16x2 LCD Display

    Y = line 0 or 1

    X = Position 0 to 15 on the line

    Ch = ASCII character to be written on LCD

    ****************************************************/

    void LCD_Data_Wr(unsigned char X, unsigned char Y, unsigned char Ch){

    unsigned char Offset;

    switch (Y){

    case 0:

    Offset = 0x00;

    break;

    case 1:

    Offset = 0x40;

    }

    LCD_Command_Wr((Offset + X) | 0x80); // Position the cursor

    XBYTE[DataAddr] = Ch; //Write ASCII data to the display

    Delay(Time5ms); // Delay 5 ms

    }

    //***********************************************

  • 8/8/2019 Evert Haywood

    11/14

    void ClearScreen(void){

    unsigned char i;

    for(i=0;i

  • 8/8/2019 Evert Haywood

    12/14

    while(1){

    TI = 0; //Must be one before next char can

    go out

    if(ValOut){

    EA = 0;

    TI = 1; // transmit interupt

    _nop_();

    TI = 0;

    SBUF = ValOut; //Transmit value pressed

    while(!TI);

    TI = 0;

    EA = 1; interrupt enable

    ValOut = 0x00; //Clear register

    }

    if(ValIn){

    LCD_Data_Wr(x, y, ValIn);

    x=x+1;

    P1=ValIn;

    if (x==16)

    {

    y=y+1;

    x=0;

  • 8/8/2019 Evert Haywood

    13/14

    if (y==2)

    {

    ClearScreen();

    y=0;

    x=0;

    }

    }

    ValIn = 0x00;

    }

    }

    }

    5. ConclusionCommunication between a microcontroller and a PC was achieved using serial data transmission. TheRS 232 standard was used. When a key on the microcontroller keypad was pressed it was displayed

    on the PC screen in the Hyper terminal and when a key on the PC keyboard was pressed it was

    displayed on the microcontrollers screen. Full sentences can be displayed on both devices.

    Appendix

  • 8/8/2019 Evert Haywood

    14/14