PIC-Based Serial Enabled Character LCD Hookup Guide

Pages
Contributors: bboyho, MikeGrusin
Favorited Favorite 4

Firmware Overview

Baud Rate

Set the serial interface to: 9600 baud, 8 bits of data, 1 start bit, 1 stop bit, and no parity (9600,8,1,1,N). This can be changed or updated using the following command set. However, be aware that if you change the communication protocol, you may not be able to re-connect or control the device until your microcontroller's baud rate matches.

Data & Display Information

All settings are stored on onboard EEPROM and loaded during power up. To display data on the SerLCD and built-in serial enabled LCDs, you simply send ASCII-formatted characters using a serial interface which matches the communication protocol. This means that if you pass the ASCII character 'r' to the module, an 'r' will be displayed on the LCD at the next cursor position.

Configuration & Command Set

There are two reserved control characters used to control and configure various features on the LCD. The control characters are 0xFE and 0x7C. Sending a control character followed by a command will allow you to control the cursor, backlight, and other features on the SerialLCD. A complete table of commands are shown below in hexadecimal and decimal value in brackets. Either representation is acceptable when sending a control or command character. The HD44780 LCD controller is very common. The extended commands for this chip include but are not limited to those described in table. Please refer to the HD44780 datasheet for more information.

Control Character Command Character Description
0xFE [ 0d254 ] 0x01 [ 0d1 ] Clear Display
0x14 [ 0d20 ] Move Cursor Right 1 Space
0x10 [ 0d16 ] Move Cursor Left 1 Space
0x1C [ 0d28 ] Scroll Right 1 Space
0x18 [ 0d24 ] Scroll Left 1 Space
0x0C [ 0d12 ] Turn Display On / Hide Cursor
0x08 [ 0d8 ] Turn Display Off
0x0E [ 0d14 ] Underline Cursor On
0x0D [ 0d13 ] Blinking Cursor On
0x80 + n [ 0d128 + p ] Set Cursor Position,
where n is the hexadecimal position and
p is the decimal value of the position
0x7C [ 0d124 ] 0x03 [ 0d3 ] 20 Characters Wide
0x04 [ 0d4 ] 16 Characters Wide
0x05 [ 0d5 ] 4 Lines
0x06 [ 0d6 ] 2 Lines
0x09 [ 0d9 ] Turn Splash Screen On/Off
0x0A [ 0d10 ] Set Splash Screen
0x0B [ 0d11 ] Set to 2400 Baud
0x0C [ 0d12 ] Set 4800 Baud
0x0D [ 0d13 ] Set 9600 Baud (Default)
0x0E [ 0d14 ] Set 14400 Baud
0x0F [ 0d15 ] Set 19200 Baud
0x10 [ 0d16 ] Set 38400 Baud
0x80 [ 0d128 ] Backlight Off
0x9D [ 0d157 ] Backlight Full On
0x12 [ 0d18 ] Reset to Default Baud While
LCD's Splash Screen is Still Active

SerLCD Command Set

Clear Screen and Set Cursor Position

Clear display and set cursor position are the two commands that are used frequently. To clear the screen, send the control character 0xFE followed by 0x01. Clearing the screen resets the cursor position back to position 0 (i.e. the first character on the first line).

To set the active cursor position, send the control character 0xFE followed by 0x80 + n, where n is an offset in hexadecimal as described in the tables below. In this case, it would be easier to use the decimal value for setting the cursor position (0d128) with the viewable cursor position (p) and then send the value.

16 Character Displays
Line Number Viewable Cursor Positions (Decimal)
1 0-15
2 64-79
3 16-31
4 80-95
20 Character Displays
Line Number Viewable Cursor Positions (Decimal)
1 0-19
2 64-83
3 20-39
4 80-103

Example of Setting the Cursor Position

Say we want to the place a character on the third character position of the second line in a 16x2 character display. The cursor position is not what you would expect. Notice that the last character on line 2 jumps from 15 to 64 on the next line? To do this we need to:

  • Add 0x80 to the viewable cursor position as stated earlier. Since we are trying to add a hexadecimal value with a decimal, you would need to convert a value to the same representation. Since we know that 0x80 is also 0d128, we will just stick with decimal. Therefore, the third character on the second line in decimal is: 128 + 66 = 194.
  • Now that we know the position, send the command character 0xFE to tell the SerLCD you want to send a command followed by the number 194. If you are comfortable converting back to hexadecimal, you can also send 0xC2.
  • The cursor should now be sitting in the third position of the second line. Sending any other character will display on the LCD starting at this position.

Setting Up the LCD Size

The SerLCD backpack's firmware includes settings to interface for the following types of LCDs:

  • 16x2
  • 16x4
  • 20x2
  • 20x4

If you purchased the SerLCD backpack module by itself, you will have to configure the module to the type of LCD it is going to be, or is currently attached. To set the type of LCD the SerLCD module is attached to, transmit the control character 0x7C followed with either 0x03, 0x04, 0x05, or 0x06 as explained in the SerLCD Command Set above. These commands set the LCD character width and number of lines. These settings are used to correctly wrap the cursor to keep it within the viewable screen. The type of LCD is saved to EEPROM after each change.

If you purchased the built-in serial enabled LCD, it has already been configured to work with that specific LCD. You should not have to configure anything.

Changing the Baud Rate

The backpack and built-in serial enabled LCD defaults to 9600 baud, but they can be set to a variety of baud rates.

If the serial enabled LCD gets into an unknown state or you otherwise can't communicate with it, try sending a "CTRL-R" (0x12) character at 9600 baud while the splash screen is active (during the first 500 ms of boot-up) and the unit will reset to 9600 baud.

Backlight Brightness

The SerLCD v2.5 provides you with control of the backlight to one of 30 different brightness levels. To control the backlight, send the control character 0x7C followed by a number from 0x80 to 0x9D. Sending a 0x80 sets the backlight to off and 0x9D sets the backlight to fully on.

This is handy when power consumption of the unit must be minimized. By reducing the brightness, the overall backlight current consumption is reduced.

Splash Screen

The SerLCD and built-in serial enabled LCD displays a splash screen by default. This splash screen verifies that the unit is powered, working correctly, and that the connection to the LCD is correct. The splash screen is displayed for 500 ms during boot-up and may be turned off if desired.

PIC-Based Serial Enabled Character LCD Tutorial-04 Splash Screen

Setting Splash Screen

A new addition to the V2.5 firmware is the ability for the user to set their own splash screen (2 lines). To do this, just set the top 2 lines as you would like them to appear, send the control character 0x7C followed by "CTRL-J" (0x09) to save it to memory. To test, just cycle power.

Turning Splash Screen On/Off

To disable the splash screen, send the control character 0x7C to the unit followed by "CTRL-J" (0x0A). Every time this command is sent to the unit, the splash screen display option will toggle. If the splash screen is currently being displayed, sending the 0x7C and 0x0A characters will disable the splash screen during the next boot, and sending the 0x7C and 0x0A characters again will enable the splash screen.

Extended Command

When testing the extended LCD command 0x0C, the command used all three of the following commands:

  • Turn Visual Display On
  • Underline Cursor Off
  • Blinking Box Cursor Off

So if you had the cursor/blinking box on and turned the visual display off, the cursor/blinking box would not remain on after after issuing the 0xFE control and 0x0C command value to turn the screen back on.