8051 Microcontroller Lab Manual Lab 07

download 8051 Microcontroller Lab Manual Lab 07

of 5

Transcript of 8051 Microcontroller Lab Manual Lab 07

  • 7/22/2019 8051 Microcontroller Lab Manual Lab 07

    1/5

    Microprocessor & Microcontroller Lab Lab 07: LCD Interfacing

    DEE, Faculty of Engineering & Technology, International Islamic University, Islamabad Page 22

    Lab 07: LCD Interfacing

    Objective:

    1. To interface the LCD with 8051 in 8 bit mode

    2. Code 8051 for display of alphabets on LCD

    Introduction:

    The LCD available on the 8051 development board is 2x16 LCD which means that this LCD candisplay 16 characters in a line and there are 2 lines. So maximum 32 characters can be displayedon the 16x2 LCD at a time.Each character is displayed in a 5x7 pixel matrix. There are two registers in an LCD:

    1) Data Register:

    Data register contains the character to be displayed on the LCD. Data is the ASCII value of

    the character to be displayed

    2) Command / Instruction Register:

    Stores the command / instructions given to the LCD. A command or instruction performsthe predefined task for the LCD. Some of the predefined tasks are clearing the screen,Moving / setting cursor, scrolling the display etc. Some of the commands / instructions aregiven in the Table 2.

    Table 2: Pin Description of 16x2 LCD

    PIN SYMBOL I/O DESCRIPTION

    1 Vss - Power supply (GND)2 Vcc - Power supply (+5V)

    3 Vdd - Contrast Adjustment

    4 RS I0 = Select command register

    1 = Select data register

    5 R/W I0 = Write to LCD

    1 = Read from LCD

    6 E IA high to low pulse (minimum 450ns wide) is given when data issent to data pins

    7 DB0 I/O Data bit line 0 (LSB)

    8 DB1 I/O Data bit line 1

    9 DB2 I/O Data bit line 210 DB3 I/O Data bit line 3

    11 DB4 I/O Data bit line 4

    12 DB5 I/O Data bit line 5

    13 DB6 I/O Data bit line 6

    14 DB7 I/O Data bit line 7 (MSB)

    15 LED+ - Backlight Vcc +5V

    16 LED- - Backlight GND 0V

  • 7/22/2019 8051 Microcontroller Lab Manual Lab 07

    2/5

    Microprocessor & Microcontroller Lab Lab 07: LCD Interfacing

    DEE, Faculty of Engineering & Technology, International Islamic University, Islamabad Page 23

    Pin No. 4, RS:

    Register Select (RS) Pin of LCD is used to select between Command Register and Data

    Register. If RS is set, Data Register is selected and if RS is zero, Command Register is selected.

    Pin No. 5, R/W:

    Read / Write (R/W) Pin of LCD is used to select whether to read from LCD or writesomething on the LCD. IF R/W pin is set, Read operation is performed. IF R/W is zero, a command

    / data can be written on the LCD.

    Pin No. 6, E:

    Enable (E) Pin of LCD is used to enable the LCD. When this bit goes from low to high, write

    operation is performed.

    To send data on the LCD, data is first written to the data pins with R/W = 0 (to

    specify the write operation) and RS = 1 (to select the data register). A high to low pulse is

    given at E pin when data is sent. Each write operation is performed on the positive edge of

    the Enable signal.To send a command on the LCD, a particular command is first specified to the datapins with R/W = 0 (to specify the write operation) and RS = 0 (to select the command

    register). A high to low pulse is given at E pin when data is sent.

    Pin No. 7-14, D0-D7:

    There are the data bits. An ASCII equivalent of the character to be displayed or a command

    required to be executed by the LCD is sent on these 8-data bits.

    Data pin8 (D7) of the LCD is busy flag and is read when R/W = 1 & RS = 0. When busy

    flag=1, it means that LCD is not ready to accept data since it is busy with the internal operations.

    Therefore before passing any data to LCD, its command register should be read and busy flagshould be checked.

    Table 2: Command list of 16x2 LCD

    S No. Command Description Command

    1 Function Set: 8-bit, 1 Line, 5x7 Dots 0x30

    2 Function Set: 8-bit, 2 Line, 5x7 Dots 0x38

    3 Function Set: 4-bit, 1 Line, 5x7 Dots 0x20

    4 Function Set: 4-bit, 2 Line, 5x7 Dots 0x28

    5 Display off Cursor off(clearing display without clearing DDRAM content)

    0x08

    6 Display on Cursor on 0x0E

    7 Display on Cursor off 0x0C

    8 Display on Cursor blinking 0x0F

    9 Shift entire display left 0x18

    10 Shift entire display right 0x1C

  • 7/22/2019 8051 Microcontroller Lab Manual Lab 07

    3/5

    Microprocessor & Microcontroller Lab Lab 07: LCD Interfacing

    DEE, Faculty of Engineering & Technology, International Islamic University, Islamabad Page 24

    11 Move cursor left by one character 0x10

    12 Move cursor right by one character 0x14

    13 Clear Display (also clear DDRAM content) 0x01

    14 Return Home 0x02

    15 During write operation only shift cursor left (decrement cursor) 0x04

    16 During write operation only shift cursor right (increment cursor) 0x06

    17 Force the cursor at first line, position zero 0x80

    18 Force the cursor at second line, position zero 0xC0

    Fig 1: 8051 Development Board - Layout of LCD Interface and 8051 Input Output Ports

    C Code for LCD Programming:

    //ThisprogramdisplaysthealphabetfromAtoZontwolinesofLCD#includesbitRS=P1^0; //RegisterSelectPinonP1^0sbitRW=P1^1; //ReadorWriteSelectPinonP1^1sbitE=P1^2; //EnableSelectPinonP1^2sbitBF=P2^7; //BusyFlagonMSBofDataPortchardata1;

  • 7/22/2019 8051 Microcontroller Lab Manual Lab 07

    4/5

    Microprocessor & Microcontroller Lab Lab 07: LCD Interfacing

    DEE, Faculty of Engineering & Technology, International Islamic University, Islamabad Page 25

    intready() //ForcheckingthattheLCDisreadyornot?{

    charch;for(ch=0;ch

  • 7/22/2019 8051 Microcontroller Lab Manual Lab 07

    5/5

    Microprocessor & Microcontroller Lab Lab 07: LCD Interfacing

    DEE, Faculty of Engineering & Technology, International Islamic University, Islamabad Page 26

    delay(50);LCD_Initialize();for(data1='A';data1