Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
01/10/07 02:00
Read: times


 
#130547 - Asm code
Responding to: ???'s previous message
Why does the assembler code have to be specific for the 2051/4051? Most people interface LCDs through the ports pins, so example code for any of the other 8051 variants are probably just as applicable. I would suggest you learn to read 'c' - its easier to read than assembler! Besides, you should be looking at the method rather than the actual code.
;----------------------------------------------------------------------------
;
;
;  print messages on the lcd display.
;  Dptr-> message in rom terminated by 00h
;
;
;----------------------------------------------------------------------------
pstring
        clr     a
        movc    a,@a+dptr
        jz      lcdp_2
        lcall   lcd_data_wr
        inc     dptr
        sjmp    pstring
lcdp_2
        ret
;----------------------------------------------------------------------------
;
;
;  Print hex value in A to the lcd display
;
;
;----------------------------------------------------------------------------
phex
        push    a
        swap    a
        lcall   hex
        pop     a
hex
        anl     a,#0fh
        add     a,#30h
        cjne    a,#3ah,hex_1
hex_1
        jc      hex_2
        add     a,#7
hex_2
        lcall   lcd_data_wr
        ret
;----------------------------------------------------------------------------
;
;
;  Print packed bcd value in A to the lcd display
;
;
;----------------------------------------------------------------------------
pbcd    push    a
        swap    a
        anl     a,#0fh
        add     a,#'0'
        lcall   lcd_data_wr
        pop     a
        anl     a,#0fh
        add     a,#'0'
        ljmp    lcd_data_wr
;----------------------------------------------------------------------------
;
;
;  initialise the lcd display
;
;
;----------------------------------------------------------------------------
lcd_init
        mov     LCD_PORT,#0C0h
;
;  delay 150mS
;
        mov     a,#150
        lcall   delay_1ms
        mov     a,#3
        mov     LCD_PORT,#0C3h
        nop
        nop
        setb    LCD_DEN
        nop
        nop
        clr     LCD_DEN
;
;  delay 50mS
;
        mov     a,#50
        lcall   delay_1ms

        mov     LCD_PORT,#0C3h
        nop
        nop
        setb    LCD_DEN
        nop
        nop
        clr     LCD_DEN
;
;  delay 50mS
;
        mov     a,#50
        lcall   delay_1ms

        mov     LCD_PORT,#0C3h
        nop
        nop
        setb    LCD_DEN
        nop
        nop
        clr     LCD_DEN
;
;  delay 10mS
;
        mov     a,#10
        lcall   delay_1ms
        mov     LCD_PORT,#0C2h
        nop
        nop
        setb    LCD_DEN
        nop
        nop
        clr     LCD_DEN
;
;  delay 10mS
;
        mov     a,#10    ; 10 * 100uS =1mS
        lcall   delay_1ms
        mov     a,#2ch    ; 2 line mode
        lcall   lcd_comm_wr  ; write lcd command
;
;  delay 1mS
;
        mov     a,#100    ; 10 * 100uS =1mS
        lcall   delay_100u
        mov     a,#0ch    ; display on,cursor off
        lcall   lcd_comm_wr  ; write lcd command
;
;  delay 1mS
;
        mov     a,#10    ; 10 * 100uS =1mS
        lcall   delay_100u
        mov     a,#06h    ; auto inc,shift right
        lcall   lcd_comm_wr  ; write lcd command
        mov     a,#01h
        lcall   lcd_comm_wr  ; clear the display
;
;  delay 10mS
;
        mov     a,#1
        lcall   delay_1ms
        ret
;----------------------------------------------------------------------------
;
;  Locate the lcd cursor. lcd_comm_wr routine must follow below!
;  Cursor position in A
;  zaps: A,B
;
;
;----------------------------------------------------------------------------
locate_cursor
        cjne    a,#16,lc_1
lc_1
        jc      lc_2            ; if location < 16 (line #1)
        add     a,#30h          ; else add offset for 2nd line
lc_2
        setb    a.7             ; set bit 7 for locate cursor cmd
;----------------------------------------------------------------------------
;
;
;  send a command to the lcd display. command in A
;  Zaps: A,B
;
;----------------------------------------------------------------------------
lcd_comm_wr
        clr     LCD_RS
        mov     b,a             ;save the command
        swap    a               ;get hi nibble into low nibble
        anl     a,#0fh
        mov     c,a.0
        mov     P0.0,c
        mov     c,a.1
        mov     P0.1,c
        mov     c,a.2
        mov     P0.2,c
        mov     c,a.3
        mov     P0.3,c
        nop
        nop
        setb    LCD_DEN
        nop
        nop
        clr     LCD_DEN
        mov     a,b
        anl     a,#0fh
        mov     c,a.0
        mov     P0.0,c
        mov     c,a.1
        mov     P0.1,c
        mov     c,a.2
        mov     P0.2,c
        mov     c,a.3
        mov     P0.3,c
        nop
        nop
        setb    LCD_DEN
        nop
        nop
        clr     LCD_DEN
;
;  delay for lcd controller
;
        mov     b,#25      ;at least 40uS
ldrw_1
        djnz    b,ldrw_1    ;waste some time
        ret
;******************************************************************************
;
;
;  send data to the lcd display. command in A
;  zaps: A,B
;
;
;******************************************************************************
lcd_data_wr
        mov     b,a      ;save the command
        swap    a      ;get hi nibble into low nibble
        anl     a,#0fh
        mov     c,a.0
        mov     P0.0,c
        mov     c,a.1
        mov     P0.1,c
        mov     c,a.2
        mov     P0.2,c
        mov     c,a.3
        mov     P0.3,c
        setb    LCD_RS
        nop
        nop
        setb    LCD_DEN
        nop
        nop
        clr     LCD_DEN
        mov     a,b
        anl     a,#0fh
        mov     c,a.0
        mov     P0.0,c
        mov     c,a.1
        mov     P0.1,c
        mov     c,a.2
        mov     P0.2,c
        mov     c,a.3
        mov     P0.3,c
        setb    LCD_RS
        nop
        nop
        setb    LCD_DEN
        nop
        nop
        clr     LCD_DEN
;
;  delay for lcd controller
;
        mov     b,#25      ;at least 40uS
ldrw_2
        djnz    b,ldrw_2    ;waste some time
        ret
;----------------------------------------------------------------------------
;
;
;  Delay routine. A has # of 100 microseconds to delay
;  zaps: A,B
;
;
;----------------------------------------------------------------------------
delay_100u
        mov     b,#54      ;@12.xxx mhz approx!
dly_1
        djnz    b,dly_1
        djnz    a,delay_100u
        ret
;----------------------------------------------------------------------------
;
;
;  Delay routine. A has # of 1 milliseconds to delay
;  zaps: A,B
;
;
;----------------------------------------------------------------------------
delay_1ms
        mov     b,#120      ;@12.xxx mhz approx!
dly_2
        nop
        nop
        nop
        nop
        nop
        nop
        djnz    b,dly_2
        djnz    a,delay_1ms
        ret



The lcd was connected to port0 in this instance
lcd d4..7 to P0.0..3
lcd EN to P0.5
lcd RS to P0.4
lcd R/W to 0v

This uses 4 bit mode - with is advisable due to the number of available port pins on a 2051/4051

Any questions :- refer to the hitachi hd44780 datasheet first.



List of 44 messages in thread
TopicAuthorDate
How to create wr rd for E strobe on LCD            01/01/70 00:00      
   No research!            01/01/70 00:00      
      Wrong plenty of research            01/01/70 00:00      
         clock speed?            01/01/70 00:00      
            Erik it is 12 clocker            01/01/70 00:00      
               the question is moot ...            01/01/70 00:00      
         Wrong!            01/01/70 00:00      
            My error            01/01/70 00:00      
               Asm code            01/01/70 00:00      
                  missing boldface            01/01/70 00:00      
                  4051 has no port 0            01/01/70 00:00      
                     Tell me something I don't know!            01/01/70 00:00      
   when posting a schematic PLEASE do not do it in a            01/01/70 00:00      
      This why Erik            01/01/70 00:00      
         upset?            01/01/70 00:00      
            Your 1 True Love            01/01/70 00:00      
               I don't what happen but see below            01/01/70 00:00      
   AT89C4051 hardware            01/01/70 00:00      
      A better schematic post            01/01/70 00:00      
         Understanding the schematic will help.            01/01/70 00:00      
            Thanks for the your reply            01/01/70 00:00      
               Which ports you use doesn't matter ...            01/01/70 00:00      
   LCD interface            01/01/70 00:00      
      Thanks for the comment            01/01/70 00:00      
         Cant post code?            01/01/70 00:00      
      Yikes, that interface is old-skool !            01/01/70 00:00      
         yikes, your attitude sucks            01/01/70 00:00      
         You don't like my idea            01/01/70 00:00      
            It is here!            01/01/70 00:00      
               don't quite understand            01/01/70 00:00      
                  I can            01/01/70 00:00      
                     commodore 64            01/01/70 00:00      
   STOP - THINK - START OVER            01/01/70 00:00      
      Thanks for your comments            01/01/70 00:00      
         You must know what is required            01/01/70 00:00      
            an addition            01/01/70 00:00      
               shortcut            01/01/70 00:00      
                  in response to Andy, there is now one worse            01/01/70 00:00      
                     That's why these queries continue to appear HERE!            01/01/70 00:00      
                     Mapquest            01/01/70 00:00      
   Nice Thread. Lots of passion.            01/01/70 00:00      
      This was a popular PIC demo about 15 years ago            01/01/70 00:00      
         We're dating ourselves a bit arent we?            01/01/70 00:00      
            Well ... Yes ... maybe ... those were the days ...            01/01/70 00:00      

Back to Subject List