Build your own “2-Wire LCD Interface” using the PIC16C84 microcontroller

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.

Build your own 2-Wire LCD Interface using the PIC16C84 microcontrollerThis 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.

A popular solution that only requires one pin from the microcontroller to the LCD is the use of β€œSerial LCD Interfaces” (such as Wirz Electronics β€œSLI-OEM” – http://www.wirz.com/) which convert β€œNRZ” serial data (either CMOS/TTL or RS-232 voltage levels) to the data and signals necessary for the Hitachi 44780 controllers.

Many of these products (such as the SLI-OEM) are excellent and can provide useful product interface and debugging information. The only drawback to them is the need for properly timed NRZ serial data which may be difficult or even impossible to guarantee in some 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:

The project presented in this article is an enhancement of this circuit. By combining the shift register’s β€œData Line” with the most significant bit of the shift register, the β€œE” Strobe can be implemented without resorting to a separate line for the function. The 1 K resistor and diode act as an β€œAND” gate. A schematic of the circuit is shown below.

The operation of the resistor/diode β€œAND” gate may not be immediately obvious. When the shift register bit is low, the diode pulls the connection to the β€œE” pin low. When the shift register bit is high, the diode will not cause any current flow from the connection at the β€œE” pin to the shift register. The resistor from β€œData” to the β€œE” pin is a current limiting resistor. When the shift register bit is low and the data bit is high, then the current through the resistor will be limited to 5 mA (for a 5 Volt logic application). At the β€œData” side of the resistor, the voltage will still be high, even though the diode is pulling the β€œE” pin low.

When both the β€œData” line and the shift register bit are high, the β€œE” pin will be high. The β€œAND” circuit could be a TTL two input AND gate (such as a 7408), if you have an extra one available for your application. When I originally created this circuit, I used the same two transistor and two resistor circuit that I used for the 89C2051 emulator in β€œProgramming and Customizing the 8051 Microcontroller”. I saw this β€œAND” equivalent circuit in an old copy of β€œElectronics Now” and found that it worked well in this application.

To load the shift register, it first has to be cleared to ensure that the β€œE” will not be strobed to the LCD inadvertently. 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, no β€œhigh” voltage level is passed to the β€œE” pin of the LCD.

 Build your own 2-Wire LCD Interface using the PIC16C84 microcontroller SchematicOnce this is done, the data can be shifted in. 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:

The application code, β€œ2wirelcd.asm” is an assembler source file written for the PIC16C84. The file is written to be used with the β€œMPASM” assembler built into Microchip’s β€œMPLAB”. I wrote the code with the idea that it should be easily portable to any low-end or mid-range PICMicro without modification.

For the two I/O pins (β€œData” and β€œClock”), I β€œdefined” them to allow you to use virtually any pins in your PICMicro application. I say β€œvirtually any” because PORTA pin 4 (also known as β€œRA4”) is of β€œopen drain” configuration and cannot source a positive voltage. The code itself is a very straightforward example of writing a 4-bit LCD application which displays the string β€œHello” on the LCD display. The important difference between this code and a straight 4-bit LCD output is the β€œNybbleOut” subroutine, which is called twice by each of the β€œSendCHAR” and β€œSendINS” subroutines (which send characters and instructions, respectively, to the LCD).

 

For more detail: Build your own 2-Wire LCD Interface using the PIC16C84 microcontroller

 


About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.