Writing text on LCD Module using 89C51

Muhammad Kamran, [email protected]

Department of Electronics, University of Peshawar,

Peshawar, NWFP, 25120, Pakistan.


Electronic Projects    Courses    My Links    Articles    Contacts    Students Resources


Nowadays many people are using LCD modules in their projects, because it can be interfaced with any micro controller very easily, actually there are different configurations by which we can connect LCD with controller, but in this article i will tell you that how we can use LCD module as memory mapped i/o. by this technique the controller will consider the LCD module just like any memory location in the X-RAM. in the circuit shown below i have configured the LCD module Command Register at address 00H and Data Register at 01H, so when ever we will write the data at address 00H, it will be considered as command for LCD, and when ever at 01H, it will be considered as ASCII character to be write. the following table shows addresses for different read write operations.

NO

Operation

Address

1

Command Write

00H

2

Data Write

01H

3

Command Read

02H

4

Data Read

03H

Table "1"

        The following sequence of instructions can be used to write commands and data.


  To write a command into command register.

                MOV A,#38H             ; the command 38H will move into Accumulator.
                MOV R0,#00H           ; move the address of command register into R0.
                MOVX @R0,A           ; write the contents of A to command register.

    

 To write an ASCII character on LCD module.

                MOV A,#41H             ; the ASCII code of Uppercase "A" will move.
                MOV R0,#01H           ; move the address of data register into R0.
                MOVX @R0,A           ; write the contents of A on LCD display.


    To use the LCD module as memory mapped i/o as explained above we will have to do the following connections with micro controller, since the address and data both will transfer through Port "0", therefore we will have to use an Octal Latch 74573. the PCB layout is also available to download. an example program is also available to download,

Circuit diagram.

In the table 2 i have given the detail of different commands, from this table one can make different commands by himself .

Table "2"

Here i have given different subroutines, by combining which we can make a complete program, first of all i will show you the subroutine for initialization of LCD module.

mov a,#06h                ;Command for character entry mode.
acall wrtcmd
mov a,#38h                ; 8 Bit mode, 2 lines and 5*7 dots /char.
acall wrtcmd
mov a,#0fh                ;Command for Display cursor on/off.
acall wrtcmd
mov a,#01h                ;Command to clear display.
acall wrtcmd 
mov a,#02h                ;Command for Cursor home.
acall wrtcmd              ; Commands ends here.

The second subroutine will write one command word into the command register. before calling this subroutine the command word should be there in accumulator.

           wrtcmd:     mov r1,#00h
                              movx @r1,a
                              acall delay
                              acall delay
                              acall delay            ; 3 times delay subroutine .
                              ret

This third subroutine will write one ASCII character into the command register. before calling this subroutine the ASCII character should be there in accumulator.


            wrtcmd:     mov r1,#01h
                              movx @r1,a
                              acall delay
                              acall delay
                              acall delay            ; 3 times delay subroutine .
                              ret

This fourth subroutine will produce the delay of approximately 22 msec, if execute for 3 times it will produce delay of 66 msec.

                delay:      mov r2,#150
                reload:    mov r3,#150
                again:     djnz r3,again
                               djnz r2,reload
                               ret

I have also written a library in C Language, by which we can write any type of data on LCD using C language, there are many built in functions which can be called from any "KEIL C" program, and all necessary files including that library can be download from the link given below.

1.    Complete program for Writing character strings by using above subroutines.

2.    Library for LCD Functions including schematics and example program in C Language.

3.    Schematic in PDF format.

4.    PCB File for the above circuit. (will be available very soon)


Electronic Projects    Courses    My Links    Articles    Contacts    Students Resources


Last Updated: March 02, 2004.

Hosted by www.Geocities.ws

1