Prerequisite Modules
- Development Software Suite
- Version Control
- Embedded C and IAR Primer
- Firmware System
- LED Basic
- Button Interface
Character LCDs are very common and quite easy to use in an embedded system. The majority of ASCII displays use the HD44780 standard driver from Hitachi so regardless of the vendor the interface is roughly the same. The datasheet for the ASCII LCD used on the development board is HERE. The driver supports the HD44780 instruction set and has some other features, too. The data interface is I²C plus control of the RGB backlight elements.

The displayable area of the screen is 20 characters x 2 lines, though the LCD RAM holds 40 characters per line so it can be used for scrolling longer messages quite easily. Each character has a 1-byte address. Nmemonics are defined in (brackets) for the main locations:


API Description
The driver manages all of the communications with the LCD and abstracts the interface to three basic function calls. There are no unique types required.
Public Functions
The following functions may be used by any application in the system.
- void LCDMessage(u8 u8Address_, u8 *u8Message_) – Sends a text message to the LCD to be printed at the address specified.
- void LCDClearChars(u8 u8Address_, u8 u8CharactersToClear_) – Clears a number of chars starting from the address specified. This function does not span rows.
- void LCDCommand(u8 u8Command_) – Queues a command code to be sent to the LCD. The full command list is in the header file, but common commands are shown below including LCD_DISPLAY_CMD which is a compound command consisting of a base value that is ORed with other options:

Examples
Checkout the latest Master branch and try the following examples in UserApp1Initialize(). You can single-step through these since they are in the Initialize section of the firmware because the LCD task is forced to run during this time and complete each command. LCD commands and data in the main loop normally must wait for a few iterations for the messages to be sent out.
Write “Hello world!” to Line 1. What happens?

Clear “ASC” from the screen.

Send the CLEAR command to remove the rest of the characters.


Exercise
In this exercise you will write your name to LINE 1, add button labels, and turn on a blinking cursor. All of this code will be done in UserApp1Initialize() since it only needs to run once. You can comment out the other code that you have written so far in this module EXCEPT for the last line with LcdCommand(LCD_CLEAR_CMD) since this exercise needs to clear the screen to start.
Add UserApp_au8MyName[] in the Global variable space so it accessible to any function in the task. Initialize it with your name (maximum 20 characters).

Use LcdMessage() to write your name starting at the top left character position. Then use four individual calls to LcdMessage() to add button labels ‘0’, ‘1’, ‘2’ and ‘3’. Be sure to determine the correct address for each label so the digit is directly above the button.

Build and test the code. You do not have to set breakpoints unless you want to see each action as it occurs. Setting up the LCD in UserApp1Initialize() like this would be typical for an application so the screen is ready to go once the main loop is running.

Now move to UserApp1SM_Idle() and use LcdCommand() to toggle the cursor blinking mode when BUTTON0 is pressed. The command argument must be built up by OR-ing the options you want, including keeping the display on.

Build and run the code and try turning on the cursor with BUTTON0. If you have followed these steps exactly then you should NOT see the cursor. Why?
Add the following line at the end of UserApp1Initialize(), rebuild the code and test again. Now you should see the cursor.

