Writing a String on Hitachi LCD using AT89S52

Thread Starter

KiroloesAmir035

Joined Jan 6, 2021
5
I try writing a string instead of writing letter by letter. So, I tried this code:

LCD:
                ORG 00H
                RS BIT P2.7
                E BIT P2.6
                MOV SP, #25H
                MOV P1, #00H
                MOV P2, #00H
                MOV TMOD, #01H
                
;;;;;;;;;;;;;;;;;;;;;;;;;;;COMMANDS;;;;;;;;;;;;;;;;;;;;;;;;;;;
                ACALL COMMANDS
;;;;;;;;;;;;;;;;;;;;;;;;;;;PRINTING;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;               
                
                MOV DPTR, #STRING1
                ACALL STRING_PRNT
                

;;;;;;;;;;;;;;;;;;;;;;;;;;;NO LOOPING;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;               
                
HERE:            SJMP HERE

;;;;;;;;;;;;;;;;;;;;;;;;;;;COMMAND FUNCTION;;;;;;;;;;;;;;;;;;;;;;;;;;
COMMANDS:
                
                MOV R1, #32H
                ACALL DELAY_MS
                
                MOV P1, #30H            ;8-BIT INITIALIZATION
                CLR RS                    ;COMMAND MODE
                SETB E
                ACALL DELAY_MS
                CLR E
                ACALL DELAY_MS
                MOV R1, #05H            ; 5MS DELAY
                ACALL DELAY_MS

                MOV P1, #30H            ;8-BIT INITIALIZATION
                CLR RS                    ;COMMAND MODE
                SETB E
                ACALL DELAY_MS
                CLR E
                ACALL DELAY_MS
                MOV R1, #0DH            ; 4MS DELAY
                ACALL DELAY_US

                MOV P1, #30H            ;8-BIT INITIALIZATION
                CLR RS                    ;COMMAND MODE
                SETB E
                ACALL DELAY_MS
                CLR E
                ACALL DELAY_MS
                MOV R1, #0DH            ; 4MS DELAY
                ACALL DELAY_US

                MOV P1, #20H            ;4-BIT WITH 1 LINE INITIALIZATION
                CLR RS                    ;COMMAND MODE
                SETB E
                ACALL DELAY_MS
                CLR E
                ACALL DELAY_MS
                MOV R1, #0DH            ;50 MICROSECONDS DELAY
                ACALL DELAY_US
                
                MOV R0, #28H            ;4-BIT MODE OF LCD INITIALIZATION
                ACALL CMD               
                MOV R1, #0DH            ;50 MICROSECONDS DELAY
                ACALL DELAY_US
    
                MOV R0, #08H            ;DISPLAY ON, CURSOR ON
                ACALL CMD               
                MOV R1, #05H            ;50 MICROSECONDS DELAY
                ACALL DELAY_US
                
                
                MOV R0, #01H            ;CLEAR LCD
                ACALL CMD
                MOV R1, #02H            ;2 MS DELAY
                ACALL DELAY_MS

                MOV R0, #06H            ;ENTRY MODE
                ACALL CMD               
                MOV R1, #05H            ;50 MICROSECONDS DELAY
                ACALL DELAY_US
                
                MOV R0, #0EH
                ACALL CMD
                MOV R1, #05H
                ACALL DELAY_US
                
                MOV R0, #80H            ;HOME CURSOR
                ACALL CMD
                MOV R1, #02H            ;2 MS DELAY
                ACALL DELAY_MS
                MOV R1, #14H            ;20 MS DELAY
                ACALL DELAY_MS

                RET
CMD:           
;SENDING THE UPPER NIBBLE
                MOV A, R0
                ANL A, #0F0H
                MOV P1, A
                CLR RS                    ;COMMAND MODE
                SETB E
                MOV R1, #01H
                ACALL DELAY_MS
                CLR E
                MOV R1, #01H
                ACALL DELAY_MS
;SENDING THE LOWER NIBBLE
                MOV A, R0
                ANL A, #0FH
                SWAP A
                MOV P1, A
                CLR RS
                SETB E
                MOV R1, #01H
                ACALL DELAY_MS
                CLR E
                MOV R1, #01H
                ACALL DELAY_MS
                RET
                
;;;;;;;;;;;;;;;;;;;;;;;;;;;PRINT FUNCTION;;;;;;;;;;;;;;;;;;;;;;;;;;;               
                
PRNT:
                MOV R0, #0EH
                ACALL CMD
                MOV R1, #05H
                ACALL DELAY_US

;SENDING THE UPPER NIBBLE
                MOV A, R0
                ANL A, #0F0H
                MOV P1, A
                SETB RS                    ;DATA MODE
                SETB E
                MOV R1, #01H
                ACALL DELAY_MS
                CLR E
                MOV R1, #01H
                ACALL DELAY_MS
;SENDING THE LOWER NIBBLE
                MOV A, R0
                ANL A, #0FH
                SWAP A
                MOV P1, A
                SETB RS
                SETB E
                MOV R1, #01H
                ACALL DELAY_MS
                CLR E
                MOV R1, #01H
                ACALL DELAY_MS
                
                MOV R0, #0CH
                ACALL CMD
                MOV R1, #05H
                ACALL DELAY_US
                
                MOV R1, #01H
                ACALL DELAY_MS

                RET
                
                
            
STRING_PRNT:
                CLR A
                MOVC A, @ A + DPTR
                MOV R0, A
                ACALL PRNT
                INC DPTR
                JZ SAD
                SJMP STRING_PRNT
SAD:            RET
;;;;;;;;;;;;;;;;;;;;;;;;;;;;DELAY FUNCTION;;;;;;;;;;;;;;;;;;;;;;;;;;               
                
DELAY_MS:           
                MOV TH0, #0F8H
                MOV TL0, #30H
                SETB TR0
LOOP:            JNB TF0, LOOP
                CLR TR0
                CLR TF0
                DJNZ R1, DELAY_MS
                RET
                
                
                
DELAY_US:        MOV TH0, #0FFH
                MOV TL0, #0ECH
                SETB TR0
LOOP1:            JNB TF0, LOOP1
                CLR TR0
                CLR TF0
                DJNZ R1, DELAY_US
                RET
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;               
                ORG 500H
STRING1:        DB "HELLO WORLD",0
    
                END
but the DPTR value is increasing until infinity and the string is not written on the LCD
what should I do to solve this problem ?
 

Ian Rogers

Joined Dec 12, 2012
948
Code:
STRING_PRNT:
                CLR A
                MOVC A, @ A + DPTR
                MOV R0, A
                ACALL PRNT
                INC DPTR
                JZ SAD
                SJMP STRING_PRNT
SAD:            RET
You are not checking for the "NULL" terminator..

Code:
STRING_PRNT:
                CLR A
                MOVC A, @ A + DPTR
                JZ SAD
                MOV R0, A
                ACALL PRNT
                INC DPTR
                SJMP STRING_PRNT
SAD:            RET
Now if A is zero the routine will end..
 
Top