[MOT20x1.ASM] (link to file)
Sample program and schematics appear in the application note AN587 in the Microchip Embedded Control Handbook for 1994/95.
A program for driving an LCD with a PIC appears in the /pub/picsrc directory of the Parallax FTP site ftp://ftp.parallaxinc.com It is written for the Parallax 8051-lookalike assembler.
Sample program and a schematic appear in the "PIC16C84 sub-page" of Peer Ouwehand's "How to control HD44780-based Character-LCD" at http://www.iaehv.nl/users/pouweha/lcd.htm programmed in PIC assembly language.
A way to save even more I/O space is to use a serial interface, requiring just 3 digital output port pins. It uses a shift register with serial-in, parallel-out, and output latch. This setup allows the convenient coding of a parallel interface (just writing the data to the USART transmit buffer) and low pin count of a serial interface.
________________ __________
_____ | 74LS595 | | |
| | QA|-------|DB4 |
|--------|>ser. clock QB|-------|DB5 |
CPU | | QC|-------|DB6 |
OUT |--------|>latch QD|-------|DB7 |
PORT | | QE|-------|RS |
|--------|serial data QF|-------|E |
_____| | QG|--nc | |
10Kohm | QH|--nc | |
pullup | | | |
+5V--^^^---|\Reset | .---|R/W |
.-----|\OE | | |__________|
| |________________| |
GND GND
</pre>
Note: 74LS595 can be substituted by 74LS164 + 74LS244.
The Amateur Robitics column in June '94 Nuts & Volts demonstrated how to use this technique with the 68hc11's SPI port, using MOSI, SCK, and /SS. This would be especially handy with a nonnetworked 68HC11-based Miniboard single-board computer, which has MOSI, MISO, SCK, and /SS conveniently routed to the top left corner where resistor pack 2 goes. The experimenter could put the contrast potentiometer and latch on a daughterboard mounted underneath the LCD module.
An alternative with a less expensive shift register has the low pincount advantage, but requires bit manipulation of port pins:
-----+ +----------+
| | |
|---------------------------------|E |
| ________________ | |
| | 74LS164 | | |
| | QA|-------|DB4 |
|--------|>ser. clock QB|-------|DB5 |
CPU | | QC|-------|DB6 |
OUT | | QD|-------|DB7 |
PORT | | QE|-------|RS |
|--------|serial data QF|--nc | |
_____| | QG|--nc | |
10Kohm | QH|--nc | |
pullup | | | |
+5V--^^^---|\Clear | .---|R/W |
| | | +----------+
|________________| |
GND
Save another I/O line with this idea from Robert Rolf:
"On your SPI example, you can free up the latch line by using the clock line with a diode, pullup, and capacitor. I use the SPI in normally high mode, rising clock for data bits. 10K pullup, 10nF to GND, and the clock through diode pulls it low. After all the bits are shifted in, the RC times-out, and clocks [latches] the '595."
The LCD Serial Backpack from Scott Edwards Electronics lets you communicate with a one- or two-line LCD over an asynchronous serial port at 2400 or 9600 bps. Both TTL and RS-232 voltage levels are supported. The Backpack is a tiny daughterboard with an onboard processor, fitting neatly behind any LCD module, having solder pads for both 2x7 and 1x14 hookups. Backpacks are sold alone or with a variety of LCDs. Call (520) 459-4802.
NEC UPD44780 LCD Display Controller Pinouts:
PIN DEFINITION === ========== 1 SEG 22 2 SEG 21 3 SEG 20 4 SEG 19 666665555555555444444444 5 SEG 18 432109876543210987654321 6 SEG 17 65 40 7 SEG 16 66 39 8 SEG 15 67 38 9 SEG 14 68 37 10 SEG 13 69 36 11 SEG 12 70 35 12 SEG 11 71 34 13 SEG 10 72 33 14 SEG 9 73 UPD44780 TOP 32 15 SEG 8 74 31 16 SEG 7 75 30 17 SEG 6 76 29 18 SEG 5 77 28 19 SEG 4 78 NOTCHED CORNER 27 20 SEG 3 79 /AND POSSIBLE DOT 26 21 SEG 2 80 o 25 22 SEG 1 \ 111111111122222 23 GND 123456789012345678901234 24 OSC 1 25 OSC 2 26 V1 27 V2 28 V3 29 V4 30 V5 31 CL 1 32 CL 2 33 VCC 34 M - 35 D - 36 RS - Reset, assert once 37 R/W* - Hold low for write operation 38 E - Clock low to latch data. 39 DB 0 - The data bus 40 DB 1 - 41 DB 2 - 42 DB 3 - 43 DB 4 - 44 DB 5 - 45 DB 6 - 46 DB 7 - 47 COM 1 48 COM 2 49 COM 3 50 COM 4 51 COM 5 52 COM 6 53 COM 7 54 COM 8 55 COM 9 56 COM 10 57 COM 11 58 COM 12 59 COM 13 60 COM 14 61 COM 15 62 COM 16 63 SEG 40 64 SEG 39 65 SEG 38 66 SEG 37 67 SEG 36 68 SEG 35 69 SEG 34 70 SEG 33 71 SEG 32 72 SEG 31 73 SEG 30 74 SEG 29 75 SEG 28 76 SEG 27 77 SEG 26 78 SEG 25 79 SEG 24 80 SEG 23 </pre>
(Section 6 by Frank Hausman)