Lab 4 - LCDs and the Hantronix LCD
LCD Basics
The most basic LCD unit is a bare device that consists of just a glass-sandwich LCD display and terminal connections. The LCD segments of the display require complex excitation waveforms to properly polarize the nematic crystals in the display. In principle, we could use our embedded microcontroller to directly drive a bare LCD device by supplying the necessary excitation waveforms to the LCD segments. This is a complicated design exercise, however, and consumes many of the microcontroller's resources.
Rather than driving a bare-LCD directly, a more common method is to use an LCD that has a built-in controller (also called a driver IC). An industry-standard controller is the HD44780-based controller, originally from Hitachi. You can think of the HD44780 LCD controller as a small microcontroller that runs the LCD display by supplying the necessary excitation waveforms to the LCD segments. The LCD device and controller are all housed in a single unit called an LCD module. To write to the LCD with our HCS12 microcontroller, we (the 68HCS12) have to communicate with the HD44780 controller so that it knows what characters we want to display and where we want to display them.
Hantronix HDM16216L-5 LCD/Dragon12 Specifics
The LCD module on the Dragon12 board is the Model Hantronix_LCD.pdf from Hantronix, and it is based on the HD44780-standard interface. This unit has two display lines, each line capable of displaying 16 characters, each with 5x7 dot-matrix character format. The Hantronix LCD is hardwired to Port K of the Dragon12 board (see the Dragon12 Schematic 4 for full details). When we want to display a character on the LCD, we write a character bit pattern to Port K, and then set up an enable pulse to latch the character data into the HD44780 controller. Once the character is correctly set up in the HD44780, it then takes care of the electrical details needed to display it on the LCD.
The LCD module is wired to the Dragon12 so that it uses 4-bit data transfers, the other pins of Port K being used for the RS (Register Select) and Enable bits. Using 4-bit transfers means we only need one port dedicated to the LCD. Had we used 8 bit data transfers, we would then need another port for the RS and Enable bits. However, using 4-bit data transfers complicates writes to the LCD. Since each character or command essentially involves sending one byte of data to the LCD controller, we have to do two writes for each transfer, first sending the 4 msb (most significant bits) and then the 4 lsb (least significant bits) of each data byte. Each of the 4-bit patterns (msb or lsb) is referred to as a nibble, there being two nibbles in each byte. If a byte has the bit pattern %abcdefgh, then the 4-msb nibble of the byte is %abcd, and the 4-lsb nibble is %efgh.
There are five main types of lines/pins for the HD44780 LCD Controller:
1. The RS pin. RS stands for 'Register Select'. When RS=0, we are sending a command to the controller. When RS=1 we are sending data to the controller. The RS pin is tied to PK0 (Port K, bit 0).
2. The RW pin (Read-Write). The RW pin is 1 when we read data from the LCD, and 0 when we write data to the LCD. The Dragon12 is set up so that the RW pin of the LCD controller is tied to ground, meaning we can only do writes to the LCD. This is not a problem since we rarely need to read data from an LCD.
3. The EN 'Enable' pin. We must create an enable pulse to latch data into the LCD controller. The EN pin is tied to PK1. To create an enable pulse, we raise the PK1 pin to high for > 230 nsec, and then set it back to low.
4. The data lines DB7-DB4 contain the data we actually want to send to the LCD controller. Since we use 4-bit transfers to send a command or data byte, we must do two sequential writes to these pins (send the 4-msb nibble first, then the 4-lsb nibble second). The DB7-DB4 lines are attached to pins PK5 - PK2, where PK5 is the most significant bit of a nibble.
5. The power supply pins and anode/cathode intensity pins. These are prewired on the Dragon12; you can add an LCD intensity adjustment using a trimmer pot on VR1 if desired.
In addition to the essential technical data found in the in the Hantronix LCD specs, the Motorola application note AN1774 also provides information about interfacing an HD44780 LCD to an HC12.
For further information, go to the lcd demo, which presents a simple Code Warrior project for writing to the Dragon12 LCD.
What to Hand In
At the next lab, hand in the commented code from your program from Step 2 of the Demo. All programs must have "header" comments (the main comments that lead a program) that include your: (1) name; (2) date; (3) class (eg, UTEP EE3176);(4) the name of the program (eg, "lab4.asm"); and (5) what the program does. In addition, there should be comments throughout your program that describe what the main sections of code do. The rule of thumb is that you should be able to look at your code one year from now and figure out what it is doing by reading the comments and code.