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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
09/07/06 04:47
Read: times


 
#123796 - Full assembly Code ... LCD 4 bit
Responding to: ???'s previous message
Hello All,
Below is the code I am using for intializing LCD in 4 bit & sending data to it.

The problems I m facing are ...
1> If I am using the BUSY FLAG then no display.

2> If not using BUSY FLAG then only cursor is blinking and
no data is displayed on the LCD.

There is something wrong in the logic but I am
not able to rectify it.
I have commnetd the BUSY subroutine so that atleast you can get a cursor.

If the code is unreadable or comments are not enough then revert me with probs.

thanks in advance ...

AS



;***************************************************************

; LCD Program with 4-bit Data Bus. The Data Bus is connected to PORT 1 pins 0, 1, 2, 3 and
; the control lines RS, RW & EN are connected to PORT 1 pins 5, 6, 7

;***************************************************************


lcd_rs	bit p1.5
lcd_rw	bit p1.6
lcd_en	bit p1.7

org 000h
ljmp START

;===============================================================
;	Delay Subroutine
;===============================================================
WAIT_15MS:
                  Mov   r0, #15
SUB_WAIT15MS:
                  Acall WAIT_1MS
                  djnz  r0, SUB_WAIT15MS
                  ret

WAIT_5MS:
                  Mov   r0, #5
SUB_WAIT5MS:
                  acall WAIT_1MS
                  djnz  r0, SUB_WAIT5MS
                  ret

WAIT_1MS:
                  mov   r1, #250
SUB_LOOP:
                  nop
                  nop
                  djnz  r1, SUB_LOOP
                  ret

WAIT_40US:
                  mov   r0, #40
                  djnz  r0, $
                  ret

WAIT_100US:
                  mov   r0, #100
                  djnz  r0, $
                  ret


;===============================================================
;	LCD Busy Flag Status
;===============================================================

BUSY_STATUS:
                  setb  lcd_en
                  orl   p1, #0fh ; make the lower nibbles of PORT 1 as
                                 ; input port 
                  clr   lcd_en
                  setb  lcd_rw   ; set this bit for reading from LCD
                  mov   a, p1    ; move the LCD value to ACC
                  setb  lcd_en
                  clr   lcd_en
                  anl   a, #0fh  ; make the higher nibble of ACC
                                 ; high coz the LCD is sending the 
                                 ; higher nibble of the DATA 
                  swap  a        ; The higher nibble recieved from
                                 ; LCD is in lower nibble of ACC 
                                 ; so swap ACC 
                  mov   r6, a    ; save this value of ACC to R6
                  mov   a, p1    ; again read from port 1 this time
                                 ; remianing lower nibble of the 
                                 ; data os sent to ACC
                  setb  lcd_en
                  clr   lcd_en
                  anl   a, #0fh ; again make the higher nibble of ACC low
                  orl   a, r6   ; aplly the logical OR gate to previous
                                ; and present value of ACC
                  ret

BUSY:
                  anl   a, #01h
                  acall	BUSY_STATUS
                  jb    acc.7, BUSY
                  clr   lcd_rw
                  ret

;==============================================================
; LCD command and Data Sending Subroutine ...
;==============================================================
SEND_2_NIBBLES:
                  push   acc
                  swap   a ; swap ACC coz we have to send the higher nibbles first
                  jb     lcd_rs, DATA1 ; if called from WRITE_DATA, lcd_rs will be set
                  anl    a, #00001111b ; if called from WRITE_COMMAND, lcd_rs is not set.
                                       ; Make higher nibbles to low coz 
                                       ; DATA bus is connected to lower nibbles.
                  sjmp   ACTION1
DATA1:
                  anl    a, #2fh ; keep lcd_rs as set bit for text data sending
ACTION1:
                  mov    p1, a ; move the higher nibbles of data & command 
                               ; to PORT 1 lower nibbles ie DATA BUS
                  setb   lcd_en
                  clr    lcd_en

                  pop    acc ; pop the original value of ACC
                  jb     lcd_rs, DATA2 ; again check for lcd_rs status
                                       ; for differentiating data from command
                  anl    a, #00001111b
                  sjmp   ACTION2
DATA2:
                  anl    a, #2fh
ACTION2:
                  mov    p1, a ; now move the lower nibble of ACC to lower DATA bus .
                  setb   lcd_en
                  clr    lcd_en
                  acall  WAIT_40US
                  ret


;===============================================================
;	LCD Command Sending Subroutine
;===============================================================

WRITE_COMMAND:
                  mov    r3, a
                  ;acall  BUSY
                  mov    a, r3
                  acall  SEND_2_NIBBLES
                  ret



;===============================================================
;	LCD Data Sending Subroutine
;===============================================================

WRITE_DATA:
                  mov   r3, a
                  ;acall BUSY
                  mov   a, r3
                  setb  lcd_rs
                  acall SEND_2_NIBBLES
                  clr   lcd_rs
                  ret


DOIT:
                  anl   a, #00001111b ; make the higher nibbles LOW
                  mov   p1, a ; move the value of ACC to PORT 1 ie DATA BUS
                  setb  lcd_en
                  clr   lcd_en
                  ret

;===============================================================
; LCD Intialization Subroutine
;===============================================================

INIT_LCD:
                  mov	a, #03h 
                  acall	DOIT

                  acall	WAIT_5MS

                  mov	a, #03h
                  acall	DOIT

                  acall	WAIT_100US

                  mov	a, #03h
                  acall	DOIT

                  acall	WAIT_5MS

                  mov	a, #02h ; Initialzing LCD in 4-bit MODE
                  acall	DOIT

                  acall	WAIT_40US

                  mov	a, #28h
                  acall	WRITE_COMMAND
                  
                  mov	a, #08h
                  acall	WRITE_COMMAND

                  mov	a, #0eh
                  acall	WRITE_COMMAND

                  mov	a, #06h
                  acall	WRITE_COMMAND

                  ;mov	a, #80h
                  ;acall	WRITE_COMMAND


                  ret

;===============================================================
;        Main Program Starts from here
;===============================================================

START:
                  acall   WAIT_15MS ; wait for 15 MS

                  acall   INIT_LCD ; Inititalize the LCD
                  mov     dptr,#DATABASE

REPEAT:
                  clr     a
                  movc    a,@a+dptr
                  jz      COOL
                  acall   WRITE_DATA
                  inc     dptr
                  sjmp    REPEAT
COOL:
                  sjmp    COOL

DATABASE: db 'INDIA is gr8',00h





;***************************************************************

end






List of 52 messages in thread
TopicAuthorDate
4-bit LCD ... single PORT            01/01/70 00:00      
   there's a datasheet            01/01/70 00:00      
      LCD datasheets ...            01/01/70 00:00      
         the Hitachi Datasheet for HD44780 is not like that            01/01/70 00:00      
         VFDs: Lucky b*stard            01/01/70 00:00      
   4-bit LCD            01/01/70 00:00      
      There are examples on 8052.COM if you search            01/01/70 00:00      
         And you don't need R/W*            01/01/70 00:00      
            but be aware! You discard several functions.            01/01/70 00:00      
               on saving pins            01/01/70 00:00      
                  wait a minute ...            01/01/70 00:00      
                     Richard, please            01/01/70 00:00      
                        Why should he change direction?            01/01/70 00:00      
                           no such impilcation            01/01/70 00:00      
                              well, the logic is simple ...            01/01/70 00:00      
                                 OK, as always            01/01/70 00:00      
                  Richard, quit bickering            01/01/70 00:00      
                     it goes to an OLD issue            01/01/70 00:00      
                        as I see it is that this is GREAT.            01/01/70 00:00      
                  On saving pins            01/01/70 00:00      
                  read the forum messages, don't glance            01/01/70 00:00      
   Here is my example            01/01/70 00:00      
      why do you persist in 'advertising' this CRAP            01/01/70 00:00      
         Attack, Attack, Attack.            01/01/70 00:00      
            get your facts straight            01/01/70 00:00      
               Did you understand real life ?            01/01/70 00:00      
                  yes, I do            01/01/70 00:00      
   Answer            01/01/70 00:00      
      Jon, great answer            01/01/70 00:00      
         Yes, indeed, ... BUT ...            01/01/70 00:00      
            How do you know...            01/01/70 00:00      
               It's possible that things worked that way            01/01/70 00:00      
   Better late than never            01/01/70 00:00      
      \"It works\"            01/01/70 00:00      
         Yes, it does            01/01/70 00:00      
            does that mean they're all alike?            01/01/70 00:00      
               Yes, if all guys would read the datasheets...            01/01/70 00:00      
                  Hitachi JHD 162a            01/01/70 00:00      
                     Point missed            01/01/70 00:00      
                     That's not relevant!            01/01/70 00:00      
                        Advice appriciated            01/01/70 00:00      
                           where are you going to find that?            01/01/70 00:00      
      well, you just posted your own 'comment'            01/01/70 00:00      
   Simple Guidance            01/01/70 00:00      
      One LCD, One Port            01/01/70 00:00      
      horsefeathers, male cow manure            01/01/70 00:00      
   GOD!!!            01/01/70 00:00      
      try a shadow register            01/01/70 00:00      
   Full assembly Code ... LCD 4 bit            01/01/70 00:00      
      On first reading...            01/01/70 00:00      
      probs in 2 SUBROUTINES ...            01/01/70 00:00      
   Many ways to skin a cat            01/01/70 00:00      

Back to Subject List