| ??? 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
|



