2-Wire PIC LCD Interface by Myke Predko
Build your own "2-Wire LCD Interface" using the PIC16C84 microcontroller
A Special "Thanks" to Myke Predko for submitting the following project/article. About the Author Myke Predko is the author of "Programming and Customizing the PIC Microcontroller", the "Handbook of Microcontrollers" and "Programming and Customizing the 8051 Microcontroller" as well as the soon to be released "PC PhD" and "PC Interfacing Pocketbook" which are all published by McGraw-Hill. As well as writing books on electronics and programming, Myke works for Celestica, Inc. in the area of New Products Test Engineering. His wife, Patience, and he have three children, Joel, Elliot and Marya. 2-Wire LCD Interface for the PICMicro Alphanumeric LCD displays have become very popular for microcontroller applications because they can add a lot to a project in a variety of different ways. A text message giving the user instructions as well as feedback can make the application seem much more "professional" and easy to use. I like to use LCD's to help debug applications, with breakpoints set to display variable and I/O conditions and they are a lot cheaper than using a microcontroller emulator. To top it off, surplus LCD's can be found for a dollar or less. The most popular LCD interface is the Hitachi 44780 based LCD controller chip which provides a fairly easy to work with interface and low power consumption. The major drawback of the interface is the perceived complexity of working with the interface. This perception has been promoted by the lack of good (i.e. well translated) and accurate datasheets and web site information. This has been largely mitigated by the availability of a new data sheet from Hitachi; (available at here and user sites (such as my own at LCD Page with accurate information and example code that can be downloaded. Often the biggest stumbling block to using alphanumeric LCD displays is the number of pins required to control them. For the Hitachi 44780, twelve pins are required from the microcontroller to interface to the display for it to work in eight bit mode. For many smaller microcontrollers, twelve pins are not available or will be better served in the application. To be fair, this can be reduced to six by using the 44780's "Four Bit" mode, but this can still be more than acceptable for most applications. In this case, different approaches have to be made. The most popular one is to use synchronous serial data (requiring a "clock" and "data") pin to load a serial-in/parallel-out shift register with the data bits and "R/S" pin information. The "E" Strobe Pin is driven directly by the microcontroller to latch in the data from the LCD. This is shown in the diagram below:
1 von 4
I used the same two transistor and two resistor circuit that I used for the 89C2051 emulator in "Programming and Customizing the 8051 Microcontroller". the diode will not cause any current flow from the connection at the "E" pin to the shift register. The "AND" circuit could be a TTL two input AND gate (such as a 7408). the "E" Strobe can be implemented without resorting to a separate line for the function.rentron. A schematic of the circuit is shown below.2011 10:12
. When the shift register bit is low. even though the diode is pulling the "E" pin low.12. When I originally created this circuit.
The operation of the resistor/diode "AND" gate may not be immediately obvious. the voltage will still be high. This is done by first shifting in six "0"s to make sure that while the correct data is being loaded into the shift register. then the current through the resistor will be limited to 5 mA (for a 5 Volt logic application). the "E" pin will be high.com/Myke1. When the shift register bit is low and the data bit is high. The resistor from "Data" to the "E" pin is a current limiting resistor. I saw this "AND" equivalent circuit in an old copy of "Electronics Now" and found that it worked well in this application. if you have an extra one available for your application. By combining the shift register's "Data Line" with the most significant bit of the shift register. The 1 K resistor and diode act as an "AND" gate. the diode pulls the connection to the "E" pin low. When the shift register bit is high. no "high" voltage level is passed to the "E" pin of the LCD. At the "Data" side of the resistor. the data can be shifted in.2-Wire PIC LCD Interface by Myke Predko
http://www. When both the "Data" line and the shift register bit are high. Once this is done. The diagram below shows how the shift register is initially cleared and then loaded with the data to be strobed (using "E") into the LCD:
2 von 4
07. To load the shift register.htm
The project presented in this article is an enhancement of this circuit. it first has to be cleared to ensure that the "E" will not be strobed to the LCD inadvertently.
#### . "2wirelcd. #### . #### . If this is not possible in your application. Next. NybbleOut2 movwf swapf movlw movwf . The file is written to be used with the "MPASM" assembler built into Microchip's "MPLAB". "NybbleOut" first drops the "Data" line and then strobes the "Clock" bit six times to clear the shift register. respectively. I "defined" them to allow you to use virtually any pins in your PICMicro application. I have marked changed lines with "####' in comments.htm
The application code.Now. I used Carry for this purpose because in this application I used RA0 and RA1 as the output pins and to simplify the operation of the code. The important difference between this code and a straight 4-bit LCD output is the "NybbleOut" subroutine. I wrote the code with the idea that it should be easily portable to any low-end or mid-range PICMicro without modification. then "NybbleOut" should be changed to the following code. followed by the "R/S" pin value.12.2011 10:12
. #### . a "1" is strobed in. Setup to Output to the High Part of the Byte 6 . I say "virtually any" because PORTA pin 4 (also known as "RA4") is of "open drain" configuration and cannot source a positive voltage. Shift out the Data with the "RS" Bit movwf Dlay bsf Data . which is called twice by each of the "SendCHAR" and "SendINS" subroutines (which send characters and instructions.com/Myke1.Shift the Next Bit into the Carry Flag decfsz Dlay goto NO2Loop2
3 von 4
07.Clear the Data Bit (which is the Clock) btfsc STATUS. Clear the Shift Register Dlay
NO2Loop1 ClockStrobe decfsz Dlay goto NO2Loop1 movlw 5 .2-Wire PIC LCD Interface by Myke Predko
http://www. Send a Nybble to the LCD NOTemp . Put out the Gate Bit ClockStrobe NO2Loop2 bcf Data . to the LCD).asm" is an assembler source file written for the PIC16C84. I shift PORTA with Carry loaded with the "Data" Pin Value. Shift it Out bsf Data ClockStrobe rlf NOTemp . which is stored in the PICMicro's "Carry" flag. Save the Nybble to Shift Out NOTemp . The code itself is a very straightforward example of writing a 4-bit LCD application which displays the string "Hello" on the LCD display.rentron. C .If the Bit to be output is a "1". For the two I/O pins ("Data" and "Clock").
The information contained here cannot be reproduced without the author's permission. Program the PIC in simple BASIC using the PicBasic Compiler.2011 10:12
. Different hardware may result in different results. Click HERE to download the code for this project.com /PicBasic2.2-Wire PIC LCD Interface by Myke Predko
http://www. Strobe out the LCD Data
The only point to notice with this code is that the "E" strobe will become active on the last bit if the least significant data bit is high.rentron. I have tested the circuit and code that I have presented here and I am confident that it works on the hardware that I have used. If you have any problems.rentron. but I haven't found it to be a problem when I've built this circuit. This lack of "settling time" before "E" is active does violate the "true" 44780 specification.htm
. please send me an email and I'll see what I can do to point out where the problem is.12.htm
4 von 4
07. Good luck with building this circuit.com/Myke1. Visit: http://www.
Copyright and Warranty Statement This article is presented on an "AS IS" basis.