Syntax: LCDOUT Pin, Command, [OutputData]
Send data to an LCD display.
BS2p, BS2pe, and BS2px | |
Values for Pin | 0, 1, 8, or 9 |
I/O pin arrangement when Pin is 0 or 1 |
0 or 1 (depending on Pin) : LCD Enable (E) pin 2 : LCD Read/Write (R/W) pin 3 : LCD Register Select (RS) pin 4 - 7 : LCD Data Bus (DB4 - DB7, respectively) pins |
I/O pin arrangement when Pin is 8 or 9 |
8 or 9 (depending on Pin) : LCD Enable (E) pin 10 : LCD Read/Write (R/W) pin 11 : LCD Register Select (RS) pin 12 - 15 : LCD Data Bus (DB4 - DB7, respectively) pins |
Related Commands |
The three LCD commands (LCDCMD, LCDIN and LCDOUT) allow the BS2p, BS2pe, or BS2pe to interface directly to standard LCD displays that feature a Hitachi 44780 controller (part #HD44780A). This includes many 1 x 16, 2 x 16, and 4 x 20 character LCD displays. Note that LCDCMD, LCDIN and LCDOUT use a 4-bit interface to the LCD which requires a specific initialization sequence before LCDIN and LCDOUT can be used (see LCDCMD for initialization details).
The LCDOUT command is used to send one instruction followed by at least one data byte to the LCD. The data that is output is written to the LCD's Character Generator RAM (CGRAM) or Display Data RAM (DDRAM). The following is an example of the LCDOUT command:
LCDOUT 1, 1, ["Hello World!"]
The preceding example will clear the LCD screen and then send "Hello World!" to the screen. The first argument (1) is the starting I/O pin number and the second argument (also 1) is the LCD's instruction for Clear Screen.
The LCDOUT command actually uses more than just the I/O pin specified by the Pin argument. The LCDOUT command requires seven I/O pins. This is because the standard LCD displays have a parallel interface, rather than a serial one. The Pin argument can be the numbers 0, 1, 8, or 9 and will result in the use of the I/O pins shown above. Please refer to the LCDCMD command description for information on properly wiring the LCD display.
When the LCD is first powered-up, it will be in an unknown state and must be properly configured before sending commands like the one shown above. This process is known as initializing the LCD and is the first thing your program should do upon starting up. Please refer to the LCDCMD command description for information on properly initializing the LCD display.
The LCDOUT command's OutputData argument is exactly like that of the DEBUG and SEROUT command's OutputData argument. This means data can be sent as literal text, ASCII character values, repetitive values, decimal, hexadecimal and binary translations and string data as in the examples below.
value VAR Byte Setup: value = 65 Main: LCDOUT 1, 0, [value] ' send ASCII character "A" LCDOUT 1, 0, [REP value\5] ' send "AAAAA" LCDOUT 1, 0, [DEC value] ' send "6" and "5" LCDOUT 1, 0, [HEX value] ' send "4" and "1" LCDOUT 1, 0, [BIN value] ' send "1000001" STOP
The tables below list all the available conversion formatters and special formatters available to the LCDOUT command. See the DEBUG and SEROUT commands for additional information and examples of their use.
Conversion Formatter | Type of Number | Notes |
DEC{1..5} | Decimal, optionally fixed to 1 - 5 digits | 1 |
SDEC{1..5} | Signed decimal, optionally fixed to 1 - 5 digits | 1,2 |
HEX{1..4} | Hexadecimal, optionally fixed to 1 - 4 digits | 1 |
SHEX{1..4} | Signed hexadecimal, optionally fixed to 1 - 4 digits | 1,2 |
IHEX{1..4} | Indicated hexadecimal, optionally fixed to 1 - 4 digits | 1 |
ISHEX{1..4} | Signed, indicated hexadecimal, optionally fixed to 1 - 4 digits ($ prefix) | 1,2 |
BIN{1..16} | Binary, optionally fixed to 1 - 16 digits | 1 |
SBIN{1..16} | Signed binary, optionally fixed to 1 - 16 digits | 1,2 |
IBIN{1..16} | Indicated binary, optionally fixed to 1 - 16 digits | 1 |
ISBIN{1..16} | Signed, indicated binary, optionally fixed to 1 - 16 digits | 1,2 |
Special Formatter | Action |
? | Displays "symbol = x' + carriage return; where x is a number. Default format is decimal, but may be combined with conversion formatters (ex: BIN ? x to display "x = binary_number"). |
ASC ? | Displays "symbol = 'x'" + carriage return; where x is an ASCII character. |
STR ByteArray {\L} | Send character string from an array. The optional \L argument can be used to limit the output to L characters, otherwise, characters will be sent up to the first byte equal to 0 or the end of RAM space is reached. |
REP Byte\L | Send a string consisting of Byte repeated L times (ex: REP "X"\10 sends "XXXXXXXXXX"). |
The Command argument is useful for proceeding a set of data with a special LCD instruction. For example, the code below will move the cursor to location 64 (the first character on the second line) and print "Hi":
LCDOUT 1, 128 + 64, ["Hi"]
The next example, below, will turn on the blinking block cursor and print "Yo!":
LCDOUT 1, 13, ["Yo!"]
Occasionally, you will want to send data without preceding it with a command. To do this, simply use 0 for the Command argument, as in:
LCDOUT 1, 0, ["Hello there!"]
Another use for the LCDOUT command is to access and create custom characters. The Hitachi 44780 controller has a built-in character set that is similar to the ASCII character set (at least for the first 128 characters). Most of these characters are stored in ROM and are not changeable, however, the first eight characters (ASCII 0 though 7) are programmable.
Each of the programmable characters is five pixels wide and eight pixels tall. It takes eight bytes to describe each character; one byte per row (the left-most three bits are ignored). For example, the character at ASCII location 0 is defined by the bit patterns stored in bytes 0 through 7 of Character Generator RAM (CGRAM). The character at ASCII location 1 is defined by the bit patterns stored in bytes 8 through 15 of CGRAM, and so on.
To create a custom character, use some graph paper to plot out the bit pattern (on and off pixels) in a 5 x 8 pattern, as shown in below. Then calculate the corresponding binary value of the bit pattern for each of the eight rows of character data.
Character Cell Structure and Data |
After the data is calculated for each character (8 byte values per character), use the LCDOUT command with the "Move To CGRAM Address" instruction to insert the data into the character's CGRAM locations. For example, the code below will store the character shown in above into character 0's CGRAM data locations. Then it will place the cursor back on the display (DDRAM) and print the character on the screen.
LCDOUT 1, 64+0, [00, 10, 10, 00, 17, 14, 06, 00] LCDOUT 1, 128+0, ["Custom Char: ", 0]
The number 64 in the Command argument is the LCD's "Move to CGRAM Address" instruction and the 0 that is added to it is the location of the first row of data for the character 0. The LCDOUT command will write the first OutputData value (00) to this location, the second OutputData value (10) to location 1, etc. If we wanted this custom character to affect character 1, instead of 0, we'd have to adjust value of the "Move To..." command, i.e., 64+8. To affect character 2, we'd use 64+16.
To try the example above, don't forget to execute the LCD initialization code (shown in the LCDCMD description) first and never forget to move the cursor back to the screen (as with the last command, above) when you're done writing the character data to CGRAM.
BASIC Stamp Help Version 2.5.4
Copyright © Parallax Inc.
8/8/2012