MicroController Pros Home Page My Account  Cart Contents  Checkout  

****Note: We no longer process and ship international orders. Only orders from USA and Canada are now accepted.****
You can place international orders for our products on E-Bay. Just copy the item's title description from our website and paste it into the search box on E-Bay and place your order there.

  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->
Locktronics
Microchip PIC->
MIPS
Parallax->
Renesas
Silicon Labs
ST Microelectronics->
Texas Instruments->
Tibbo->
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 Software
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 16×2 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
Level Shifter Board, 1.8V/3.3V/5V, 2 Circuits, I2C or SMBus
Level Shifter Board, 1.8V/3.3V/5V, 2 Circuits, I2C or SMBus
US$10.00
Bestsellers
01. 2x5 (10-pin) 0.05" pitch IDC Connector Flat Ribbon Cable, 20cm
02. 2x5 (10-pin) 0.05" pitch IDC Connector Flat Ribbon Cable, 12cm
03. 5-pin Press-Fit Header Strip, Breakaway Pins, 2.54mm Pitch
04. Parallel to USB Adapter: Connect USB printer to LPT port
05. 2x10 (20-pin) 0.1" pitch IDC Connector Flat Ribbon Cable, 15cm
06. 8-pin Press-Fit Header Strip, Breakaway Pins, 2.54mm Pitch
07. USB Universal In-Circuit Programmer PIC AVR ARM MSP 8051 EEPROM
08. 2x5 (10-pin) 0.1" pitch IDC Connector Flat Ribbon Cable, 15cm
09. ARM JTAG Debugger & Programmer, parallel port
10. Power Supply 3-12V DC, U.S. plug, 6 connection tips
Reviews more
Good board to evaluate the NXP LPC2129 although the micro on ..
4 of 5 Stars!
  Monday 18 March, 2024   List of all our Products

Copyright © 2003-2017 MicroController Pros LLC
Powered by osCommerce