This example is donated by Marc Simons.
If you have any questions/comments please send e-mail to msimons@IAEhv.nl.
Brief description:
Pins RB0, RB1 and RB2 are used for controlling AND driving text to the LCD display.
Most of the time the PIC's are sufficient enough for most applications, except when
it comes to more I/O. This simply cannot be expanded, except when you go to the BIG
GUYS like the PIC16C74 etc. where I have done some applications with too.
Observe the schematics: An PIC16C54 is the heart of the whole thing. It drives the
HEF4094 CMOS serial2parallel converter. This gives us the databus towards the LCD
display. Since the HEF4094 strobe is activated at the rising edge, and the LCD
display on the falling edge, these can be shared. So, on the rising edge the 4094
spits out it's new byte, and on the falling edge the LCD reads it in. By the way,
this concept cannot read out info from the LCD display. (Personal opinion: It is
useless anyway!) Now the hard part comes: How to derive 'text' from 'commands'??
The LCD has a pin for it: The RS-pin. When it is clear, commands are accepted. when
set, text is accepted. How is it solved?
Before I spit out a character to the HEF4094, I set the clock for 500uSec. Resistor
R1 will load capacitor C5. Then, I spit the text character towards the 4094 as soon as
possible. Therefore the capacitor simply does not have the time to discharge: The LCD
will accept it as text.
For commands it is the same, however, of course the other way around: The capacitor
must be discharged. T1 forms an emitter follower to buffer the R/C network. The reason
for this is that the LCD RS input is an TTL input, so without proper buffering it will
not work.
The code contains a few basic routines to handle the LCD display. The switch
that I added is purely for fun: To be able to toggle rotation of the text. I used an
16 characters / 2 lines LCD display from an old security keypad. (Go to a surplus
electronics store, they always have some!)
P.S. Any suggestions for good code from YOUR side are always welcome!
Best Regards from msimons@IAEhv.nl, your PIC Scueezer Weezel!
MSIMONS.ZIP (27,140 bytes) includes the schematics, source code and include file needed for this example.
I just came across the schematics for driving an LCD module with just 3 lines on
the PIC (http://home.iae.nl/users/pouweha/lcd/lcd.shtml). I just wanted to show
you an even simpler (and slightly cheaper) way:
- Replace the HEF4094D with a plain 8-bit shift register like the 74HC164 (it will
be slightly cheaper). It has no STR input, so the PIC's RB3 just connects to the
LCD module's EN signal.
- Connect RB1 to the RS signal of the LCD module, and to the two data inputs of
the 74HC164. After having shifted out a byte into the 74HC164, you can put the
state of the RS signal on this line.
You don't need a transistor and such, and the timing isn't critical.
You operate it like this:
With EN inactive, you shift out a byte into the shift register in the same way as
you did before. This byte defines what's on the DB0-7 signals. Of course, DB0-7
will wiggle while you're shifting, but the LCD will not care as long as EN is inactive.
Then, with EN still inactive, you put the state of RS on the PIC's RB1 pin, but you
don't toggle the clock line (RB0). Then, you pulse the EN line (RB2) to make the LCD
module accept the byte.
It should also be possible to use this technique with a hardware SPI port, which is
available in some PICs (or other controllers).
I intented to make a full emulation of the HD44780, like initialze, busy flag, set display etc., but I only managed to emulate simple commands, like Clear, Home, write data and other, because of short time that I had.
I don't have the schematic that I use for the LCD but I believe most of the schematic will do the trick.
In future maybe I try and make one up, based on the LCD that I have now.