LCD Details

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.

LCD Instructions

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
0 0 0 0 0 0 0 1
Clear Display clears the display and sets the cursor to the upper left-hand corner of the display.

Return Home
0 0 0 0 0 0 1 -
Return Home sends the cursor to the upper left-hand corner of the display. However, the display is not cleared. The "-" in the table indicates that it does not matter if the bit is a 1 or a 0.

Display on/off
0 0 0 0 1 D C B
Display on/off control controls the display and cursor. With D = 1, the display is on, D = 0, the display is off. The contents of the display are not changed. With C = 1, the cursor is displayed, C = 0, the cursor is turned off. When turned off, the cursor position is updated as characters are written to the screen. The B = 1 is for a blinking cursor, B = 0 turns off the blinking. (MooseLoad, initializes the cursor to be on and blinking.)

Set Address
1 A A A A A A A
Set DDRAM Address positions the cursor. The term DDRAM refers to the memory that stores the characters being displayed. The "A" bits are specify one of the locations of the display. Your code must execute this instruction at least once before sending a character to the display. So, for example, writing an $80 to the instruction register will also move the cursor to the upper left-hand corner of the display. It also has the side-effect of selecting the memory that stores the predefined ASCII character set.

Other commands include:

Entry Mode
0 0 0 0 0 1 I/D S
Entry mode set sets how the cursor will move as characters are entered. The I/D field is for increment (1) and decrement (0). (Moose Load sets this field to increment.) The S field should normally be set to 0. A 1 in this field cause the entire display to shift. More about this function may be found in the data sheet for the LCD.

Cursor Shift
0 0 0 1 S/C R/L - -
Cursor or display shift moves the cursor to the left or right, without having to write a character to the display. The S/C field determines whether the cursor or display is shifted, 0 for the cursor, 1 for the display. The R/L field is for a shift right (1) and left (0). The "-" indicates that it does not matter if the value is a 0 or a 1.

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.

Initialization

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.

LCD Addressing

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:

000102030405060708090A0B0C0D0E0F10111213
404142434445464748494A4B4C4D4E4F50515253
1415161718191A1B1C1D1E1F2021222324252627
5455565758595A5B5C5D5E5F6061626364656667
When the LCD is initialized, it is placed in a mode so that after a character is written, the cursor moves one position to the right. Actually the address pointer is incremented by one. When a character is written to the last position of the first line, the address pointer is incremented by one, and the cursor moves to the third line. At the end of the third line, the cursor moves to the second line. And then finally to the fourth line.

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.

Status and Data Registers

The status register is accessed by reading for location $600001. The format of the status register is:

Status Register
BF AC AC AC AC AC AC AC
BF stands for Busy Flag. When BF is 1, the LCD is busy and no instruction should be written to the LCD. The 7 bits labelled AC are the current address counter value. Or in other words, this is the current cursor position. When using the LCD, a program must busy-wait on the value of the BF.

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)