I am trying to get an Hitachi LM016L LCD module working with a PIC 84,
with no success. I have had the module working with a STAMP, and I
understand everything I need to do to setup and use the module, but it
just ain't workin'.
I am using PORTA <0:3> for the LCD data port (connected to the MSB of
the LCD data pins), and PORTB <4:6> for E, RS and R/^W. Obviously I am
attempting to initialise the module for 4 bit operation. My question
is: am I likely to have problems with PORT A, and should I stick
everything on PORT B?
This is a simple problem, I just need reassurance to keep trying.
> I am trying to get an Hitachi LM016L LCD module working with a PIC 84,
> with no success. I have had the module working with a STAMP, and I
> understand everything I need to do to setup and use the module, but it
> just ain't workin'.
>
> I am using PORTA <0:3> for the LCD data port (connected to the MSB of
> the LCD data pins), and PORTB <4:6> for E, RS and R/^W. Obviously I am
> attempting to initialise the module for 4 bit operation. My question
> is: am I likely to have problems with PORT A, and should I stick
> everything on PORT B?
Not having used that direct configuration with the LCD I am speaking
from general experience with the LCD and C84 devices.
If it worked with the Stamp then your problem is probably timing related.
Put pauses of 2 ms after mode, clear and home commands and 100 us after
ather commands. Also send the enable pulse to the display with
3 instructions (lo-hi-lo) with possibly a short delay after the
data and address times have settled, the PIC is FAST and the LCD is
SLOW.
> This is a simple problem, I just need reassurance to keep trying.
If nothing helps, start the wiring and code from scratch and you will
probably notice your mistake :-)
Cheers
--
Kalle Pihlajasaari spam_OUTkalleTakeThisOuTdata.co.za
Interface Products Box 15775, Doornfontein, 2028, South Africa
+27 (11) 402-7750 Fax: +27 (11) 402-7751
>Hi All,
>
>I am trying to get an Hitachi LM016L LCD module working with a PIC 84,
>with no success. I have had the module working with a STAMP, and I
>understand everything I need to do to setup and use the module, but it
>just ain't workin'.
>
>I am using PORTA <0:3> for the LCD data port (connected to the MSB of
>the LCD data pins), and PORTB <4:6> for E, RS and R/^W. Obviously I am
>attempting to initialise the module for 4 bit operation. My question
>is: am I likely to have problems with PORT A, and should I stick
>everything on PORT B?
>
>This is a simple problem, I just need reassurance to keep trying.
>
>Andy (the other one)
>Lancaster, UK
>
>
I wonder if your problem is port A. Pin RA4 is an open collector output and may
float if the LCD module doesn't pull it up. This could cause problems when
doing the initialization. I usually use port A as the control lines and
port B as the data. If you are using the Microchip app notes, there are a
few errors. I have an example to control the LCD from a 16C84 but I can't
find the web address at the moment. E-mail me if you are interested in the
code.
>Hi All,
>
>I am trying to get an Hitachi LM016L LCD module working with a PIC 84,
>with no success. I have had the module working with a STAMP, and I
>understand everything I need to do to setup and use the module, but it
>just ain't workin'.
>
>I am using PORTA <0:3> for the LCD data port (connected to the MSB of
>the LCD data pins), and PORTB <4:6> for E, RS and R/^W. Obviously I am
>attempting to initialise the module for 4 bit operation. My question
>is: am I likely to have problems with PORT A, and should I stick
>everything on PORT B?
>
>This is a simple problem, I just need reassurance to keep trying.
>
>Andy (the other one)
>Lancaster, UK
>
>
> I am trying to get an Hitachi LM016L LCD module working with a PIC 84,
> with no success. I have had the module working with a STAMP, and I
> understand everything I need to do to setup and use the module, but it
> just ain't workin'.
>
> I am using PORTA <0:3> for the LCD data port (connected to the MSB of
> the LCD data pins), and PORTB <4:6> for E, RS and R/^W. Obviously I am
> attempting to initialise the module for 4 bit operation. My question
> is: am I likely to have problems with PORT A, and should I stick
> everything on PORT B?
I suspect that several others are right about timing. The following code
is from a standarized Embedded C library that I have been using for a
few years. I copied the following listing fragment from a project I did
for Circuit Cellar. It was compiled with MPC on a 16C74. The LCD display
was connected to Port D in this case. To save an I/O pin I generally
connect the R/^W to ground.
Walter Banks Byte Craft
#include <lcd4.c>
/********************************************************
* Device driver for 4 bit LCD interface using *
* Hitachi H2570 controllers. These displays are in *
* configurations from one line by 16 characters to *
* 4 lines by 40 characters *
* *
* No warranty is implied or given as to *
* their usability for any purpose. *
* *
* (c) Copyright 1990 *
* Byte Craft Limited *
* Waterloo, Ontario *
* Canada N2J 4E4 *
* (519) 888-6911 *
* *
* Walter Banks *
********************************************************/
0005 #define LCDdata PORTD /* Data output */
0006 #define LCD_RS PORTD.5 /* Register select bit */
0007 #define LCD_E PORTD.4 /* Clock bit */
/********************************************************
* wLCDdat - Write data word to LCD peripheral *
* Enter with data word in accumulator *
* Delay w120fS after data write *
********************************************************/
> I am using PORTA <0:3> for the LCD data port (connected to the MSB
> of the LCD data pins), and PORTB <4:6> for E, RS and R/^W.
> Obviously I am attempting to initialise the module for 4 bit
> operation. My question is: am I likely to have problems with PORT
> A, and should I stick everything on PORT B?
>
> This is a simple problem, I just need reassurance to keep trying.
>
> Andy (the other one)
Other Andy:
You should be fine with PORTA... Especially since you're not using
RA4. Your problem is undoubtedly timing-related; you probably need
to slow your initialization routine WAY down, and you should be using
the LCD's "BUSY" flag for all other operations.
Many thanks to all who have responded. I hope the information is
useful to other PICLIST readers.
Firstly can I thank all of those who advised me about the Murata 4MHz
ceramic resonator, it's working fine, and you _can_ connect the middle
pin to +5V to simplify board layout.
Secondly the LCD module...
I tried my module on the Stamp again, which showed me it was still
working properly, and I haven't damaged it (relief!). Back to the '84.
One problem I think I have is reading the busy flag, so I replaced that
section with a delay loop. Now I get some life from the display. I am
using portions of Microchips LCD application note, so my code sends 'M'
'i' 'c' 'r' 'o' 'c' 'h' 'i' 'p' to the 'Send_char' routine. Deep joy!
On the display is some text! Hang on, what does it say? 'Mogwognow'
I have worked out that the middle 2 bits of the lower nibble seem to be
always set to one, except for the first character (!). Could it be that
my SWAPF function is broken inside the CPU? I don't know, I shall
follow people's suggestions and slow it all down some more. More news
as it's made.
To anyone else who is using an LCD module with no success: Take heart,
and keep trying!
>Secondly the LCD module...
>
>I tried my module on the Stamp again, which showed me it was still
>working properly, and I haven't damaged it (relief!). Back to the '84.
>One problem I think I have is reading the busy flag, so I replaced that
>section with a delay loop. Now I get some life from the display. I am
>using portions of Microchips LCD application note, so my code sends 'M'
>'i' 'c' 'r' 'o' 'c' 'h' 'i' 'p' to the 'Send_char' routine. Deep joy!
>On the display is some text! Hang on, what does it say? 'Mogwognow'
>
>I have worked out that the middle 2 bits of the lower nibble seem to be
>always set to one, except for the first character (!). Could it be that
>my SWAPF function is broken inside the CPU? I don't know, I shall
>follow people's suggestions and slow it all down some more. More news
>as it's made.
>
>To anyone else who is using an LCD module with no success: Take heart,
>and keep trying!
>
>Andy (the other one)
(Parts of the text are a reprint of some postings in februari 1996
by Scott Dattalo and myself)
Assuming you are using AN587 to write your code:
This app.note has a bug in the code to *read from* any HD44780 based LCD
module (this affects ALL read operations).
A quote of Scott's comment (4-bit LCD interface):
The proper way to perform a read operation is to:
1) Clear RS (Register Select signal on LCD Module).
2) Set R/W (Read/Write signal on LCD Module). This will select the "read"
mode.
3) Set E (The enable bit on the LCD Module).
4) Read the 4 MSB's of the data bus on the LCD Module.
5) Clear E.
6) Set E.
7) Again, read 4 MSB's.
8) Clear E.
The two nibbles are then concatenated to form a byte. If you're reading the
busy bit, then bit 7 will reflect its state while bits 6 through 0 are either
the moste recent character or data RAM address.
The way AN587 does a read operation is:
1) Clear RS (Register Select signal on LCD Module).
2) Set R/W (Read/Write signal on LCD Module). This will select the "read"
mode.
3) Set E (The enable bit on the LCD Module).
4) Clear E.
5) Read the 4 MSB's of the data bus on the LCD Module.
6) Set E.
7) Clear E.
8) Again, read 4 MSB's.
In other words, AN587 reverses steps 4 and 5 and steps 7 and 8. The effect is
that the LCD module gets disabled before the data is read by the PIC.
(end quote)
This bug is in both the 4-bit and 8-bit code of AN587!
A correct version of an 8-bit interface (using the 16C84 and based on AN587),
the schematics and an example (see 4.1.4. Availability) can be found at: http://www.iaehv.nl/users/pouweha/lcd2.htm
The code on this page makes use the busy flag successfully.
You only need delay loops during LCD initialisation.
I had similar problems when interfacing an LCD to an 8051 controller. Make
sure you are reading/writing data on the correct clock edge and pay close
attention to the chips timing req'ts and the timing you are generating.
Good luck.
Do you know a good source for cheap 2x16 line LCD displays?
>Hi,
>
>Many thanks to all who have responded. I hope the information is
>useful to other PICLIST readers.
>
>Firstly can I thank all of those who advised me about the Murata 4MHz
>ceramic resonator, it's working fine, and you _can_ connect the middle
>pin to +5V to simplify board layout.
>
>Secondly the LCD module...
>
>I tried my module on the Stamp again, which showed me it was still
>working properly, and I haven't damaged it (relief!). Back to the '84.
>One problem I think I have is reading the busy flag, so I replaced that
>section with a delay loop. Now I get some life from the display. I am
>using portions of Microchips LCD application note, so my code sends 'M'
>'i' 'c' 'r' 'o' 'c' 'h' 'i' 'p' to the 'Send_char' routine. Deep joy!
>On the display is some text! Hang on, what does it say? 'Mogwognow'
>
>I have worked out that the middle 2 bits of the lower nibble seem to be
>always set to one, except for the first character (!). Could it be that
>my SWAPF function is broken inside the CPU? I don't know, I shall
>follow people's suggestions and slow it all down some more. More news
>as it's made.
>
>To anyone else who is using an LCD module with no success: Take heart,
>and keep trying!
>
>Andy (the other one)
well I have the LCD module working on the PIC, using delays between
characters rather than reading the busy flag. Thanks to Peer Ouwehand
for pointing out the error of trying to read the LCD data with pin E low
(which tristates the data bus!). I have looked through Hitachi's LCD
documentation, and this fact is not at all obvious. However I still
cannot successfully check for the busy flag. Most of the samples I have
seen simply tie R/^W low (always write), and use delays only. This
means you save one I/O pin, which might be satisfactory. I shall have
another go at reading from the LCD when I go home tonight (yes I _do_
have a home to go to).
Meanwhile I have successfully read and decoded data from a magnetic card
(a credit card in this case), and displayed it on my LCD. I currently
ignore parity on each character, and the final parity check, but this
doesn't matter for the purposes of experimentation. Later I shall check
parity, and then I shall attempt to decode the data with the card going
through backwards.
I hope all this drivel is of interest to someone. It is to me.
Many thanks to all correspondents so far.
Andy (the other one)
>shameless plug<
PS I shall be seeking employment in the Yorkshire area (north of England
for our overseas readers) from January '97. My main skills are
client/server development with VB, SQL Server and NT. As you can see I
dabble with low level assembly, and I also have experience in access
control and security.
--
---------------------------------------------------------------------
Andrew M Errington Tel: +44 1524 593678
Microcomputer Consultant Fax: +44 1524 844011
The Computer Centre Mobile (Orange): 0976 243931
Lancaster University a.erringtonspam_OUTlancaster.ac.uk
Lancaster LA1 4YW www.lancs.ac.uk/people/cpaame/cpaame.htm
---------------------------------------------------------------------
"A dog is not just for Christmas, there may be some left for
sandwiches on Boxing Day" - Vladimir Illich Ulyanov 1920
> well I have the LCD module working on the PIC, using delays
> between characters rather than reading the busy flag. .... I still
> cannot successfully check for the busy flag. Most of the samples I
> have seen simply tie R/^W low (always write), and use delays only.
> This means you save one I/O pin, which might be satisfactory.
Other Andy:
It also means that your LCD routines will be slower than necessary,
and it prevents you from reading the display (which can be very
useful with small microcontrollers like the PIC, since it relieves
you of the burden of storing a copy of the displayed data in the
microcontroller's RAM).
It also prevents you from using the display's otherwise-unused RAM as
slow-but-plentiful external RAM for the PIC.
You haven't given enough detail for me to really diagnose your
particular problem. Make sure, though, that you're reading all
EIGHT bits of data from the display... With your 4-bit interface,
you'll need to do TWO reads to get all the data.
Here's some sample code; it's written with the assumption that the 4
LCD data lines are tied to PORTD 4-7; SETPDI is equated to 1111xxxx
(binary) and SETPDO is equated to 0000xxxx (binary). "PAGE0" and
"PAGE1" are simple macros that set/clear the register-page-select
bit:
;
; WAIT FOR THE LCD'S "BUSY" FLAG TO CLEAR.
;
LCDREADY:
PAGE1 ;SWITCH TO DATA-SEGMENT 1.
MOVLW SETPDI ;MAKE THE LCD DATA BUS ALL
MOVWF TRISD ^ 080H ;INPUTS.
PAGE0 ;SWITCH BACK TO DATA-SEGMENT 0.
LCDWTLP:
BCF LCDRS ;SETUP TO READ THE BUSY FLAG.
BSF LCDRW ;
BSF LCDE ;CLOCK THE DATA IN.
NOP ;
MOVF PORTD,W ;GRAB THE HI-NIBBLE OF DATA
;(BIT 7 = BUSY).
BCF LCDE ;FINISH CLOCKING.
NOP ;WAIT A CYCLE.
BSF LCDE ;CLOCK THE LO-NIBBLE OUT (AND
NOP ;IGNORE IT).
BCF LCDE ;
ANDLW 10000000B ;MASK OFF ALL BUT THE BUSY FLAG.
BNZ LCDWTLP ;IF THE LCD'S STILL BUSY, LOOP
;BACK AND TRY AGAIN.
MOVLW 00001111B ;OTHERWISE, CLEAR THE DATA BUS.
ANDWF PORTD
PAGE1 ;SWITCH TO DATA-SEGMENT 1.
MOVLW SETPDO ;MAKE THE LCD DATA BUS ALL
MOVWF TRISD ^ 080H ;OUTPUTS.
PAGE0 ;SWITCH BACK TO DATA-SEGMENT 0.
RETURN ;RETURN.
For maximum efficiency, I generally call this routine just BEFORE
performing any operation on the LCD, rather than after.
> section with a delay loop. Now I get some life from the display. I am
> using portions of Microchips LCD application note, so my code sends 'M'
> 'i' 'c' 'r' 'o' 'c' 'h' 'i' 'p' to the 'Send_char' routine. Deep joy!
> On the display is some text! Hang on, what does it say? 'Mogwognow'
>
I recognice this ! Are you using 4bit mode ? When i used the
Microchipcode i discovered that they had forgotten one of the initial
delays so that my LCD was run in 8bit mode instead.
Look for all the LCD FAQ's awailable.
---
Sten Dahlgren CelsiusTech Systems ! "I'd rather have 39 Hp under my arm
S-175 88 Jaerfaella Sweden ! than one under my backside" RemoveMEsedaTakeThisOuTcelsiustech.se +46-8 58084430 ! join your nearest karting club now !!