Re: 24X2 character LCD driver code
- From: "Chris Gentry" <chrisgentry@xxxxxxxxxxxxxxxx>
- Date: Fri, 16 Sep 2005 02:24:25 GMT
"James Waldby" <j-waldby@xxxxxxxx> wrote in message
news:4327BF45.A709BC9E@xxxxxxxxxxx
> Chris Gentry wrote:
>> "James Waldby" ... wrote ...
>> > Chris Gentry wrote: ...
>> >> I'm looking for assembly code to allow me to use my 24X2
>> >> character LCD module with a PIC 16F873A microcontroller.
>> > ...
>> >> [The LCD] does not work. I've checked the contrast, but
>> >> it might be in the initialization.
>> > ...
>> >> [The LCD] is a CFAH2402A-YYB-JP.
>> > ...
>> >> [Code is at] http://www.octowave.com/~lkmud/wavemaker
>> >
>> > comp.arch.embedded probably is a more-appropriate newsgroup
>> > for your query.
> [snip]
>> > Looking at the __LCD_INIT routine in
>> > http://www.octowave.com/~lkmud/wavemaker/lcd_4bit.inc
>> > it appears that P. Pemberton has not followed the
>> > correct sequence of LCD initialization instructions as
>> > shown on the second page of section 13 of your reference
>> > http://www.octowave.com/~lkmud/wavemaker/CFAH2402AYYBJP.pdf
>> > (ie, the page labeled "4-Bit Ineterface"). The correct
>> > sequence is: Wait > 15ms, send 0011, wait > 4.1 ms,
>> > send 0011, wait > .1 ms, send 0011, check BF (the busy
>> > flag), send 0010, etc. What the routine instead does is:
>> > Wait > 15ms, send 0011, send 0011, wait > 4.1 ms,
>> > send 0011, send 0011, wait > 1 ms, send 0011, send 0010,
>> > etc.
> [snip]
>
>> So in your estimation this would be good code to stick with?
>
> Since I'm used to reading AVR assembly and don't know much
> about pic's I thought it all looked just awful. :)
> But here's an idea to try anyway - Change:
> MOVLW B'00110011' ; 2x 8bit resets
> CALL LCD_SENDINS
> call Delay20MS
> MOVLW B'00110011' ; 2x 8bit resets
> CALL LCD_SENDINS
> CALL Delay1MS
> MOVLW B'00110010' ; 8bit reset then 4bit reset
> CALL LCD_SENDINS
> to:
> MOVLW B'0011' ; 8bit reset
> CALL LCD_SENDIN4
> call Delay20MS
> MOVLW B'0011' ; 8bit reset
> CALL LCD_SENDIN4
> CALL Delay1MS
> MOVLW B'0011' ; 8bit reset
> CALL LCD_SENDIN4
> CALL Delay1MS
> MOVLW B'0010' ; 4bit reset
> CALL LCD_SENDIN4
> where LCD_SENDIN4 is:
> LCD_SENDIN4:
> MOVWF __LCD_TEMP0 ; Store byte in Temp 0
> BCF LCD_RS ; RS low=instruction
> CALL __LCD_SEND4 ; Send 1 nibble
> CALL Delay1MS
> RETURN
> and __LCD_SEND4 is a label at line 43 in lcd_4bit.inc,
> ie, just before the second BCF LCD_D7 of __LCD_SEND.
> Note, see http://pat7.com/jp/2313s2.null.c at line 108; the
> ini0 table corresponds to those first 4 instructions which
> are sent to the LCD unit via its top 4 data lines; the
> lower nibbles should not be sent, because the unit is not
> yet in 4-bit mode. Your current code has no delay between
> the third 8-bit reset and the 4-bit reset, while spec says
> to check the busy flag or wait > 39 uS. (The code in
> 2313s2.null.c works ok for AVR AT90S2313 board like at
> http://pat7.com/jp/2313s2.sch.jpg .)
>
>> Someone told me my delays might not be correct, but I'm
>> not sure how to check them in MPSIM. I can simulate it,
>> but I don't know where it would show the correct
>> times.
>
> What is your crystal frequency, anyway? You should check
> out your delay routines by blinking an LED at 1Hz or an
> easy-to-time .2Hz etc before trying to get the LCD to work.
>
>> As for the contrast I get dark rectangles across the
>> first row when I turn it up.
>
> That is what you get just by applying power, which gives
> you 8-bit interface and 1-line display. After software
> initialization per specs you will have a blinking cursor
> in first column first row, and turning up the contrast
> won't show any black rectangles.
> -jiw
Ok, I've tried that and it didn't seem to work. I worked on the code, and
put everything
together. I tested my delays at 5seconds worth and they are very close. My
revised code is now
in one file and is at : http://www.octowave.com/~lkmud/wavemaker/
I think my initialization is working now, because I no longer get the solid
rectangles
all the way across the top. Now I am getting solid rectangles where the
characters are
supposed to be on line 1 and on line 2 I'm getting some weird looking
characters. They
look like a funny backwards 'e'. I did have the cursor on and blinking in
the code, but I took
that out. On the LCD the cursor was on and blinking when I had it in code.
So I think it
might have initialized correctly now, but something is still wrong. -Chris
.
- Follow-Ups:
- Re: 24X2 character LCD driver code
- From: James Waldby
- Re: 24X2 character LCD driver code
- References:
- 24X2 character LCD driver code
- From: Chris Gentry
- Re: 24X2 character LCD driver code
- From: James Waldby
- Re: 24X2 character LCD driver code
- From: Chris Gentry
- Re: 24X2 character LCD driver code
- From: James Waldby
- 24X2 character LCD driver code
- Prev by Date: Re: Parts stores on Long Island?
- Next by Date: Re: help finding a microprocessor trainer
- Previous by thread: Re: 24X2 character LCD driver code
- Next by thread: Re: 24X2 character LCD driver code
- Index(es):
Relevant Pages
|