AT 89c51 and LCD

Status
Not open for further replies.

Peter Nabil

New Member
Hi every single one how r u doing??

Well i have an LCD HD44780U (16 pin) and i wanna connect it to the AT 89c51 and so i did but the problem is when i open the cct. nothing at all appears on the LCD although every thing is connected very well so if u PlZ read my program and tell me if there is any thing wrong with it thax a loooooot

ORG 0H ;
Mov A, #38 H ; Init LCD 2 lines, 5*7 Matrix
LCALL Command ; Issue command
LCALL Sarah ;
Mov A, # 'A' ;
Mov R0, # 30 H; RAM address pointer
Mov R1, # 40 ; counter
Again: Mov @R0, A ;
I NC R0;
DJNZ R1, Again
Mov R2, # 16 ; counter
Mov R0, # 30 H ; RAM address pointer
LCALL Juliet
Mov A, # 40 ; write at the second line
LCALL Command
Mov R2, #16 ; counter
Mov R0, # 30 H ; pointer
LCALL Juliet

Juliet: Mov A, @R0 ; Move from RAM to A
LCALL Romeo
INC R0 ; increment pointer
DJNZ R2, Juliet ;
LCALL LCD_Delay ; 2 Seconds delay
RET

Sarah: Mov A, #0E H ; LCD on, cursor on
LCALL Command ; issue command
Mov A, #01 H ; Clear LCD command
LCALL Command ; issue command
Mov A, #06 H ; Shift cursor right
LCALL Command ; issue command
Mov A, #80H ; Move to the 2nd line
LCALL Command ; issue command
RET


Command: ACALL Ready
Mov P1, A
CLR P2.5
CLR P2.6
SETB P2.7
CLR P2.7
RET

Romeo: ACALL Ready
Mov P1, A
SETB P2.5
CLR P2.6
SETB P2.7
CLR P2.7
RET

Ready: SETB P1.7
CLR P2.5
SETB P2.6
Back: CLR P2.7
SETB P2.7
JB P1.7, Back
RET
LCD_Delay: Mov R4, #07
Pet: Mov R5, #255
Mag: Mov R6, #255
Hera: NOP
NOP
DJNZ R6, Hera
DJNZ R5, Mag
DJNZ R4, Pet
RET
END



Thx again








[/b]
 
Can't help with your code, but if you turn the contrast up you should get solid black characters displayed - this happens even without the display connected to a micro.
 
The HD44780 needs a very complicated initialization procedure upon power ON.

It is not simply as just sending one command. You have to do it several times with some waiting in between.

I suggest you read its datasheet and follow the words on how to initialise the chip to the letter.

Here is my version.
Code:
;#################################################################
;
;SUBROUTINES - LCD_INIT				    lcd_init
;
;FUNCTION: initialise LCD display when power ON
;
;   ENTRY: none
;   USING: a,r0,r7
; DESTROY: r7
;  AFFECT: r7,flags
;
; CALLING: wait_ms
;          lcd_cmd
;#################################################################
;
lcd_init:
        clr p2.7
        mov r0,#lcd_cmd_wr      ;set command register address
	mov a, #30h		;set 30h
	movx @r0,a	   	;send command using MOVX
	mov wait_count,#6	;wait 6 ms  (book >4.1ms)
        call wait_ms
	;
	mov a,#30h
	movx @r0,a		;send 30h
	mov wait_count,#1
        call wait_ms            ;wait 1 ms  (book >.1mS)
	;
	mov a,#30H
	movx @r0,a
	mov r0,#lcd_cmd_rd
$1:	movx a,@r0
	jb acc.7,$1		;wait until LCD not busy
	;
	mov a,#38h		;start formal initialisation
        call lcd_cmd
	;
	mov a, #00001100b	;turn on display & no cursor
        call lcd_cmd
	mov a, #06h		;set increment address counter
        call lcd_cmd
	mov a,#lcd_clr		;lcd clear
        call lcd_cmd
	mov wait_count,#3	;wait 3mS for it to complete
        call wait_ms
	;
	ret



;################################################################
;

Edited: "unitl" corrected to read "until" in code comment.
 
Jay.slovak said:
Just curious, why did you eblc1388 made that strange "double post"? :lol:

I saw a spelling mistake "unitl" in the code comment but what I really meant is "until".

I have not logged in so when I submit I double posted. I cannot delete my post.
 
Oh, that explains it... np

BTW I really hate that we are unable to delete our own posts... :cry:
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…