piclist 2002\08\17\020524a >
Thread: LCD Contrast Variation
www.piclist.com/techref/io/lcd/pic.htm?key=lcd
face picon face BY : Jinx email (remove spam text)



> Could it be you didn't wait the 100ms at power-up before initialising
> the LCD? Resetting the PIC after power-up would be different from
> a cold power-up if the LCD was talked to too soon. Also, do you do
> the first part of the init code 3 times as recommended?

This is the LCD code I generally use, and it always has worked apart
from that one incident. It must have been something funny about that
circuit (or possibly even the PIC), although the screen did come right
when the speed was bumped up from 4MHz to 16MHz

The Hitachi handbook recommends waiting > 15ms after the LCD's
Vcc reaches 4.5V, and I've found 50ms works OK. If that problem
ever comes back perhaps I can try increasing the pu delay. Take it
as read that the msdelay routine does in fact delay 1 millisecond

;=================================================

        movlw   0xce         ;power-up delay 50ms
        movwf   temp
        call    msdelay
        incfsz  temp,f
        goto    $-2
        call     lcd_init

rest of code

;================================================
;        Initialise LCD screen
;================================================

lcd_init movlw  0x30
        movwf  portd
        bcf    rs
        bcf    rw
        bsf    en
        nop
        bcf    en
        call   msdelay      ;delay > 4.1ms
        call   msdelay
        call   msdelay
        call   msdelay
        call   msdelay

        bsf    en            ;write 0x30 again
        nop
        bcf    en
        call   msdelay       ;delay > 100us

        bsf    en            ;write 0x30 again
        nop
        bcf    en
        call   msdelay       ;delay > 100us

        movlw  0x38          ;2 lines, 5x7 font
        call   write_c
        movlw  0x0c          ;1+DCB = display on, no cursor, no blink
        call   write_c
        movlw  0x01          ;display clear
        call   write_c
        movlw  0x06          ;entry mode set, increment address
        call   write_c

        return               ;return from initialisation

;================================================
;        LCD commands
;================================================

line1    movlw  0x00          ;line 1, column 0
        call   address
        return

line2    movlw  0x40          ;line 2, column 0
        call   address
        return

address  addlw  0x80          ;set high bit of address command
        call   write_c
        return

write_c  bcf    rs            ;write command
        goto   d_out

write_d  bsf    rs            ;write data

d_out    movwf  portd
        bcf    rw
        bsf    en
        nop
        bcf    en
        call   busy
        return

busy     bsf    rw            ;set LCD RW for Read
        bcf    rs
        bank1
        movlw  b'11111111'   ;make d7 an input
        movwf  trisd
        bank0

        bsf    en
rdbusy   btfsc  bflag         ;loop until Busy Flag clear
        goto   $-1
        bcf    en
        bcf    rw

        bank1
        movlw  b'00000000'   ;d7 as output again
        movwf  trisd
        bank0

        return

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


<000c01c245b3$e8822120$e694a7cb@joe> 7bit

See also: www.piclist.com/techref/io/lcd/pic.htm?key=lcd
Reply You must be a member of the piclist mailing list (not only a www.piclist.com member) to post to the piclist. This form requires JavaScript and a browser/email client that can handle form mailto: posts.
Subject (change) LCD Contrast Variation

month overview.

new search...