The Liquid Crystal Display (LCD) is a display on the MB5 that is capable of displaying 4 lines of 20 characters. This document describes the operation of the particular LCD used on the MB5. As one might expect, to display a sequence of characters, a character code must be written to the LCD. The basic character set is the standard ASCII encoding. There are also some additional characters defined. The complete character set that may displayed is specified in a PDF file. The LCD has other capabilities, such as a way to position the cursor at any location on the display. How this is done is described in more detail below.
In broad terms, the LCD is similar to other I/O devices. It has a command register, status register and data register. The LCD cannot interrupt the CPU, so polling must be used to check when the LCD is ready to perform operations. In the documentation for the LCD, the term command register isn't used. Instead, the commands sent to the LCD are called instructions that written to an instruction register.
The LCD is controlled by writing a byte to location $600001. Since the LCD takes some time to perform the function specified by an instruction, a control program must wait until the LCD is ready before sending another instruction or character to the LCD. To check whether the LCD is busy, a program must read the status register. Since an instruction is only written to the LCD and the status register is only read, the instruction register and status register are mapped to the same location (namely $600001).
While the LCD accepts eight instructions, most of the functionality can be achieved with only four of them. The 4 most "useful" instructions are described first.
| Clear Display |
|
| Return Home |
|
| Display on/off |
|
| Set Address |
|
Other commands include:
| Entry Mode |
|
| Cursor Shift |
|
Function Set and Set CGRAM Address are two more instructions that are not needed for most applications in this course. The Function Set instruction is used to initialze the display and there is no reason to ever execute this command. The Set CGRAM Address is used to program 8 or 4 custom characters. More details on how this may be done can be found in the data sheet for the LCD.
Before the LCD can be used, it must be initialized. The initialization sequence is somewhat complex and incorrectly specified in the LCD documentation. Fortunately, Moose Load has initialized the LCD. In fact, each time the reset button on the MB5 is pressed, the LCD (and the other devices) are initialized. So, if your program sends an illegal sequence of operations to the LCD and puts it into an unknown state, pressing the reset button will get the LCD back into a known state.
When the "clear display" instruction is executed, the cursor is placed back at "address 0" of the display. This is the upper left-hand corner of the display. The 80 locations on the display are not quite sequentially numbered. The addresses of the locations, in hexadecimal are as follows:
| 00 | 01 | 02 | 03 | 04 | 05 | 06 | 07 | 08 | 09 | 0A | 0B | 0C | 0D | 0E | 0F | 10 | 11 | 12 | 13 |
| 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 4A | 4B | 4C | 4D | 4E | 4F | 50 | 51 | 52 | 53 |
| 14 | 15 | 16 | 17 | 18 | 19 | 1A | 1B | 1C | 1D | 1E | 1F | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 54 | 55 | 56 | 57 | 58 | 59 | 5A | 5B | 5C | 5D | 5E | 5F | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 |
If you want to get the effect of the writing to sequential lines, the program writing to the LCD must keep track of the cursor position and then occasionally use the Set DDRAM address instruction to reposition the cursor.
The status register is accessed by reading for location $600001. The format of the status register is:
| Status Register |
|
The data register is at location $600003. The ASCII character code of the character to be displayed is written to this location.
| Instructor | Revision 1.3 (2004/04/06 02:46:45) |