Searching \ for '[PIC] Interfacing to a Hitachi 44780 LCD in 4-bit' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/io/lcd/pic.htm?key=lcd
Search entire site for: 'Interfacing to a Hitachi 44780 LCD in 4-bit'.

Exact match. Not showing close matches.
PICList Thread
'[PIC] Interfacing to a Hitachi 44780 LCD in 4-bit '
2007\06\10@173740 by Matthew Mucker

flavicon
face
All,

I've been debugging this problem for weeks and haven't found where my error
is, so I'm turning to the list for help. I'm trying to drive a Hitachi 44780
LCD module in 4-bit mode from a PIC chip.

I have my PIC 16F628 connected to the LCD module as follows:

RB4 --> LCD_E
RB3 --> LCD_RS
RA0 --> LCD_D4
RA1 --> LCD_D5
RA2 --> LCD_D6
RA3 --> LCD_D7

I have tested each of these outputs and verified that I can write a logic
'1' or '0' and get the expected voltage.

I've used Myke Predko's page (http://www.myke.com/lcd.htm) as my main reference.

According to MPLAB SIM, my code is writing the following when the LCD_E line
is blipped:

                       LCD
                       DATA        LCD
TIME                        7654        RS        notes

0                        0011        0        send 0x03, wait 5msec
5.1964                0011        0        send 0x03, wait 160 usec
5.5218                0011        0        send 0x03 a third time, wait 160 usec
5.8472                0010        0        Enable 4-bit mode (following commands are
two nybbles)
6.0126                0010        0
6.1766                1000        0        00101000: 4-bit mode, 2 line display, 5x7
font
6.3248                0000        0
6.5068                1000        0        00001000: disp. Off, cursor off, blink off
6.6730                0000        0
6.8370                0001        0        00000001: clear display, wait
12.0356                0000        0
12.1996                0110        0        00000110: increment cursor/no shift
12.3658                0000        0
12.5298                1100        0        00001100: display on, cursor off, blink off
12.6968                0000        0        
12.8608                0010        0        00000010: home cursor
18.0618                0101        1
18.2258                0111        1        Letter 'W', first character to be displayed

The LCD doesn't seem to initialize and for sure my characters aren't being
displayed. I'm getting quite frustrated with this project. I'm hoping
someone out there can spot the error of my ways for me and help me get back
on the straight and narrow.

Thanks,

-Matt

2007\06\10@175518 by Jan-Erik Soderholm

face picon face
Matthew Mucker wrote:
> All,
>
> I've been debugging this problem for weeks and haven't found where my error
> is, so I'm turning to the list for help. I'm trying to drive a Hitachi 44780
> LCD module in 4-bit mode from a PIC chip.

Do you get the lines (1 line one on a 2 line module and 2
lines on a 4 line module) with dark "blocks" after
power-on ?
Do you have the contrast adjustment adjusted correctly ?
Std or ext temp range module ?

/Jan-Erik




2007\06\10@180108 by David VanHorn

picon face
Have you set the bias voltage?
You should have it at the point where the char cells are JUST starting
to get dark.
Without the bias voltage, even if you have it right, you won't see anything.

Second: Verify the timing, and sequence of events.  Add extra delays.



On 6/10/07, Matthew Mucker <spam_OUTmatthewTakeThisOuTspammucker.net> wrote:
{Quote hidden}

> -

2007\06\10@180458 by Jesse Lackey

flavicon
face
Hello, two comments / questions for you...

I'm not sure if it is the same LCD driver chip, but the one in an LCD
from Lumex I used on this project:
www.celestialaudio.com/MC9S12NE64/index.html
had so many problems in 4-bit mode that I gave up and used it in 8-bit
mode.  I discuss this a little on the webpage.

So if possible, for starters anyway, can you switch to 8-bit mode to
eliminate that source of possible error?

Secondly, is there a "dimming voltage" on the LCD you are using?  The
lumex datasheet spec and schematic were given in an unclear way and
tripped me up.  So for awhile I was doing everything right but no
display b/c I had that voltage wrong.

Good luck to you.  I was not happy about the problems I had with this
LCD as well.

J



Matthew Mucker wrote:
{Quote hidden}

2007\06\10@182648 by Jinx

face picon face
Is R/W tied low ?

2007\06\10@182952 by Matthew Mucker

flavicon
face
Yes, I have the contrast adjusted correctly.  I get the first line of
blocks, the second line clear. (It's a 2 line by 25 char display.)

> {Original Message removed}

2007\06\10@183238 by Matthew Mucker

flavicon
face
I'd love to use 8-bit mode, but I'm out of pins on the PIC!

{Quote hidden}

usec
> > 5.8472                0010        0        Enable 4-bit mode (following
commands are
> > two nybbles)
> > 6.0126                0010        0
> > 6.1766                1000        0        00101000: 4-bit mode, 2 line
display, 5x7
> > font
> > 6.3248                0000        0
> > 6.5068                1000        0        00001000: disp. Off, cursor off,
blink
> off
> > 6.6730                0000        0
> > 6.8370                0001        0        00000001: clear display, wait
> > 12.0356                0000        0
> > 12.1996                0110        0        00000110: increment cursor/no shift
> > 12.3658                0000        0
> > 12.5298                1100        0        00001100: display on, cursor off,
blink
{Quote hidden}

> -

2007\06\10@185244 by Jinx

face picon face
How are you writing two nybbles ? LSN, MSN, Busy ?

2007\06\10@190001 by stef mientki

flavicon
face
Matthew Mucker wrote:
> All,
>
> I've been debugging this problem for weeks and haven't found where my error
> is, so I'm turning to the list for help. I'm trying to drive a Hitachi 44780
> LCD module in 4-bit mode from a PIC chip.
>  
Are you sure you have a "real" 44780 ?
Anyway after using a lot of displays without any problems,
I got a VARITRONIX type which gave a lots of trouble.
An extra delay solved the problem, see code below.

success,
Stef Mientki



|-- <Version: 1.2    ,01-09-2004, Stef Mientki
--    - Extra delay in Init procedure, after 4-bits setting,
--      needed for VARITRONIX MDLS-16268-series
--        Problem was a uncomplete reset, after which the total behaviour was instable

||
const _HD44780_short_delay = 5|

|
||procedure LCD_init is
 -- if multiplexed IO-pins, these values will be set just before sending
 if ! HD44780_multiplexed_output then
   HD44780_b4_pin        = low
   HD44780_b5_pin        = low
   HD44780_b6_pin        = low
   HD44780_b7_pin        = low
   HD44780_DataCmd_pin   = low

   HD44780_b4_direction  = output
   HD44780_b5_direction  = output
   HD44780_b6_direction  = output
   HD44780_b7_direction  = output
   HD44780_DataCmd_direction = output
 end if

 HD44780_Enable_pin       = low
 HD44780_Enable_direction = output

 delay_1mS ( 40 )                      -- even long enough for Vcc as low as 2.7V
 HD44780_DataCmd_pin = low                 -- select command
 _HD44780_write_low_nibble ( 0b_0011 ) -- first init
 delay_1mS ( 5 )                       -- extra delay
 _HD44780_write_low_nibble ( 0b_0011 ) -- second init
 delay_10uS( 10 )                      -- extra delay
 _HD44780_write_low_nibble ( 0b_0011 ) -- third init

 _HD44780_write_low_nibble ( 0b_0010 ) -- set 4-bit interface
 delay_10uS( _HD44780_short_delay )    -- FOR SOME DISPLAYS (VARITRONIX) required delay
 _HD44780_Command( 0b_0010_1000 )      -- two lines, 5x7 (high nibble)
 _HD44780_Command( 0b_0000_1111 )      -- display on, cursor on, blink on
 _HD44780_Command( 0b_0000_0001 )      -- clear display
 _HD44780_Command( 0b_0000_0110 )      -- increment and no shift

 -- now display version of this lib
 delay_1ms(100)
 LCD_char_pos ( "V", 1)
 LCD_char_pos ( " ", 2)
 LCD_char_pos ( "1", 3)
 LCD_char_pos ( ".", 4)
 LCD_char_pos ( "4", 5)
end procedure
|

{Quote hidden}

2007\06\10@223701 by Matthew Mucker

flavicon
face
Yes, R/W is tied low through a 1K resistor.

> -----Original Message-----
> From: .....piclist-bouncesKILLspamspam.....mit.edu [EraseMEpiclist-bouncesspam_OUTspamTakeThisOuTmit.edu] On
> Behalf Of Jinx
> Sent: Sunday, June 10, 2007 5:26 PM
> To: Microcontroller discussion list - Public.
> Subject: Re: [PIC] Interfacing to a Hitachi 44780 LCD in 4-bit mode
>
> Is R/W tied low ?
>
> -

2007\06\10@223849 by Matthew Mucker

flavicon
face
Yup, it's clearly labeled with the Hitachi name and the 44780 part number.

{Quote hidden}

usec
> > 5.8472                0010        0        Enable 4-bit mode (following
commands are
> > two nybbles)
> > 6.0126                0010        0
> > 6.1766                1000        0        00101000: 4-bit mode, 2 line
display, 5x7
> > font
> > 6.3248                0000        0
> > 6.5068                1000        0        00001000: disp. Off, cursor off,
blink
> off
> > 6.6730                0000        0
> > 6.8370                0001        0        00000001: clear display, wait
> > 12.0356                0000        0
> > 12.1996                0110        0        00000110: increment cursor/no shift
> > 12.3658                0000        0
> > 12.5298                1100        0        00001100: display on, cursor off,
blink
{Quote hidden}

> -

2007\06\10@224112 by Matthew Mucker

flavicon
face
The simulator says that the data pins are giving the values I expect (my
original table was data from the simulator), but if it matters here are my
code snippets:

SendByteToLCD:
               ;send the two nybbles to the LCD display
               movwf TempByteToLCD
               swapf TempByteToLCD, 0 ;the LCD expects the high nybble
first
               call SendNybbleToLCD
               movfw TempByteToLCD
               call SendNybbleToLCD
               return

SendNybbleToLCD:
               ;send the low nybble of w to the LCD display.
               andlw b'00001111' ;only the low four bits of WREG count
               banksel PORTA
               movwf PORTA ;send the four bits out of the I/O port
               nop
               nop

               ;raise the E line
               bsf LCD_E
               nop
               nop

               ;lower the E line
               bcf LCD_E

               ;wait 160us between commands
               movlw d'160'
               call Wait_WREG_Microseconds
               return



> -----Original Message-----
> From: KILLspampiclist-bouncesKILLspamspammit.edu [RemoveMEpiclist-bouncesTakeThisOuTspammit.edu] On
> Behalf Of Jinx
> Sent: Sunday, June 10, 2007 5:52 PM
> To: Microcontroller discussion list - Public.
> Subject: Re: [PIC] Interfacing to a Hitachi 44780 LCD in 4-bit mode
>
> How are you writing two nybbles ? LSN, MSN, Busy ?
>
> -

2007\06\10@225832 by Jinx

face picon face
> The simulator says that the data pins are giving the values I expect
> (my original table was data from the simulator), but if it matters here
> are my code snippets:

Looks OK (sorry, I said LSN before MSN). How about RS ? It
would be 0 during initialisation and 1 to write the "W" to the screen

2007\06\10@230629 by Jinx

face picon face

> Yes, I have the contrast adjusted correctly.  I get the first line of
> blocks, the second line clear. (It's a 2 line by 25 char display.)

Has it had excess voltage ? I've found LCDs are not very tolerant
and will die at the drop of a hat, even though they may appear to be
OK, looking as you describe above

2007\06\10@234500 by Maarten Hofman

face picon face
Redwood Shores, 10 juni 2007.

I once used a 1K resistor for pulldown of the R/W of a 44780-compatible. It
turned out that that was not enough to actually pull it down: it had to be
truly grounded. Fortunately the "44780" also won the competition on the
databus, only destroying my 16F877A PORTD and nothing else (at least, so far
it doesn't look like it destroyed more). I recommend not using a resistor at
all, and just connecting the R/W to ground directly.

Greetings,
Maarten Hofman.

2007\06\10@235527 by Bob Axtell

face picon face
Matthew Mucker wrote:
> Yes, R/W is tied low through a 1K resistor.
>
>  
>> -----Original Message-----
>> From: spamBeGonepiclist-bouncesspamBeGonespammit.edu [TakeThisOuTpiclist-bouncesEraseMEspamspam_OUTmit.edu] On
>> Behalf Of Jinx
>> Sent: Sunday, June 10, 2007 5:26 PM
>> To: Microcontroller discussion list - Public.
>> Subject: Re: [PIC] Interfacing to a Hitachi 44780 LCD in 4-bit mode
>>
>> Is R/W tied low ?
>>
>> --

2007\06\11@050806 by Jan-Erik Soderholm

face picon face
Another thing...

> 12.5298   1100 0 00001100: display on, cursor off, blink off
> 12.6968   0000 0

You could try to change to "curson on"
to see if the cursor is visable at least...

Jan-Erik.


2007\06\11@052750 by Michael Rigby-Jones

picon face


{Quote hidden}

Note that the LCD controller is busy for approximately 10ms after power up, so you must wait at least this long before attemping to configure it!

Regards

Mike

=======================================================================
This e-mail is intended for the person it is addressed to only. The
information contained in it may be confidential and/or protected by
law. If you are not the intended recipient of this message, you must
not make any use of this information, or copy or show it to any
person. Please contact us immediately to tell us that you have
received this e-mail, and return the original to us. Any use,
forwarding, printing or copying of this message is strictly prohibited.
No part of this message can be considered a request for goods or
services.
=======================================================================

2007\06\11@065321 by Jinx

face picon face
> Note that the LCD controller is busy for approximately 10ms
> after power up, so you must wait at least this long before
> attemping to configure it!

Very true. I've had to increase my delay after power-up from
the usual 15ms to 30ms with some (no-name) brands. They
simply don't play ball if you try to initialise too early. Maybe
start with 50ms, decrease until it fails if power-up time is an
issue


2007\06\11@073659 by Anand Gadiyar

picon face
On 6/11/07, Jinx <EraseMEjoecolquittspamclear.net.nz> wrote:
> > Note that the LCD controller is busy for approximately 10ms
> > after power up, so you must wait at least this long before
> > attemping to configure it!
>
> Very true. I've had to increase my delay after power-up from
> the usual 15ms to 30ms with some (no-name) brands. They
> simply don't play ball if you try to initialise too early. Maybe
> start with 50ms, decrease until it fails if power-up time is an
> issue
>

I had been struggling to get the LCD working in 4-bit mode on my board
for a long long time. Increasing the initial delay to 30ms did the
trick for me too. :)

--Anand

2007\06\11@081955 by Peiserma

flavicon
face
piclist-bounces@mit.edu wrote:
>> Note that the LCD controller is busy for approximately 10ms after
>> power up, so you must wait at least this long before attemping to
>> configure it!
>
> Very true. I've had to increase my delay after power-up from
> the usual 15ms to 30ms with some (no-name) brands. They
> simply don't play ball if you try to initialise too early.
> Maybe start with 50ms, decrease until it fails if power-up
> time is an issue

I also use 30ms. I've pasted a snipped of my c-code for 4bit
initialization which worked for me. should be easy enough to
convert to asm...


//        Copywrite Craig Lee 1998
//
// REVISION HISTORY
//        08/19/02 P.O.E.

[snip]

       LCD_TRIS_RS = 0;
       LCD_TRIS_EN = 0;
       LCD_EN = 0;                // enable
       LCD_RS = 0;                // register select
       LCD_TRIS_D4 = 0;
       LCD_TRIS_D5 = 0;
       LCD_TRIS_D6 = 0;
       LCD_TRIS_D7 = 0;

       DelayMs(30);                // power on delay

       lcd_write_nybble(0x3);        //DB5, DB4 = 1
       DelayMs(5);

       lcd_write_nybble(0x3);        //DB5, DB4 = 1
       DelayMs(5);

       lcd_write_nybble(0x3);        //DB5, DB4 = 1
       DelayMs(5);

       //get 4 bit interface
       lcd_write_nybble(0x2);        //DB5 = 1
       DelayMs(5);

       //function set. 4 bit, 2 lines, 5x8 dots
       lcd_command(LCD_FUNCMODE | LCD_4BITS | LCD_2LINES | LCD_5x8);
       
       //display control, all off
       lcd_command(LCD_DISPCNTRL);

       //clear display
       lcd_command(0x01);
       DelayMs(5);

       //entry mode increment (advance) cursor
       lcd_command(LCD_ENTRYMODE | LCD_INC);

       //display control, display on
       lcd_command(LCD_DISPCNTRL | LCD_DISPLAY);

2007\06\11@084655 by Michael Rigby-Jones

picon face


>-----Original Message-----
>From: RemoveMEpiclist-bouncesEraseMEspamEraseMEmit.edu [RemoveMEpiclist-bouncesspam_OUTspamKILLspammit.edu]
>On Behalf Of Jinx
>Sent: 11 June 2007 11:53
>To: Microcontroller discussion list - Public.
>Subject: Re: [PIC] Interfacing to a Hitachi 44780 LCD in 4-bit mode
>
>
>> Note that the LCD controller is busy for approximately 10ms after
>> power up, so you must wait at least this long before attemping to
>> configure it!
>
>Very true. I've had to increase my delay after power-up from
>the usual 15ms to 30ms with some (no-name) brands. They simply
>don't play ball if you try to initialise too early. Maybe
>start with 50ms, decrease until it fails if power-up time is an issue

The delay needed above the 10ms minimum depends on the rise time of the power rail, and the threshold at which the PIC starts working compared to the LCD.  The original Hitachi HD44780 has a threshold of 4.5volts for the standard 5v part.  The PIC could come out of brownout as low as 3.7volts for a 5v part.

The busy flag is opertational during this period, so if you have R/W connected to a pin the safest method is to poll the busy register after power on until clear (with a suitable timeout).  I don't know if the clones do this or not.

Regards

Mike

=======================================================================
This e-mail is intended for the person it is addressed to only. The
information contained in it may be confidential and/or protected by
law. If you are not the intended recipient of this message, you must
not make any use of this information, or copy or show it to any
person. Please contact us immediately to tell us that you have
received this e-mail, and return the original to us. Any use,
forwarding, printing or copying of this message is strictly prohibited.
No part of this message can be considered a request for goods or
services.
=======================================================================

2007\06\11@092109 by Jinx

face picon face
> The busy flag is opertational during this period, so if you have R/W
> connected to a pin the safest method is to poll the busy register after
> power on until clear (with a suitable timeout).  I don't know if the
> clones do this or not.

Clones are usually pretty good and I try to stick with what I know,
just expect the odd anomaly now and then. When using the minimum
standard interface, with R/W tied low, Busy isn't available of course.
That's a h/w up side, possibly a s/w (timing) down side

2007\06\11@145300 by Brooke Clarke

flavicon
face
Hi Matthew:

There are a number of things that can go wrong besides what's already been
mentioned.

1) some of the PIC code for the 44780 has bugs.
2) when trying to drive a nibble you often mess up the other bits since the
tendency is to use Byte wide commands.
3) there are some time delays that need to be observed during the
initialization of the LCD
4) it's best to read back the status bit.  If you don't then there's a gray
area where you need to have delays so you're sure the LCD has finished
processing the last command.  Some commands can take a L o n g   t i m e.

I highly recommend that you download the free code used in the PIC Kit 2 for
the LCD interface.  It treats each pin separately which avoids problem (2) and
gives you the freedom of assigning the LCD AFTER you have chosen the pins for
the other stuff, no need to reserve a nibble.

--
Have Fun,

Brooke Clarke
http://www.PRC68.com
http://www.precisionclock.com

2007\06\12@041159 by Lind, Allan

flavicon
face
> The LCD doesn't seem to initialize and for sure my characters aren't
being
> displayed. I'm getting quite frustrated with this project. I'm hoping
> someone out there can spot the error of my ways for me and help me get
back
> on the straight and narrow.

High Voltages near the module can prevent initialization from working.
I made a Geiger counter and had tons of problems trying to get my LCD to
initialize in 4 bit mode.
The problem turned out to be NOT the code, but that the 650V circuitry
was too close to the data lines feeding the LCD.
I shortened the data lines and shielded with some foil, and everything
started working great!
Here are segments of the code I used (uses internal 48KHz clock)

Regards,
Allan



       include "P16F628A.INC"
       list        p=PIC16f628A
       __CONFIG _CP_OFF & _PWRTE_OFF & _WDT_OFF & _MCLRE_OFF &
_INTOSC_OSC_NOCLKOUT & _LVP_OFF & _BODEN_OFF


; -------------
; LCD Data
; RA0        DB4        O/P
; RA1        DB5        O/P
; RA2        DB6        O/P
; RA3        DB7        O/P
; -------------


; RA6 for E                O/P
; RA7 for RS        O/P
; Ground RW



#define LCD_E        PORTA, 6
#define LCD_RS        PORTA, 7

       ORG        0
       goto        Start

       org        0x4                ; Interrupt Vector


Start
       call        LCD_init

;        rest of code here



LCDstr
       addwf        PCL, f
       DT 0x33,0x32,0x28,0x01,0x0c,0x06,0


;========================================
;        LCD INIT ROUTINE
;========================================

LCD_init
       clrf        PORTA
       call        MEDDELAY        ; wait 20 mS
       call        MEDDELAY
       bcf        LCD_RS        ; clear RS
       bcf        LCD_E                ; clear ENA


       clrf        MSGPTR
       movf        MSGPTR, W
       call        LCDstr                ; Get first byte from string into W
register
       movwf        CHAR                        ; Store in string

get_LCDstr                                ; Initialization string for LCD

       bsf        LCD_E                        ; Drive ENA High
       swapf        CHAR, w                ; swap nibbles
       andlw        0x0f                        ; mask out the upper nibble
       iorlw        b'01000000'                ; ensure ENA stays High
       movwf        PORTA                        ; send upper nibble
       bcf        LCD_E                        ; Drive E low so LCD will
process input
       call        MEDDELAY                ; Wait 10ms
       bsf        LCD_E                        ; Drive ENA High
       movf        CHAR, w
       andlw        0x0f                        ; mask out the upper nibble
       iorlw        b'01000000'                ; ensure ENA stays High
       movwf        PORTA                        ; send lower nibble

       bcf        LCD_E                        ; Drive E low so LCD will
process input
       call        MEDDELAY                ; Wait 10ms
       incf        MSGPTR, f
       movf        MSGPTR, W                  ; increment pointer - put the
offset in W register
       call        LCDstr                ; fetch the next byte from the string
into W Register
       movwf        CHAR                        ; Store in string
       andlw        0xff                        ; sets the zero flag if W = 0
       btfss        STATUS, Z                ; skip if zero bit set
       goto        get_LCDstr
       call        MEDDELAY                ; Wait 10ms
       bsf        LCD_RS                ; set RS
       clrf        MSGPTR
       return                        ; finished if W = 0



SHORTDELAY                        ; Delay of 550uS
       clrwdt
       nop
       nop

       return

MEDDELAY                        ; Delay of 10mS
       movlw        14
       movwf        STORE2
LOOP2        call        SHORTDELAY
       decfsz        STORE2,1
       goto        LOOP2
       return

2007\06\12@052913 by Jinx

face picon face
> High Voltages near the module can prevent initialization from working.

I haven't had initialisation fail but had relays too close to LCD wiring,
which made it go nutty. Answer was like yours - re-route and screen

2007\06\12@140213 by Rich Satterlee

flavicon
face
Hi-

Might I suggest that it is not the connected data lines, rather it is the open
data lines that are causing the problem?  I wonder if shielding could be reduced or
eliminated by pulling the unused data lines (up or down, I don't have the data
sheet with me) with series resistors?

 Cheers,

    Rich S.

---- Original Message ----
From:                Lind, Allan
Date:                Tue 6/12/07 1:23
To:                Microcontroller discussion list - Public.
Subject:        RE: [PIC] Interfacing to a Hitachi 44780 LCD in 4-bit mode

> The LCD doesn't seem to initialize and for sure my characters aren't
being
> displayed. I'm getting quite frustrated with this project. I'm hoping
> someone out there can spot the error of my ways for me and help me get
back
> on the straight and narrow.

High Voltages near the module can prevent initialization from working.
I made a Geiger counter and had tons of problems trying to get my LCD to
initialize in 4 bit mode.
The problem turned out to be NOT the code, but that the 650V circuitry
was too close to the data lines feeding the LCD.
I shortened the data lines and shielded with some foil, and everything
started working great!
Here are segments of the code I used (uses internal 48KHz clock)

Regards,
Allan



       include "P16F628A.INC"
       list        p=PIC16f628A
       __CONFIG _CP_OFF & _PWRTE_OFF & _WDT_OFF & _MCLRE_OFF &
_INTOSC_OSC_NOCLKOUT & _LVP_OFF & _BODEN_OFF


; -------------
; LCD Data
; RA0        DB4        O/P
; RA1        DB5        O/P
; RA2        DB6        O/P
; RA3        DB7        O/P
; -------------


; RA6 for E                O/P
; RA7 for RS        O/P
; Ground RW



#define LCD_E        PORTA, 6
#define LCD_RS        PORTA, 7

       ORG        0
       goto        Start

       org        0x4                ; Interrupt Vector


Start
       call        LCD_init

;        rest of code here



LCDstr
       addwf        PCL, f
       DT 0x33,0x32,0x28,0x01,0x0c,0x06,0


;========================================
;        LCD INIT ROUTINE
;========================================

LCD_init
       clrf        PORTA
       call        MEDDELAY        ; wait 20 mS
       call        MEDDELAY
       bcf        LCD_RS        ; clear RS
       bcf        LCD_E                ; clear ENA


       clrf        MSGPTR
       movf        MSGPTR, W
       call        LCDstr                ; Get first byte from string into W
register
       movwf        CHAR                        ; Store in string

get_LCDstr                                ; Initialization string for LCD

       bsf        LCD_E                        ; Drive ENA High
       swapf        CHAR, w                ; swap nibbles
       andlw        0x0f                        ; mask out the upper nibble
       iorlw        b'01000000'                ; ensure ENA stays High
       movwf        PORTA                        ; send upper nibble
       bcf        LCD_E                        ; Drive E low so LCD will
process input
       call        MEDDELAY                ; Wait 10ms
       bsf        LCD_E                        ; Drive ENA High
       movf        CHAR, w
       andlw        0x0f                        ; mask out the upper nibble
       iorlw        b'01000000'                ; ensure ENA stays High
       movwf        PORTA                        ; send lower nibble

       bcf        LCD_E                        ; Drive E low so LCD will
process input
       call        MEDDELAY                ; Wait 10ms
       incf        MSGPTR, f
       movf        MSGPTR, W                  ; increment pointer - put the
offset in W register
       call        LCDstr                ; fetch the next byte from the string
into W Register
       movwf        CHAR                        ; Store in string
       andlw        0xff                        ; sets the zero flag if W = 0
       btfss        STATUS, Z                ; skip if zero bit set
       goto        get_LCDstr
       call        MEDDELAY                ; Wait 10ms
       bsf        LCD_RS                ; set RS
       clrf        MSGPTR
       return                        ; finished if W = 0



SHORTDELAY                        ; Delay of 550uS
       clrwdt
       nop
       nop

       return

MEDDELAY                        ; Delay of 10mS
       movlw        14
       movwf        STORE2
LOOP2        call        SHORTDELAY
       decfsz        STORE2,1
       goto        LOOP2
       return

2007\06\12@141115 by Rich Satterlee

flavicon
face
Hi-

I can't answer for the PICKIT code (I'm sure its fine).  However, I am just starting
with the ET ARM stamp set and their example code for the 4 digit LCD display is in
error.  I had to slow down the timing loops to get my display working.  I have used
that display in PIC designs without a problem, however this code uses time delays
rather than looking at the busy bit as my pic code does.  I'm pretty sure that the
specs on my display are faster than the Hitachi specs.  I don't have the data sheets
with me now to verify.  Just got through this exercise last week. Sigh.

Might I also suggest that if one wants to design his/her own code that one might try
starting with the 8 bit interface to get some familiarity with the device, then
going to a 4 bit interface.  This is the process I went through although I tried
starting with a 4 bit interface.  This made the reading of the character ram on the
display a little easier.

 Cheers,

  Rich S.

---- Original Message ----
From:                Brooke Clarke
Date:                Mon 6/11/07 12:26
To:                RemoveMEpiclistTakeThisOuTspamspammit.edu, Matthew Mucker
Subject:        [PIC] Interfacing to a Hitachi 44780 LCD in 4-bit mode

Hi Matthew:

There are a number of things that can go wrong besides what's already been
mentioned.

1) some of the PIC code for the 44780 has bugs.
2) when trying to drive a nibble you often mess up the other bits since the
tendency is to use Byte wide commands.
3) there are some time delays that need to be observed during the
initialization of the LCD
4) it's best to read back the status bit.  If you don't then there's a gray
area where you need to have delays so you're sure the LCD has finished
processing the last command.  Some commands can take a L o n g   t i m e.

I highly recommend that you download the free code used in the PIC Kit 2 for
the LCD interface.  It treats each pin separately which avoids problem (2) and
gives you the freedom of assigning the LCD AFTER you have chosen the pins for
the other stuff, no need to reserve a nibble.

--
Have Fun,

Brooke Clarke
http://www.PRC68.com
http://www.precisionclock.com

2007\06\12@200424 by Jinx

face picon face
> by pulling the unused data lines (up or down

A genuine 44780 has internal pull-ups

2007\06\13@020930 by Rich Satterlee

flavicon
face
Hi-

O.K. Just a thought.  I'm not sure what the "other" interfaces are like.  I *DO*
know that my R/S line on this display was "funny" and had to be pulled down from
an open drain connection.  Opps, that one was a little 16X2 "no name" that I had
using the open drain of RA4 (for the 16F628).  Until I pulled it down (and yes,
I had a pullup on the open drain, I had "interesting" times with it).  

See what happens when you don't have your data sheets with you?

 Cheers,

  Rich S.

---- Original Message ----
From:                Jinx
Date:                Tue 6/12/07 17:16
To:                Microcontroller discussion list - Public.
Subject:        Re: [PIC] Interfacing to a Hitachi 44780 LCD in 4-bit mode

> by pulling the unused data lines (up or down

A genuine 44780 has internal pull-ups

2007\06\13@045537 by Jan-Erik Soderholm

face picon face
And note also that *if* one uses the module
in read/write mode (to read the busy flag)
the module will drive the remaining 4 data
lines. So do not tie them *hard* up or down...

Jan-Erik.

Jinx wrote:
>> by pulling the unused data lines (up or down
>
> A genuine 44780 has internal pull-ups
>

2007\06\13@052429 by Jinx

face picon face

> And note also that *if* one uses the module
> in read/write mode (to read the busy flag)
> the module will drive the remaining 4 data
> lines. So do not tie them *hard* up or down...

That's right. The read sequence is set the PIC I/O to input
(the LCD's MOS pull-ups will stop a float) then R/W = 1,
otherwise you have two outputs busses clashing, even for
what might be just an instant. I think the PIC would probably
win the current drive battle

More... (looser matching)
- Last day of these posts
- In 2007 , 2008 only
- Today
- New search...