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->
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 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
Bluetooth 4.0 mikroBUS Module, nRF8001, SPI, 3.3V (BLE P click)
Bluetooth 4.0 mikroBUS Module, nRF8001, SPI, 3.3V (BLE P click)
US$25.00
Specials more
GSM/GPRS Module for Arduino
GSM/GPRS Module for Arduino
US$103.00
US$89.00
Bestsellers
01. PIC16F877A-I/P Microcontroller, 40 DIP, 20 MHz
02. PIC16F628A-I/P Microcontroller, 18 DIP, 20 MHz
03. LCD 4-mux, 7 digits x 14 segments, progress bar, arrows
04. Atmel ATtiny2313-20PU AVR Microcontroller, 20 DIP, 20 MHz
05. LCD 4-mux, 7.1 digits x 7 segments, progress bar, arrows
06. USB Universal In-Circuit Programmer PIC AVR ARM MSP 8051 EEPROM
07. ARM JTAG Debugger & Programmer, parallel port
08. Power Supply 3-12V DC, US/UK/Euro/AU Plugs, 100-240VAC
09. Power Supply 3-12V DC, U.S. plug, 6 connection tips
10. Atmel AVR JTAG In-Circuit Debugger & Programmer, USB
Reviews more
32-pin QFP to DIP Adapter & Breakout Module
This is .8mm spacing, so be aware of that when ordering. ..
4 of 5 Stars!
  Saturday 30 August, 2014   List of all our Products

Copyright © 2003-2014 MicroController Pros LLC
Powered by osCommerce