Re: 24X2 character LCD driver code




"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


.



Relevant Pages

  • Re: LCD Display problem
    ... "Do you think the kernel is getting the image it wants to splash o to ... The LCD initialization is as per provided by LCD provider. ... "Look for display controller initialization in your lcd driver. ...
    (microsoft.public.windowsce.platbuilder)
  • Re: Help getting an LCD to work
    ... >> leads me to think my initialization routines aren't working (gee, ... >> the LCD. ... The info provided by Optrex is only ... > approximately accurate with respect to the time delays. ...
    (comp.arch.embedded)
  • Re: Help getting an LCD to work
    ... > leads me to think my initialization routines aren't working (gee, ... > the LCD. ... The main problem with getting Optrex LCDs to work is the ... The BUSY flag can and should be used from there onward. ...
    (comp.arch.embedded)
  • Re: Help getting an LCD to work
    ... Contrast voltage had to be negative. ... Wrong sequence of initialization commands. ... When using BUSY flag you have to watch carefuly during the initialization ... I had done initialization as written in one datasheet of my 2x16 LCD, ...
    (comp.arch.embedded)
  • Re: Cant enter safe mode -- bizarre video problem
    ... The display on my LCD screen then starts to quiver and blink. ... Through the quivering and blinking, I can see a black screen with some options to select. ...
    (microsoft.public.windowsxp.video)