89C4051 Newbie needs help

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View
Hi,

I have connected a 16X2 LCD to my 4051 on a breadboard. The P1 is connected
to the data lines of the LCD in 8 bit format.  RW is grounded, RS to P3.0
and E to P3.1.

I wrote a short program to send the bytes 38h, 38h, 06, 0Fh, 01 to P1 and on
each byte I pulsed the E line H then L.  But nothing happened on the LCD.  I
attached the software at below.  Can anyone see what's wrong with it?

 ; MYLCD.asm     written on 030822
;
; P1 as LCD data and p3.0 & p3.1 as rs & e
;
$mod51

LCD_data        set     p1
LCD_RS          equ     0b0h    ;p3.0
LCD_E           equ     0b1h    ;p3.1
;
config          equ     38h     ;8 bit data, 2 lines, 5x7 matrix
entrymode       equ     6       ;inc cursor, do not shift display
combncur        equ     0fh
clrdsp          equ     1
;
                org     0000h
;
reset:          jmp     start
;
                org     0100h
;
start:          mov     p1,#0           ;set p1 dir out
                clr     LCD_rs          ;set rs L
                clr     LCD_E           ;set e L
                mov     r0,#config      ;#38
                call    wrlcd           ;send it to LCD
                mov     r0,#config      ;#38
                call    wrlcd
                mov     r0,#entrymode   ;#06
                call    wrlcd
                mov     r0,#combncur    ;#0f
                call    wrlcd
                mov     r0,#clrdsp      ;#01
                call    wrlcd
loop:         jmp   loop
;
wrlcd:          push    acc
                mov     a,r0
                mov     p1,a
                clr     lcd_rs          ;make sure it is L
                setb    lcd_e           ;pulse lcd_e
                clr     lcd_e
                call    wait            ;wait for 65ms
                pop     acc
                ret
wait:           mov     r2,#0ffh        ;delay for a while
wait0:          mov     r3,#0ffh
wait1:          nop
                djnz    r3,wait1
                nop
                djnz    r2,wait0
                ret
                end                     ;end of program


Allen


------
The next war will determine NOT who is right  BUT what is left.




Re: 89C4051 Newbie needs help
Quoted text here. Click to load it

Sorry, haven't really got the inclination
to check your code for you - but you might
want to check that you have pullups on
P1.0 and P1.1 (common trap with this micro)

You also need to monitor busy on most LCD's,
and transmit when the LCD is not busy,
and you usually need to go through an initialisation
sequence for the LCD.  Good Luck.

Regards
Steve

www.airborn.com.au



Re: 89C4051 Newbie needs help

Quoted text here. Click to load it
connected
P3.0
and on
LCD.  I
Quoted text here. Click to load it

No, is 10K ohms OK for this purpose?  What about p3.0 and p3.1?  Do they
also need pullups?

Quoted text here. Click to load it

No, I didn't monitor the busy as I gave it ample time (65ms) to do its job.



Quoted text here. Click to load it



Re: 89C4051 Newbie needs help

Quoted text here. Click to load it



Yes, that should be just great.  If the LCD has pullups
then they wouldn't be required - but I don't think many
LCDs have pullups.

Quoted text here. Click to load it

No, I think it is more just P1.0 and P1.1 because
they can also be the comparator lines.  They are OC.

Quoted text here. Click to load it

Yes, ofcourse - sorry, I didn't look properly.
Hopefully with this and a contrast pot it will
all spring into life.  If your LCD is a high
temp one, be careful - some of those need a
slight negative voltage on the contrast pot.
Either way, you should be able to wind it around until
the display goes a bit black, then back it off.

Regards
Steve

 www.airborn.com.au



Re: 89C4051 Newbie needs help
Thanks to Steve & Rein,

My 16X2 LCD is finally working.  I am going to add in the text to display
and later convert my software to work in 4 bit mode and make use of the RW
lines to detect BUSY state.  Without your help it would have meant another 3
weeks' hard work for me.  Thanks again.

Allen

Quoted text here. Click to load it
P1
job.



Re: 89C4051 Newbie needs help
Kind of looks ok to me. What clock speed is your CPU running at? You might want
to check to make sure you're holding E high for a long enough period with an
oscilloscope. Is your delay really 65ms (milliseconds) or did you mean us
(microseconds). If the former, then it seems excessive (but wouldn't hurt
talking to the LCD). If the latter, then it's too short for the 01 command
(82us to 1.64ms in the datasheet I'm looking at).

Re: 89C4051 Newbie needs help

Quoted text here. Click to load it
want
an

I am using 12MHz xtal and as the book says, 1 instruction per uS so the wait
loop should be greater than 65 mili-seconds as I looped it 255 X 255 times
with an NOP in between.

I have connected the LCD display to an New Micro NMIY-0031 board and use the
O (output byte) to send the sequence one byte at a time and the lcd
displayed a flashing cursor after the 01 (clrdsp) byte.  SO my LCD is
definitely good.

Allen




Re: 89C4051 Newbie needs help



Quoted text here. Click to load it
did you set the contrast? any "black" lines visible?  you only send
"clrdsp" command. how about one data byte?
rw


Re: 89C4051 Newbie needs help
Quoted text here. Click to load it

[snip]

Quoted text here. Click to load it

Only if you sent the appropriate contol bytes to turn the cursor on (&
select whether block or underline) and tell it to flash!!

There is not a lot of intelligence in these displays - you have to tell
them to do absolutely *everything*

HTH

Chris

Site Timeline