Tuesday, October 18, 2011

Simple LCD interfacing program with 8051 microcontroller

so we have three control pins to take care of.
so lets program using these 3 control pins.
; P2.0 EQU RS
; P2.1 EQU RW
; P2.2 EQU E
ORG 0000H    ;
MOV A, #38H    ; INITIATE LCD
ACALL COMMWRT    ;
ACALL DELAY    ;

MOV A, #0EH    ; DISPLAY ON CURSOR ON
ACALL COMMWRT    ;
ACALL DELAY    ;

MOV A, #01H    ; CLEAR LCD
ACALL COMMWRT    ;
ACALL DELAY    ;

MOV A, #84H    ; CURSOR AT LINE 1 POSITION 4
ACALL COMMWRT    ;
ACALL DELAY    ;

MOV A, #'A'    ; SEND ASCII DATA
ACALL DATAWRT    ;
ACALL DELAY    ;

AGAIN :
SJMP AGAIN    ;

COMMWRT:
MOV P1, A    ;
CLR P2.0    ; RS = 0 FOR COMMAND REGISTER
CLR P2.1    ; R/W = 0 FOR WRITE
SETB P2.2    ; E = 1 FOR HIGH PULSE
ACALL DELAY    ;
CLR P2.2    ; E = 0 FOR LOW PULSE
RET

DATAWRT:
MOV P1, A    ;
SETB P2.0    ; RS = 1 FOR DATA REGISTER
CLR P2.1    ; R/W = 0 FOR WRITE
SETB P2.2    ; E = 1 FOR HIGH PULSE
ACALL DELAY    ;
CLR P2.2    ; E = 0 FOR LOW PULSE
RET

DELAY :
MOV R3, #50H ;
BACK: 
MOV R4, #255H ;
HERE:
DJNZ R4, HERE ;
DJNZ R3, BACK ;
RET
END

Terms used in LCD


Terms used in LCD
display data RAM
DD RAM
display data RAM
CG RAM
character generator RAM
ACC
CG RAM address
ADD
DD RAM address corresponding to cursor address
AC
address counter used for both CG and DD
1/D = 1 for increment
1/D = 0 for decrement
S = 1 accompanies display shift

S/C = 1 display shift
S/C = 0 for cursor shift
R/L = 1 shift to right
R/L = 0 shift to left
DL = 1 8 bits
DL = 0 4 bits
F = 1 5x10 dots
F = 0 5x7 dots
BF = 1 Internal operation
BF = 0 can accept instruction

Programming LCD (basics)

Few Points for programming LCD.
>> Rs register select pin.
If RS = 0 command code register is selected or opened allowing user to send commands.
If RS = 1 data register is selected or opened allowing user to send data.

>> As LCD runs on a lower clock speed therefore proper DELAY should be provided after every command write and data write.
Usually a 255D delay is more than enough.

>> Enable pin. E. when data is supplied to data pins a high to low pulse must be applied to pin in order to latch data to

LCD pin. This must be a minimum of 450nS wide.

Steps to send command and data.
38h initialize LCD
0Eh display on cursor on.
01h clear LCD
06h shift cursor right
84h position the cursor.
now send data.

for LCD program see the next post