MicroController Pros Home Page
My Account  Cart Contents  Checkout  
  Store » PCAM+ 8051 Tutorial 6 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 6: Scrolling LCD Text

Back to PCAM+ page.


Back to Chapter 5

Scrolling LCD Text with the 89S52 Microcontroller

This chapter further explains interfacing the LCD with the 89S52 microcontroller using assembly syntax. Now, we'll make the text scroll left and right.

Let's start with the connections. First, mount the LCD onto the PCAM+ board. Next, use the single-pin 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 through 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:
        LCALL ROTATE_LEFT
        LCALL ROTATE_LEFT
        LCALL ROTATE_LEFT
        LCALL ROTATE_LEFT
        LCALL ROTATE_RIGHT
        LCALL ROTATE_RIGHT
        LCALL ROTATE_RIGHT
        LCALL ROTATE_RIGHT
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

ROTATE_RIGHT:
        CLR RS
        MOV PDATA,#1Eh
        SETB EN
        CLR EN
        LCALL WAIT_LCD
        LCALL DELAY
RET

ROTATE_LEFT:
        CLR RS
        MOV PDATA,#18h
        SETB EN
        CLR EN
        LCALL WAIT_LCD
        LCALL DELAY
RET

DELAY:
        MOV R5,#100D
        LOOP1:
                MOV R6,#25D
        LOOP2:
                MOV R7,#100D
        DELAY_LOOP:
                DJNZ R7,$
                DJNZ R6,LOOP2
                DJNZ R5,LOOP1
RET

When assembled and downloaded, this code should display EMBEDDEDMARKET on the first line and HELLO... on the second line as in an earlier chapter, but this time the text scrolls left & right.

Proceed to Chapter 7


Back to PCAM+ page.

Shopping Cart more
0 items
What's New? more
A20 Linux Board, HDMI, SATA, Gigabit Ethernet, 2x USBH, 4GB NAND
A20 Linux Board, HDMI, SATA, Gigabit Ethernet, 2x USBH, 4GB NAND
US$75.00
Specials more
XBee Explorer USB, Serial Access to XBee Pins, mini-USB
XBee Explorer USB, Serial Access to XBee Pins, mini-USB
US$24.95
US$18.00
Bestsellers
01. PIC16F877A-I/P Microcontroller, 40 DIP, 20 MHz
02. LCD 4-mux, 7 digits x 14 segments, progress bar, arrows
03. PIC16F628A-I/P Microcontroller, 18 DIP, 20 MHz
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
Flex Sensor 4.5"
crap... Design flaw where the metal terminals meet the plast ..
1 of 5 Stars!
  Wednesday 01 October, 2014   List of all our Products

Copyright © 2003-2014 MicroController Pros LLC
Powered by osCommerce