Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

assembly code for lcd display

Status
Not open for further replies.

jidan

Member
I have have assembly code for lcd display I want to display letter on lcd (keil compiler )
code is here
Code:
       ORG 0H
MOV A,#38H ;INIT. LCD 2 LINES, 5X7 MATRIX
ACALL COMNWRT ;call command subroutine
ACALL DELAY ;give LCD some time
MOV A,#0EH ;display on, cursor on
ACALL COMNWRT ;call command subroutine
ACALL DELAY ;give LCD some time
MOV A,#01 ;clear LCD
ACALL COMNWRT ;call command subroutine
ACALL DELAY ;give LCD some time
MOV A,#06H ;shift cursor right
ACALL COMNWRT ;call command subroutine
ACALL DELAY ;give LCD some time
MOV A,#84H ;cursor at line 1, pos. 4
ACALL COMNWRT ;call command subroutine
ACALL DELAY ;give LCD some time
MOV A,#’J’ ;display letter J
ACALL DATAWRT ;call display subroutine
ACALL DELAY ;give LCD some time
MOV A,#’D’ ;display letter D
ACALL DATAWRT ;call display subroutine
AGAIN: SJMP AGAIN ;stay here
COMNWRT: ;send command to LCD
MOV P1,A ;copy reg A to port 1
CLR P2.0 ;RS=0 for command
CLR P2.1 ;R/W=0 for write
SETB P2.2 ;E=1 for high pulse
ACALL DELAY ;give LCD some time
CLR P2.2 ;E=0 for H-to-L pulse
RET
DATAWRT: ;write data to LCD
MOV P1,A ;copy reg A to port 1
SETB P2.0 ;RS=1 for data
CLR P2.1 ;R/W=0 for write
SETB P2.2 ;E=1 for high pulse
ACALL DELAY ;give LCD some time
CLR P2.2 ;E=0 for H-to-L pulse
RET
DELAY: MOV R3,#50 ;50 or higher for fast CPUs
HERE2: MOV R4,#255 ;R4 = 255
HERE: DJNZ R4,HERE ;stay until R4 becomes 0
DJNZ R3,HERE2
RET
END

but I am getting this error

lcd.asm(17): error A9: SYNTAX ERROR

lcd.asm(17): error A9: SYNTAX ERROR

lcd.asm(20): error A9: SYNTAX ERROR

lcd.asm(20): error A9: SYNTAX ERROR

lcd.asm(20): error A9: SYNTAX ERROR

lcd.asm - 6 Error(s), 0 Warning(s).

anyone tell me how to remove this error?
 
Looks like the assembler doesn't like the MOV A,'J' Statement!

Very strange because ASEM51 does support it..

I have thrown this into ASEM51 and it compiles

Code:
     ORG 0H
MOV A,#38H ;INIT. LCD 2 LINES, 5X7 MATRIX
ACALL COMNWRT ;call command subroutine
ACALL DELAY ;give LCD some time
MOV A,#0EH ;display on, cursor on
ACALL COMNWRT ;call command subroutine
ACALL DELAY ;give LCD some time
MOV A,#01 ;clear LCD
ACALL COMNWRT ;call command subroutine
ACALL DELAY ;give LCD some time
MOV A,#06H ;shift cursor right
ACALL COMNWRT ;call command subroutine
ACALL DELAY ;give LCD some time
MOV A,#84H ;cursor at line 1, pos. 4
ACALL COMNWRT ;call command subroutine
ACALL DELAY ;give LCD some time
MOV A,#'J' ;display letter J
ACALL DATAWRT ;call display subroutine
ACALL DELAY ;give LCD some time
MOV A,#'D' ;display letter D
ACALL DATAWRT ;call display subroutine
AGAIN: SJMP AGAIN ;stay here
COMNWRT: ;send command to LCD
MOV P1,A ;copy reg A to port 1
CLR P2.0 ;RS=0 for command
CLR P2.1 ;R/W=0 for write
SETB P2.2 ;E=1 for high pulse
ACALL DELAY ;give LCD some time
CLR P2.2 ;E=0 for H-to-L pulse
RET
DATAWRT: ;write data to LCD
MOV P1,A ;copy reg A to port 1
SETB P2.0 ;RS=1 for data
CLR P2.1 ;R/W=0 for write
SETB P2.2 ;E=1 for high pulse
ACALL DELAY ;give LCD some time
CLR P2.2 ;E=0 for H-to-L pulse
RET
DELAY: MOV R3,#50 ;50 or higher for fast CPUs
HERE2: MOV R4,#255 ;R4 = 255
HERE: DJNZ R4,HERE ;stay until R4 becomes 0
DJNZ R3,HERE2
RET
END

Notice my 'D' and your ’D’ !! The inverted commas are different...
 
Looks like the assembler doesn't like the MOV A,'J' Statement!

Very strange because ASEM51 does support it..

I have thrown this into ASEM51 and it compiles

Code:
     ORG 0H
MOV A,#38H ;INIT. LCD 2 LINES, 5X7 MATRIX
ACALL COMNWRT ;call command subroutine
ACALL DELAY ;give LCD some time
MOV A,#0EH ;display on, cursor on
ACALL COMNWRT ;call command subroutine
ACALL DELAY ;give LCD some time
MOV A,#01 ;clear LCD
ACALL COMNWRT ;call command subroutine
ACALL DELAY ;give LCD some time
MOV A,#06H ;shift cursor right
ACALL COMNWRT ;call command subroutine
ACALL DELAY ;give LCD some time
MOV A,#84H ;cursor at line 1, pos. 4
ACALL COMNWRT ;call command subroutine
ACALL DELAY ;give LCD some time
MOV A,#'J' ;display letter J
ACALL DATAWRT ;call display subroutine
ACALL DELAY ;give LCD some time
MOV A,#'D' ;display letter D
ACALL DATAWRT ;call display subroutine
AGAIN: SJMP AGAIN ;stay here
COMNWRT: ;send command to LCD
MOV P1,A ;copy reg A to port 1
CLR P2.0 ;RS=0 for command
CLR P2.1 ;R/W=0 for write
SETB P2.2 ;E=1 for high pulse
ACALL DELAY ;give LCD some time
CLR P2.2 ;E=0 for H-to-L pulse
RET
DATAWRT: ;write data to LCD
MOV P1,A ;copy reg A to port 1
SETB P2.0 ;RS=1 for data
CLR P2.1 ;R/W=0 for write
SETB P2.2 ;E=1 for high pulse
ACALL DELAY ;give LCD some time
CLR P2.2 ;E=0 for H-to-L pulse
RET
DELAY: MOV R3,#50 ;50 or higher for fast CPUs
HERE2: MOV R4,#255 ;R4 = 255
HERE: DJNZ R4,HERE ;stay until R4 becomes 0
DJNZ R3,HERE2
RET
END

Notice my 'D' and your ’D’ !! The inverted commas are different...
I have compiled there is no error but I want to scrolling letter on lcd which command may be use ?

 
There are two ways to scroll on an LCD...

One way is to print onto your screen and shift the screen left or right.
The second is to print a buffer to the screen and scroll the buffer..

The first is the easiest, but you can only scroll n many times.

The second is harder, but gives more flexibility..
 
There are two ways to scroll on an LCD...

One way is to print onto your screen and shift the screen left or right.
The second is to print a buffer to the screen and scroll the buffer..

The first is the easiest, but you can only scroll n many times.

The second is harder, but gives more flexibility..
I tried using this command MOV A,#06H ;shift cursor right but letters are not scrolling continuously
https://www.google.co.in/url?sa=t&r...2r1J30GitVfjw3PKSIYAWow&bvm=bv.62922401,d.bmk
 
I wrote code using this command MOV A,#18H but letters are not scrolling.
Code:
     ORG 0H
MOV A,#38H ;INIT. LCD 2 LINES, 5X7 MATRIX
ACALL COMNWRT ;call command subroutine
ACALL DELAY ;give LCD some time
MOV A,#0EH ;display on, cursor on
ACALL COMNWRT ;call command subroutine
ACALL DELAY ;give LCD some time
MOV A,#01 ;clear LCD
ACALL COMNWRT ;call command subroutine
ACALL DELAY ;give LCD some time
MOV A,#06H ;shift cursor right
ACALL COMNWRT ;call command subroutine
ACALL DELAY ;give LCD some time
MOV A,#84H ;cursor at line 1, pos. 4
ACALL COMNWRT ;call command subroutine
ACALL DELAY
MOV A,#18H
ACALL COMNWRT
ACALL DELAY ;give LCD some time
MOV A,#'J' ;display letter J
ACALL DATAWRT ;call display subroutine
ACALL DELAY ;give LCD some time
MOV A,#'D' ;display letter D
ACALL DATAWRT ;call display subroutine
AGAIN: SJMP AGAIN ;stay here
COMNWRT: ;send command to LCD
MOV P1,A ;copy reg A to port 1
CLR P2.0 ;RS=0 for command
CLR P2.1 ;R/W=0 for write
SETB P2.2 ;E=1 for high pulse
ACALL DELAY ;give LCD some time
CLR P2.2 ;E=0 for H-to-L pulse
RET
DATAWRT: ;write data to LCD
MOV P1,A ;copy reg A to port 1
SETB P2.0 ;RS=1 for data
CLR P2.1 ;R/W=0 for write
SETB P2.2 ;E=1 for high pulse
ACALL DELAY ;give LCD some time
CLR P2.2 ;E=0 for H-to-L pulse
RET
DELAY: MOV R3,#50 ;50 or higher for fast CPUs
HERE2: MOV R4,#255 ;R4 = 255
HERE: DJNZ R4,HERE ;stay until R4 becomes 0
DJNZ R3,HERE2
RET
END
 
Last edited:
Code:
    ORG 0H

    MOV    A,#38H        ;INIT. LCD 2 LINES, 5X7 MATRIX
    ACALL    COMNWRT     ;call command subroutine
    ACALL    DELAY         ;give LCD some time
    MOV    A,#0EH         ;display on, cursor on
    ACALL    COMNWRT     ;call command subroutine
    ACALL    DELAY         ;give LCD some time
    MOV    A,#01         ;clear LCD
    ACALL    COMNWRT     ;call command subroutine
    ACALL    DELAY         ;give LCD some time
    MOV    A,#06H        ;shift cursor right
    ACALL    COMNWRT     ;call command subroutine
    ACALL    DELAY         ;give LCD some time
    MOV    A,#84H         ;cursor at line 1, pos. 4
    ACALL    COMNWRT     ;call command subroutine
    ACALL    DELAY

    MOV    A,#'J'         ;display letter J
    ACALL    DATAWRT     ;call display subroutine
    ACALL    DELAY         ;give LCD some time
    MOV    A,#'D'         ;display letter D
    ACALL    DATAWRT     ;call display subroutine

scroll:
    ACALL    DELAY         ;give LCD some time
    MOV    A,#18H
    ACALL    COMNWRT        ; Scroll left once
    ACALL    DELAY         ;give LCD some time
    MOV    A,#18H
    ACALL    COMNWRT        ; twice
    ACALL    DELAY         ;give LCD some time
    MOV    A,#18H
    ACALL    COMNWRT        ; three times
    ACALL    DELAY         ;give LCD some time
    MOV    A,#18H
    ACALL    COMNWRT        ; last
    ACALL    DELAY         ;give LCD some time

AGAIN:    SJMP    AGAIN         ;stay here

Paste this in and it will explan
 
Code:
    ORG 0H

    MOV    A,#38H        ;INIT. LCD 2 LINES, 5X7 MATRIX
    ACALL    COMNWRT     ;call command subroutine
    ACALL    DELAY         ;give LCD some time
    MOV    A,#0EH         ;display on, cursor on
    ACALL    COMNWRT     ;call command subroutine
    ACALL    DELAY         ;give LCD some time
    MOV    A,#01         ;clear LCD
    ACALL    COMNWRT     ;call command subroutine
    ACALL    DELAY         ;give LCD some time
    MOV    A,#06H        ;shift cursor right
    ACALL    COMNWRT     ;call command subroutine
    ACALL    DELAY         ;give LCD some time
    MOV    A,#84H         ;cursor at line 1, pos. 4
    ACALL    COMNWRT     ;call command subroutine
    ACALL    DELAY

    MOV    A,#'J'         ;display letter J
    ACALL    DATAWRT     ;call display subroutine
    ACALL    DELAY         ;give LCD some time
    MOV    A,#'D'         ;display letter D
    ACALL    DATAWRT     ;call display subroutine

scroll:
    ACALL    DELAY         ;give LCD some time
    MOV    A,#18H
    ACALL    COMNWRT        ; Scroll left once
    ACALL    DELAY         ;give LCD some time
    MOV    A,#18H
    ACALL    COMNWRT        ; twice
    ACALL    DELAY         ;give LCD some time
    MOV    A,#18H
    ACALL    COMNWRT        ; three times
    ACALL    DELAY         ;give LCD some time
    MOV    A,#18H
    ACALL    COMNWRT        ; last
    ACALL    DELAY         ;give LCD some time

AGAIN:    SJMP    AGAIN         ;stay here

Paste this in and it will explan
I have paste this but I am getting this error lcd.asm - 22 Error(s), 1 Warning(s).

lcd.asm(6): error A45: UNDEFINED SYMBOL (PASS-2)

lcd.asm(7): error A45: UNDEFINED SYMBOL (PASS-2)

lcd.asm(9): error A45: UNDEFINED SYMBOL (PASS-2)

lcd.asm(10): error A45: UNDEFINED SYMBOL (PASS-2)

lcd.asm(12): error A45: UNDEFINED SYMBOL (PASS-2)

lcd.asm(13): error A45: UNDEFINED SYMBOL (PASS-2)

lcd.asm(15): error A45: UNDEFINED SYMBOL (PASS-2)

lcd.asm(16): error A45: UNDEFINED SYMBOL (PASS-2)

lcd.asm(18): error A45: UNDEFINED SYMBOL (PASS-2)

lcd.asm(19): error A45: UNDEFINED SYMBOL (PASS-2)

lcd.asm(22): error A45: UNDEFINED SYMBOL (PASS-2)

lcd.asm(23): error A45: UNDEFINED SYMBOL (PASS-2)

lcd.asm(25): error A45: UNDEFINED SYMBOL (PASS-2)

lcd.asm(28): error A45: UNDEFINED SYMBOL (PASS-2)

lcd.asm(30): error A45: UNDEFINED SYMBOL (PASS-2)

lcd.asm(31): error A45: UNDEFINED SYMBOL (PASS-2)

lcd.asm(33): error A45: UNDEFINED SYMBOL (PASS-2)

lcd.asm(34): error A45: UNDEFINED SYMBOL (PASS-2)

lcd.asm(36): error A45: UNDEFINED SYMBOL (PASS-2)

lcd.asm(37): error A45: UNDEFINED SYMBOL (PASS-2)

lcd.asm(39): error A45: UNDEFINED SYMBOL (PASS-2)

lcd.asm(40): error A45: UNDEFINED SYMBOL (PASS-2)

lcd.asm(42): warning A41: MISSING 'END' STATEMENT

lcd.asm - 22 Error(s), 1 Warning(s).
 
You still need the code underneath the forever loop!!!

Code:
COMNWRT:                    ;send command to LCD
   MOV   P1,A                ;copy reg A to port 1
   CLR    P2.0                 ;RS=0 for command
   CLR    P2.1                 ;R/W=0 for write
   SETB   P2.2                ;E=1 for high pulse
   ACALL DELAY           ;give LCD some time
   CLR    P2.2                 ;E=0 for H-to-L pulse
   RET

DATAWRT:                 ;write data to LCD
   MOV P1,A             ;copy reg A to port 1
   SETB P2.0            ;RS=1 for data
   CLR P2.1              ;R/W=0 for write
   SETB P2.2            ;E=1 for high pulse
   ACALL DELAY     ;give LCD some time
   CLR P2.2               ;E=0 for H-to-L pulse
 RET

DELAY: 
    MOV R3,#50         ;50 or higher for fast CPUs
HERE2: 
    MOV R4,#255 ;R4 = 255
HERE: 
    DJNZ R4,HERE ;stay until R4 becomes 0
    DJNZ R3,HERE2
   RET
EN
 
I wrote this code but it scrolling only two times
Code:
     ORG 0H
MOV A,#38H ;INIT. LCD 2 LINES, 5X7 MATRIX
ACALL COMNWRT ;call command subroutine
ACALL DELAY ;give LCD some time
MOV A,#0EH ;display on, cursor on
ACALL COMNWRT ;call command subroutine
ACALL DELAY ;give LCD some time
MOV A,#01 ;clear LCD
ACALL COMNWRT ;call command subroutine
ACALL DELAY ;give LCD some time
MOV A,#06H ;shift cursor right
ACALL COMNWRT ;call command subroutine
ACALL DELAY ;give LCD some time
MOV A,#84H ;cursor at line 1, pos. 4
ACALL COMNWRT ;call command subroutine
ACALL DELAY ;give LCD some time
MOV A,#'J' ;display letter J
ACALL DATAWRT ;call display subroutine
ACALL DELAY ;give LCD some time
MOV A,#'D' ;display letter D
ACALL DATAWRT ;call display subroutine

COMNWRT: ;send command to LCD
MOV P1,A ;copy reg A to port 1
CLR P2.0 ;RS=0 for command
CLR P2.1 ;R/W=0 for write
SETB P2.2 ;E=1 for high pulse
ACALL DELAY ;give LCD some time
CLR P2.2 ;E=0 for H-to-L pulse
RET
DATAWRT: ;write data to LCD
MOV P1,A ;copy reg A to port 1
SETB P2.0 ;RS=1 for data
CLR P2.1 ;R/W=0 for write
SETB P2.2 ;E=1 for high pulse
ACALL DELAY ;give LCD some time
CLR P2.2 ;E=0 for H-to-L pulse
RET
DELAY: MOV R3,#50 ;50 or higher for fast CPUs
HERE2: MOV R4,#255 ;R4 = 255
HERE: DJNZ R4,HERE ;stay until R4 becomes 0
DJNZ R3,HERE2
RET
scroll:
    ACALL    DELAY         ;give LCD some time
    MOV    A,#18H
    ACALL    COMNWRT        ; Scroll left once
    ACALL    DELAY         ;give LCD some time
    MOV    A,#18H
    ACALL    COMNWRT        ; twice
    ACALL    DELAY         ;give LCD some time
    MOV    A,#18H
    ACALL    COMNWRT        ; three times
    ACALL    DELAY         ;give LCD some time
    MOV    A,#18H
    ACALL    COMNWRT        ; last
    ACALL    DELAY         ;give LCD some time

AGAIN:    SJMP    AGAIN         ;stay here
END

I want to scrolling continuously
 
I wrote this code but it scrolling only two times
Code:
     ORG 0H
MOV A,#38H ;INIT. LCD 2 LINES, 5X7 MATRIX
ACALL COMNWRT ;call command subroutine
ACALL DELAY ;give LCD some time
MOV A,#0EH ;display on, cursor on
ACALL COMNWRT ;call command subroutine
ACALL DELAY ;give LCD some time
MOV A,#01 ;clear LCD
ACALL COMNWRT ;call command subroutine
ACALL DELAY ;give LCD some time
MOV A,#06H ;shift cursor right
ACALL COMNWRT ;call command subroutine
ACALL DELAY ;give LCD some time
MOV A,#84H ;cursor at line 1, pos. 4
ACALL COMNWRT ;call command subroutine
ACALL DELAY ;give LCD some time
MOV A,#'J' ;display letter J
ACALL DATAWRT ;call display subroutine
ACALL DELAY ;give LCD some time
MOV A,#'D' ;display letter D
ACALL DATAWRT ;call display subroutine

COMNWRT: ;send command to LCD
MOV P1,A ;copy reg A to port 1
CLR P2.0 ;RS=0 for command
CLR P2.1 ;R/W=0 for write
SETB P2.2 ;E=1 for high pulse
ACALL DELAY ;give LCD some time
CLR P2.2 ;E=0 for H-to-L pulse
RET
DATAWRT: ;write data to LCD
MOV P1,A ;copy reg A to port 1
SETB P2.0 ;RS=1 for data
CLR P2.1 ;R/W=0 for write
SETB P2.2 ;E=1 for high pulse
ACALL DELAY ;give LCD some time
CLR P2.2 ;E=0 for H-to-L pulse
RET
DELAY: MOV R3,#50 ;50 or higher for fast CPUs
HERE2: MOV R4,#255 ;R4 = 255
HERE: DJNZ R4,HERE ;stay until R4 becomes 0
DJNZ R3,HERE2
RET
scroll:
    ACALL    DELAY         ;give LCD some time
    MOV    A,#18H
    ACALL    COMNWRT        ; Scroll left once
    ACALL    DELAY         ;give LCD some time
    MOV    A,#18H
    ACALL    COMNWRT        ; twice
    ACALL    DELAY         ;give LCD some time
    MOV    A,#18H
    ACALL    COMNWRT        ; three times
    ACALL    DELAY         ;give LCD some time
    MOV    A,#18H
    ACALL    COMNWRT        ; last
    ACALL    DELAY         ;give LCD some time

AGAIN:    SJMP    AGAIN         ;stay here
END

I want to scrolling continuously. sorry for double posting how to delete this post?
 
Then you need the software scrolling.... You create a buffer, fill it with a message, display the first 16 characters, rotate the buffer, display the first 16 characters..etc....

Hardware scrolling on a small LCD like that needs some work. The display will scroll once per command, so you'll need to use the unseen portion.
The 16x2 LCD has room for 64 characters before it spills to the next line... I don't know how many times it scrolls though...

Using an external buffer gives more flexibility..... If you write a routine to display a string and display a portion of the string at a time, this gives the appearance of scrolling....
 
I want to display letters on lcd that scrolling continuously you said forever loop I made code that scrolling only two time how to use forever loop in this code
 
How many letters? If you want the same message scrolling all the time you need to place the string onto the screen in the forever loop...

Pseudo code...
loop
Place the string onto the screen
adjust string to be one letter shifted left
take the dropped letter and place it at the end of the string
return and do it again...
 
A bit choppy but you'll get the idea
You can see the use of POP and PUSH to save values from being destroyed..
Code:
AGAIN:
    MOV    R1,#32        ;String lasts 32 characters
    MOV    A,#0h        ;Keep count
SCROLL:
    ACALL    DATAHOME
    ACALL    PRINT        ;Print Buffer
    INC    A
    DJNZ    R1,SCROLL
    SJMP    AGAIN         ;Forever loop

PRINT:
    PUSH    Acc        ;Save A as its used in previous loop
    MOV     DPTR,#STRING    ;Point DPTR to string
    MOV    R2,#16        ;16 characters

LOOP:    POP    Acc
    PUSH    Acc
    MOVC    A,@A+DPTR    ;Add offset
    ACALL    DATAWRT        ;send to screen

    INC    DPTR
    DJNZ    R2,LOOP        ;Done?
    POP    Acc        ;restore A
    RET

STRING:
    db    "               HELLO BIG WORLD!               "
     
DATAHOME:
    PUSH    Acc
    MOV    A, #080H    ;Home
    ACALL    COMNWRT   
    POP    Acc
    RET
 
A bit choppy but you'll get the idea
You can see the use of POP and PUSH to save values from being destroyed..
Code:
AGAIN:
    MOV    R1,#32        ;String lasts 32 characters
    MOV    A,#0h        ;Keep count
SCROLL:
    ACALL    DATAHOME
    ACALL    PRINT        ;Print Buffer
    INC    A
    DJNZ    R1,SCROLL
    SJMP    AGAIN         ;Forever loop

PRINT:
    PUSH    Acc        ;Save A as its used in previous loop
    MOV     DPTR,#STRING    ;Point DPTR to string
    MOV    R2,#16        ;16 characters

LOOP:    POP    Acc
    PUSH    Acc
    MOVC    A,@A+DPTR    ;Add offset
    ACALL    DATAWRT        ;send to screen

    INC    DPTR
    DJNZ    R2,LOOP        ;Done?
    POP    Acc        ;restore A
    RET

STRING:
    db    "               HELLO BIG WORLD!               "
    
DATAHOME:
    PUSH    Acc
    MOV    A, #080H    ;Home
    ACALL    COMNWRT  
    POP    Acc
    RET
I tried but my message is not scrolling all time its scrolling only two time I don't know what is problem in code?
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top