1. 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.
    Dismiss Notice

assembly code for lcd display

Discussion in '8051/8951' started by jidan, Mar 14, 2014.

  1. jidan

    jidan Member

    Joined:
    Oct 8, 2013
    Messages:
    67
    Likes:
    1
    I have have assembly code for lcd display I want to display letter on lcd (keil compiler )
    code is here
    Code (text):
           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?
     
  2. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,165
    Likes:
    910
    Location:
    Rochdale UK
    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 (asm):

         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...
     
    • Thanks Thanks x 1
  3. jidan

    jidan Member

    Joined:
    Oct 8, 2013
    Messages:
    67
    Likes:
    1
    I have compiled there is no error but I want to scrolling letter on lcd which command may be use ?

     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,165
    Likes:
    910
    Location:
    Rochdale UK

    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..
     
  6. jidan

    jidan Member

    Joined:
    Oct 8, 2013
    Messages:
    67
    Likes:
    1
    I tried using this command MOV A,#06H ;shift cursor right but letters are not scrolling continuously
     
  7. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,165
    Likes:
    910
    Location:
    Rochdale UK
    That is cursor move direction... The command to shift display right and left is... 0x1C for right and 0x18 for left..
     
  8. jidan

    jidan Member

    Joined:
    Oct 8, 2013
    Messages:
    67
    Likes:
    1
    I wrote code using this command MOV A,#18H but letters are not scrolling.
    Code (text):

         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: Mar 15, 2014
  9. jidan

    jidan Member

    Joined:
    Oct 8, 2013
    Messages:
    67
    Likes:
    1
    can anyone check out code why letters are not scrolling on LCD
     
  10. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,165
    Likes:
    910
    Location:
    Rochdale UK
    Code (asm):

        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
     
  11. jidan

    jidan Member

    Joined:
    Oct 8, 2013
    Messages:
    67
    Likes:
    1
    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).
     
  12. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,165
    Likes:
    910
    Location:
    Rochdale UK
    You still need the code underneath the forever loop!!!

    Code (asm):

    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
     
     
  13. jidan

    jidan Member

    Joined:
    Oct 8, 2013
    Messages:
    67
    Likes:
    1
    I wrote this code but it scrolling only two times
    Code (text):
         
         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
     
  14. jidan

    jidan Member

    Joined:
    Oct 8, 2013
    Messages:
    67
    Likes:
    1
    I wrote this code but it scrolling only two times
    Code (text):
         
         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?
     
  15. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,165
    Likes:
    910
    Location:
    Rochdale UK
    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....
     
  16. jidan

    jidan Member

    Joined:
    Oct 8, 2013
    Messages:
    67
    Likes:
    1
    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
     
  17. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,165
    Likes:
    910
    Location:
    Rochdale UK
    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...
     
  18. jidan

    jidan Member

    Joined:
    Oct 8, 2013
    Messages:
    67
    Likes:
    1
    I want same message scrolling all the time but don't know how to create forever loop?
     
  19. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,165
    Likes:
    910
    Location:
    Rochdale UK
    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 (asm):

    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
     
     
  20. jidan

    jidan Member

    Joined:
    Oct 8, 2013
    Messages:
    67
    Likes:
    1
    I tried but my message is not scrolling all time its scrolling only two time I don't know what is problem in code?
     
  21. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,165
    Likes:
    910
    Location:
    Rochdale UK
    Codes fine... Have you missed anything when you copied the code?
     

Share This Page