Initialization of 20x4 lcd...
Discussion in "8051 Discussion Forum" started by sumant08 Sep 24, 2009.
Thu Sep 24 2009, 05:58 pm
I want to connect 20x4 lcd to 8051.
I am using the same .asm code which i used for 16x2 lcd.
It is displaying the data but the first line is cont. on the third line & second line on fourth line.
Is initialization code same for both the lcd ?, i.e 38h , 0ch , 01 , 06 , 80h ,0 ...
I am using the same .asm code which i used for 16x2 lcd.
It is displaying the data but the first line is cont. on the third line & second line on fourth line.
Is initialization code same for both the lcd ?, i.e 38h , 0ch , 01 , 06 , 80h ,0 ...
Thu Sep 24 2009, 09:07 pm
It is displaying the data but the first line is cont. on the third line & second line on fourth line.
Yep, the initialization is same as 16X2 LCD, the third line is the continuation of first line and fourth line that of second line.
first line address : 00h to 13h
second line address : 40h to 53h
third line : 14h to 27h
fourth line : 54h to 67h
Arun
sumant08 like this.
Thu Sep 24 2009, 10:38 pm
Thanks...
But can u pls post a demo code for displaying data on 4 different lines...
But can u pls post a demo code for displaying data on 4 different lines...
Fri Sep 25 2009, 01:57 pm
O.K sumant, here's the code i wrote for you :
and here is its working :
Arun
;*********************************************************************** ; 20X4 LCD DEMO CODE FOR 8051,WRITTEN BY ARUN KUMAR V - DATE: 25/09/09 ;*********************************************************************** $MOD51 LCD EQU P1 RS EQU P3.2 RW EQU P3.3 EN EQU P3.4 ORG 0000H MAIN: LCALL PWR_DELAY LCALL INIT LINE1: MOV A,#080H LCALL CMD MOV DPTR,#MSG_1 AGAIN1: CLR A MOVC A,@A+DPTR JZ LINE2 LCALL DAT INC DPTR SJMP AGAIN1 LINE2: MOV A,#0C0H LCALL CMD MOV DPTR,#MSG_2 AGAIN2: CLR A MOVC A,@A+DPTR JZ LINE3 LCALL DAT INC DPTR SJMP AGAIN2 LINE3: MOV A,#094H LCALL CMD MOV DPTR,#MSG_3 AGAIN3: CLR A MOVC A,@A+DPTR JZ LINE4 LCALL DAT INC DPTR SJMP AGAIN3 LINE4: MOV A,#0D4H LCALL CMD MOV DPTR,#MSG_4 AGAIN4: CLR A MOVC A,@A+DPTR JZ DONE LCALL DAT INC DPTR SJMP AGAIN4 DONE: SJMP $ ;****************************LCD SUBROUTINES**************************************** DAT: SETB EN ;H-> L PULSE ON E SETB RS ;RS=1 DATA CLR RW ;RW=0 FOR WRITE MOV LCD,A ;MOVE ACC.DATA TO PORT CLR EN NOP LCALL DDELAY RET ;****************************LCD SUBROUTINES**************************************** CMD: SETB EN ;H-> L PULSE ON E CLR RS ;RS=0 FOR COMMAND CLR RW ;RW=0 FOR WRITE MOV LCD,A ;MOVE ACC. DATA TO PORT CLR EN NOP LCALL DDELAY RET ;****************************LCD SUBROUTINES**************************************** INIT: MOV A,#038H ; INITIALIZE, 2-LINES, 5X7 MATRIX. LCALL CMD ACALL DDELAY ;INITIAL DELAY 4.1MSEC MOV A,#038H ; INITIALIZE, 2-LINES, 5X7 MATRIX. LCALL CMD ACALL DDELAY ; MOV A,#038H ; INITIALIZE, 2-LINES, 5X7 MATRIX. LCALL CMD MOV A,#0EH ; VISIBLE CURSOR ON; LCALL CMD MOV A,#01H ; CLEAR LCD SCREEN LCALL CMD MOV A,#06H ; SHIFT CURSOR RIGHT LCALL CMD RET ;****************************LCD SUBROUTINES**************************************** CLEAR: MOV A,#01H LCALL CMD RET ;****************************LCD SUBROUTINES**************************************** DDELAY: MOV R5,#41D QT2: MOV R6,#50D QT1: DJNZ R6,QT1 DJNZ R5,QT2 RET ;****************************LCD SUBROUTINES**************************************** PWR_DELAY: MOV R4,#30D H2: MOV R3,#250D H1: DJNZ R3,H1 DJNZ R4,H2 RET ORG 250H MSG_1: DB "THIS IS LINE1 OF LCD",00H MSG_2: DB "THIS IS LINE2 OF LCD",00H MSG_3: DB "THIS IS LINE3 OF LCD",00H MSG_4: DB "THIS IS LINE4 OF LCD",00H END
and here is its working :
Arun
nischay kumar, sumant08 like this.
Powered by e107 Forum System