MicroController Pros Home Page
My Account  Cart Contents  Checkout  
  Store » PCAM+ 8051 Tutorial 4 My Account  |  Cart Contents  |  Checkout   
Quick Find
 
Enter keywords to find the product you are looking for in the Quick Find field above

or use
Advanced Search
Categories
Accessory Boards->
8051->
ADI Blackfin
Arduino->
ARM->
Atmel AVR->
Cypress PSoC
Freescale->
FTDI->
Fujitsu
Locktronics
Maxim
Microchip PIC->
MIPS
National Semiconductor
Parallax->
Renesas->
Silicon Labs
ST Microelectronics->
Texas Instruments->
Tibbo->
Zilog
Books->
Displays->
E-Blocks
EEPROM/EPROM/FLASH
Embedded Ethernet->
Embedded Software->
I/O Modules->
Parts & Components->
Pick & Place Tools
Programmable Logic (PLD)
Prototype PCBs->
Robotics
ROM/Flash Emulators
Test & Measurement->
Tutorial CD-ROMs
Universal Programmers->
Wireless->
Information
Intro to Embedded Tools
Embedded News Digest
Useful Resources
Shipping & Returns
Warranty & Liability
Privacy Notice
Conditions of Use
Contact Us
PCAM+ 8051 Tutorial 4: LCD Interface

Back to PCAM+ page.


Back to Chapter 3

LCD Interface with 8051 Microcontroller

The LCD Provided with the PCAM+ kit is a 162 type. This means that the LCD can display 16 characters per line and there are 2 lines on the LCD. These LCDs are widely used in a variety of applications that you find in everyday use.

This chapter explains the interfacing of the LCD with the 89S52 microcontroller using assembly syntax.

First, mount the LCD onto the PCAM+ as shown in the picture below:

Use the single-pin Female-to-Female connecting wires to make following connections:

  • Connect P0 of the 89S52 (all 8 pins in sequence from 0 to 7) to the LCD section's 0 to 7 pins. See the marking near the LCD pins for identification.
  • Connect P2.0 to RS pin of LCD section
  • Connect P2.1 to RW pin of LCD section
  • Connect P2.2 to EN pin of LCD section

Write the following program using 8051IDE:

EN      EQU     P2.2    ;change as per your connections
RS      EQU     P2.0    ;change as per your connections
RW      EQU     P2.1    ;change as per your connections
PDATA   EQU     P0      ;change as per your connections

START:
        LCALL INIT_LCD
        LCALL CLEAR_LCD
        LCALL PRINT_MESSAGE
END_LESS_LOOP:
SJMP END_LESS_LOOP

INIT_LCD:
        CLR RS
        MOV PDATA,#00110100b
        SETB EN
        CLR EN
        LCALL WAIT_LCD

        CLR RS
        MOV PDATA,#00111100b
        SETB EN
        CLR EN
        LCALL WAIT_LCD

        CLR RS
        MOV PDATA,#0Ch
        SETB EN
        CLR EN
        LCALL WAIT_LCD

        CLR RS
        MOV PDATA,#06h
        SETB EN
        CLR EN
        LCALL WAIT_LCD
RET

;NOTE: Copy character to be displayed in A
WRITE_TEXT:
        SETB RS
        MOV PDATA,A
        SETB EN
        CLR EN
        LCALL WAIT_LCD
RET

CLEAR_LCD:
        CLR RS
        MOV PDATA,#01h
        SETB EN
        CLR EN
        LCALL WAIT_LCD
RET

WAIT_LCD:
        CLR EN
        CLR RS
        SETB RW
        MOV PDATA,#0FFh
        SETB EN
        MOV A,PDATA
        JB ACC.7,WAIT_LCD
        CLR EN
        CLR RW
RET

PRINT_MESSAGE:
        MOV A,#'E'
        LCALL WRITE_TEXT

        MOV A,#'M'
        LCALL WRITE_TEXT

        MOV A,#'B'
        LCALL WRITE_TEXT

        MOV A,#'E'
        LCALL WRITE_TEXT

        MOV A,#'D'
        LCALL WRITE_TEXT

        MOV A,#'D'
        LCALL WRITE_TEXT

        MOV A,#'E'
        LCALL WRITE_TEXT

        MOV A,#'D'
        LCALL WRITE_TEXT

        MOV A,#'M'
        LCALL WRITE_TEXT

        MOV A,#'A'
        LCALL WRITE_TEXT

        MOV A,#'R'
        LCALL WRITE_TEXT

        MOV A,#'K'
        LCALL WRITE_TEXT

        MOV A,#'E'
        LCALL WRITE_TEXT

        MOV A,#'T'
        LCALL WRITE_TEXT

;This is how to print characters on second line of the LCD

        CLR RS
        MOV PDATA,#0C4h
        SETB EN
        CLR EN
        LCALL WAIT_LCD
        MOV A,#'H'
        LCALL WRITE_TEXT

        CLR RS
        MOV PDATA,#0C5h
        SETB EN
        CLR EN
        LCALL WAIT_LCD
        MOV A,#'E'
        LCALL WRITE_TEXT

        CLR RS
        MOV PDATA,#0C6h
        SETB EN
        CLR EN
        LCALL WAIT_LCD
        MOV A,#'L'
        LCALL WRITE_TEXT

        CLR RS
        MOV PDATA,#0C7h
        SETB EN
        CLR EN
        LCALL WAIT_LCD
        MOV A,#'L'
        LCALL WRITE_TEXT

        CLR RS
        MOV PDATA,#0C8h
        SETB EN
        CLR EN
        LCALL WAIT_LCD
        MOV A,#'O'
        LCALL WRITE_TEXT

        CLR RS
        MOV PDATA,#0C9h
        SETB EN
        CLR EN
        LCALL WAIT_LCD
        MOV A,#'.'
        LCALL WRITE_TEXT

        CLR RS
        MOV PDATA,#0CAh
        SETB EN
        CLR EN
        LCALL WAIT_LCD
        MOV A,#'.'
        LCALL WRITE_TEXT

        CLR RS
        MOV PDATA,#0CBh
        SETB EN
        CLR EN
        LCALL WAIT_LCD
        MOV A,#'.'
        LCALL WRITE_TEXT
RET

This lengthy code actually is simple. It is divided into initialization of the LCD and writing text on it.

Save the above code and assemble from 8051IDE. Use Handyprog-USB Programmer to download the generated HEX to the 89S52 controller.

Assuming the PCAM+ hardware is powered, the LCD should display EMBEDDEDMARKET on the first line and HELLO... on the second line.

Proceed to Chapter 5


Back to PCAM+ page.

Shopping Cart more
0 items
What's New? more
Arduino WiFi Shield, CC3000, IEEE 802.11b/g, SD, WiMAX Antenna
Arduino WiFi Shield, CC3000, IEEE 802.11b/g, SD, WiMAX Antenna
US$39.95
Bestsellers
01. 2x10 Pin male header, 2.54mm, 7.5mm plastic spacer
02. 2x5 (10-pin) 0.1" pitch IDC Connector Flat Ribbon Cable, 15cm
03. 2x5 (10-pin) 0.05" pitch IDC Connector Flat Ribbon Cable, 20cm
04. 2x10 (20-pin) 0.1" pitch IDC Connector Flat Ribbon Cable, 15cm
05. PIC16F877A-I/P Microcontroller, 40 DIP, 20 MHz
06. USB-to-Serial Cable: 5V TTL, Audio Plug Connector, Reverse RX/TX
07. LCD 4-mux, 7.1 digits x 7 segments, progress bar, arrows
08. Power Supply 3-12V DC, U.S. plug, 6 connection tips
09. 2x3 (6-pin) 0.1" pitch IDC Connector Flat Ribbon Cable, 15cm
10. PIC16F628A-I/P Microcontroller, 18 DIP, 20 MHz
Specials more
LED, Red 5mm 632nm, pack of 10
LED, Red 5mm 632nm, pack of 10
US$1.30
US$0.90
Reviews more
Microchip PIC Board, 40-pin, USB, 16x2 LCD
This is a great little board that allowed us to get a very s ..
5 of 5 Stars!
  Thursday 24 April, 2014   List of all our Products

Copyright © 2003-2014 MicroController Pros LLC
Powered by osCommerce