Discussion in "Project Help" started by    nnemdi    Dec 14, 2007.
Fri Dec 14 2007, 11:58 pm
#1
hi,

i have a correct code to interface keypad but i am havig difficulty in interfacing it to the lcd display....
please can someone help me with the code....to display data from a 16x2 8 bit lcd display..
Attachment
Sat Dec 15 2007, 12:38 am
#2
please visit the LCD tutorial.. it will explain you everything you need to know when interfacing an LCD if you find any problem post here..
link: www.8051projects.net/lcd-interfacing/
Wed Jan 02 2008, 06:36 pm
#3
i am still having problems with programming the lcd..i am using the keil mcb900 board with uvison3 software...and the lcd is not recieving any data..the lcd am using powertip pc1602lrsd....please i need your help
thanks
Thu Jan 03 2008, 01:54 am
#4
may i see your LCD program..?
i hope you have already gone through the LCD tutorial..
please also provide a link to LCD datasheet if possible.
Thu Jan 03 2008, 03:27 am
#5
here is my code...
i have been working on it all day and the code does not have any effect on the lcd...i am using the keil mcb900 with uvision3..
see code below

Attachment
Thu Jan 03 2008, 03:43 am
#6
there is problem in checking for busy flag..
you are giving the enable pulse only once..
you have to give it every time you read the busy flag..

I am going to correct your code for command_byte.. for other you can do yourself..

;**********************************************************
; Feed Command/Data to the LCD module
;***********************************************************
command_byte:
clr p2.0 ; RS low for a command byte.
jmp bdelay
data_byte:
setb p2.0 ; RS high for a data byte.
nop
bdelay:
clr p2.1 ; R/w low for a write mode
clr p2.2
nop
setb p2.2 ;enable pulse
nop
;******************* Check Busy Flag
mov p1,#0ffh ;configure port1 to input mode
setb p2.1 ;set RW to read
clr p2.0 ;set RS to command
bloop:clr p2.2 ;generate enable pulse
nop
setb p2.2
nop
mov a,p1
anl a,#80h ;check bit#7 busy flag
cjne a,#00h,bloop;keep waiting until busy flag clears
Thu Jan 03 2008, 08:09 am
#7
the code still does not do anything..i can't understand why my code is not working,,,please can you check it again..
thanks
Thu Jan 03 2008, 08:19 am
#8
here is my new code below am i correct..because the lcd does not do anything..please your help will be aprreciated..thank you
;**********************************************************
;; Application Note:
; =================
; Displaying Characters on an LCD Character Module
;
; Description: Demo software to display “canned”
;message and custom characters.
; Controller: Phillips 87C751
; LCD controller: HD44780, KS0066, SED1278
;
;*************************************************************
; Constant Definition
;*************************************************************

;*****************************************
; Port Connections
; =================
; P1.0 ->
 D0
; P1.1 ->
 D1
; P1.2 ->
 D2
; . . .
; P1.7 ->
 D7
; P2.2 ->
 Enable
; P2.0 ->
 RS
; P2.1 ->
 RW
;*******************************************************
; Interrupt Vectors
; ------------------
org 000h
jmp PowerUp ; Power up reset vector

PowerUp:
;**************************************
; LCD Initialization Routine
;**************************************
cinit: clr P3.1 ;RS low
clr P2.1 ;RW low
setb P2.2 ;Enable
mov p1,#38h
acall command_byte
acall ddelay ;initial delay 4.1mSec
mov p1,#38h ;function set
acall command_byte
acall ddelay ;busy flag not avail. yet
mov p1,#38h ;function set
acall command_byte
mov p1,#0ch ;display on
acall command_byte
mov p1,#01h ;clear display
acall command_byte
acall cgram ;define custom fonts
acall first_line ;display first line
acall second_line ;display second line
sdone:
jmp sdone
;********************************************************
;Subroutine: WRITE
;=================
;Purpose: To feed in data/command bytes to the LCD module
;Parameters:dptr = should be set to the beginning of
; the data byte address
; Data bytes should be finished with 99H
;Alg: get a new data/command byte
; while (new data != 99h) {
; set port1 with new data
; call data_byte
; increment data pointer
; }
; return
;********************************************************
write:
write_loop:
mov a,#0
movc a,@a+dptr
cjne a,#99h,write_cont
ret
write_cont:
mov p1,a
acall data_byte
inc dptr
jmp write_loop
;************************************************
; Delay Routine:
; Delay periond = Ims
;************************************************
ddelay:
         PUSH        ACC
         MOV         A,#0A6H
MD_OLP:
         INC         A
         NOP
         NOP
         NOP
         NOP
         NOP
         NOP
         NOP
         NOP
         JNZ         MD_OLP
         NOP
         POP         ACC
         RET
MADELAY:
         PUSH        ACC
         MOV         A,#036H
MAD_OLP:
         INC         A
         NOP
         NOP
         NOP
         NOP
         NOP
         NOP
         NOP
         NOP
         JNZ         MAD_OLP
         NOP
         POP         ACC
ret
;********************************
; set address to beginning
; of CG RAM
;********************************
cgram:
mov p1,#40h
acall command_byte
mov dptr,#cgram_data
acall write
ret
;********************************
; Set DDRAM to the beginnig of
; the first line - 00
;********************************
first_line:
mov p1,#080h ;set DDRAM
acall command_byte
mov dptr,#fline_data
acall write
ret
;********************************
; Set DDRAM to the beginning of
; the second line - 40
;********************************
second_line:
mov p1,#0c0h ;set DDRAM
acall command_byte
mov dptr,#sline_data
acall write
ret
;**********************************************************
; Feed Command/Data to the LCD module
;***********************************************************
;***********************************************************
command_byte:
clr p2.0 ; RS low for a command byte.
jmp bdelay
data_byte:
setb p2.0 ; RS high for a data byte.
nop
bdelay:
clr p2.1 ; R/w low for a write mode
clr p2.2
nop
setb p2.2 ;enable pulse
nop
;******************* Check Busy Flag
mov p1,#0ffh ;configure port1 to input mode
setb p2.1 ;set RW to read
clr p2.0 ;set RS to command
bloop:
clr p2.2 ;generate enable pulse
nop
setb p2.2
nop
mov a,p1
anl a,#80h ;check bit#7 busy flag
cjne a,#00h,bloop;keep waiting until bu
;*****************************************
; check busy flag twice
;*****************************************
bwait:
clr p2.2 ;generate enable pulse
nop
setb p2.2
nop
mov a,p1
anl a,#80h ;check bit#7 busy flag
cjne a,#00h,bloop;keep waiting until bu
ret
;********************************************
; Data Bytes
;*******************************************
FLINE_DATA:
db '>
>
8051projects<<'
db 099h
SLINE_DATA:
db 00h,01h,02h,03h,04h,05h,06h,07h
db 099h
CGRAM_DATA:
font1: db 0ah,15h,11h,11h,0ah,04h,00h,00h
font2: db 04h,0ah,11h,11h,15h,0ah,00h,00h
font3: db 04h,0eh,15h,04h,04h,04h,04h,00h
font4: db 04h,04h,04h,04h,15h,0eh,04h,00h
font5: db 18h,18h,1fh,1fh,1fh,18h,18h,00h
font6: db 1fh,1fh,03h,03h,03h,1fh,1fh,00h
font7: db 0ah,15h,0ah,15h,0ah,15h,0ah,00h
font8: db 15h,0ah,15h,0ah,15h,0ah,15h,00h
db 99h
end


[ Edited Thu Jan 03 2008, 11:37 am ]
Thu Jan 03 2008, 11:31 am
#9
change the power up sequence like this...
PowerUp:
;**************************************
; LCD Initialization Routine
;**************************************
cinit: clr P3.1 ;RS low
clr P2.1 ;RW low
mov p1,#38h
acall command_byte
acall ddelay ;initial delay 4.1mSec
mov p1,#0Ch ;function set
acall command_byte
mov p1,#06h ;display on
acall command_byte
mov p1,#01h ;clear display
acall command_byte
acall cgram ;define custom fonts
acall first_line ;display first line
acall second_line ;display second line
sdone:
jmp sdone


You also need to rewrite the command_byte routine..

;**********************************************************
; Feed Command/Data to the LCD module
;***********************************************************
;***********************************************************
command_byte:
clr p2.0 ; RS low for a command byte.
jmp bdelay
data_byte:
setb p2.0 ; RS high for a data byte.
nop
bdelay:
clr p2.1 ; R/w low for a write mode  
clr p2.2
nop
setb p2.2 ;enable pulse
nop
clr P2.2  ;enable H->
L
nop
;******************* Check Busy Flag
;mov p1,#0ffh ;configure port1 to input mode
;no need to make all lines 1 just make the bit 7 as inout
setb P1.7
setb p2.1 ;set RW to read
clr p2.0 ;set RS to command
bloop:
clr p2.2 ;generate enable pulse
nop
setb p2.2
nop
;mov a,p1
;anl a,#80h ;check bit#7 busy flag
;cjne a,#00h,bloop;keep waiting until bu
jb P1.7 bloop  ;jump if P1.7 is 1
;*****************************************
; check busy flag twice
;*****************************************
;bwait:
;clr p2.2 ;generate enable pulse
;nop
;setb p2.2
;nop
;mov a,p1
;anl a,#80h ;check bit#7 busy flag
;cjne a,#00h,bloop;keep waiting until bu
;There is no need of above commented code...
ret


try now.. hope it works..


[ Edited Thu Jan 03 2008, 11:36 am ]
Thu Jan 03 2008, 05:39 pm
#10
it still doesn't work..the lcd does not do anything..i dont know were it gone wrong...my code below..
 

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

StevenDrulk
Sat Apr 27 2024, 08:47 pm
StephenHauct
Sat Apr 27 2024, 09:38 am
Adamsaf
Sat Apr 27 2024, 07:12 am
Robertphype
Sat Apr 27 2024, 12:23 am
ktaletrryp
Fri Apr 26 2024, 10:55 pm
Robertrip
Fri Apr 26 2024, 11:20 am
ArnoldDiant
Fri Apr 26 2024, 03:53 am
RodneyKnorb
Thu Apr 25 2024, 07:08 pm