Difference between revisions of "Lcd protocol 1.6"

From BitWizard Wiki
Jump to navigation Jump to search
Line 40: Line 40:
|-
|-
| 0x14 || reinit LCD.
| 0x14 || reinit LCD.
|-
| 0x20 || set the number of lines. Should not be necessary in most circumstances.
|-
| 0x21 || set the number of characters per line. Should not be necessary in most circumstances.
|-
|-
| 0xf0 || change address. Requires a write to 0xf1 and 0xf2 first.
| 0xf0 || change address. Requires a write to 0xf1 and 0xf2 first.

Revision as of 16:41, 4 July 2013

This document describes the protocol specific to the LCD modules I2C_LCD, and SPI_LCD. Each can be configured with a 20x4 or a 16x2 display.

Addresses on the SPI and I2C bus are 7 bits wide. The lower bit specifies if the transaction is to be a read or a write. Write transactions have the lower bit cleared (0), read transactions have the lower bit set (1).

Each transaction on the bus starts with the address of the board. The spi_lcd board will ignore any transactions on the SPI bus that do not start with its own address, similar to the i2c bus version.

After the address a single byte indicates the "port" on the board that the data is written to. The software can thus define 256 ports on each board.

Also see the general SPI protocol and SPI versus I2C protocols


write ports

Some ports just set a single value. So writing more than one byte to such a port is redundant. Other ports are logically a stream of bytes. So writing more than one byte is encouraged.

The spi_lcd board defines several ports.

port function implemented on
0x00 display data.
0x01 write data as command to LCD.
0x08 write up to 20 bytes for startupmessage line 1. 1.6 and higher
0x09 write up to 20 bytes for startupmessage line 2. 1.6 and higher
0x0a write up to 20 bytes for startupmessage line 3. 1.6 and higher
0x0b write up to 20 bytes for startupmessage line 4. 1.6 and higher
0x10 any data clears the screen.
0x11 move the cursor to line l, position p.
l is the top 3 bits
p is the bottom 5 bits of the data.
0x12 set contrast.
0x13 set backlight.
0x14 reinit LCD.
0x20 set the number of lines. Should not be necessary in most circumstances.
0x21 set the number of characters per line. Should not be necessary in most circumstances.
0xf0 change address. Requires a write to 0xf1 and 0xf2 first.
0xf1 write 0x55 here to start unlocking the change address register.
0xf0 write 0xaa here to unlock the change address register.

read ports

The spi_lcd board supports two read ports:

port function
0x01 identification string. (terminated with 0).
0x02 read eeprom (serial number).

startup message

The startup message is stored in eeprom. It will be shown in the future when you power up your display.

The space reserved for the messages is 20 characters per line. Writing each character to eeprom takes some time. This means that after sending a line of data, it is best to wait 100ms before sending the next.

Because of the construction of the software inside the LCD, a termination marker is set just past the last byte sent. So if you send "ABC", the eeprom will contain: (shown in hex) 41 42 43 ff. This means that for 20 characters 21 bytes are used. So if you need a full line, you will overwrite the start of the next line with the end marker.

So each time you provide a 20 character startup line, you will need to update the following line as well.

To clear the startup message send a single "0xff". For each line you care about. The current version will show the default message if the first character of the first line is 0xff. Later versions might decide on a per-line basis.

examples

read identification

read the identification string of the board. ('spi_lcd 1.3').

data sent data recieved explanation
0x83 xx select destination with address 0x82 for READ.
0x01 xx identify
xx 0x73 's'
xx 0x70 'p'
xx 0x69 'i'
xx ... etc.


Send text to display

Display the string "Hello World!" (only the first 5 bytes of the string shown).

data sent data recieved explanation
0x82 xx select destination with address 0x82 for WRITE
0x00 xx datastream
0x48 xx 'H'
0x65 xx 'e'
0x6c xx 'l'
0x6c xx 'l'
0x6f xx 'o'
xx ... etc.

set cursor position

move to line 1, character 5:

data sent data recieved explanation
0x82 xx select destination with address 0x82 for WRITE
0x11 xx port 0x11 = set cursor position.
0x25 xx 0x25 = 001 00101 = line 1 position 5.

define custom character

A usage of the 0x01 port is to define custom characters. Here in a less verbose format:

82 01 40                        # set CGRAM char 0 line 0 
82 00 01 02 04 08 10 10 10      # define character 0 (7 bytes)
82 11 00                        # move to home position
82 00 41 42 0                   # print characters A B and our newly defined character.

Use 0x48 instead of 0x40 to define character number "1".

the character data "01 02 04 08 10 10 10" is just an example. 11 11 11 1f 11 11 11 is the uppercase "H" that I have on my display right now.

the last two lines are just a example of how to get back to "display" mode. It works for me I don't have the inclination to find other ways.

scrolling the display

Send

82 01 18

to scroll the display one place left. Use 0x1c instead of 0x18 to scroll right. Replace 0x82 by the address of your display (e.g. 0x94 if you have an rpi_ui at the default address).