# LCDIN

LCDIN Example

Syntax: LCDIN Pin, Command, [InputData]

## Function

Receive data from an LCD display.

- Pin is a variable/constant/expression (0 - 1 or 8 - 9) that specifies which I/O pins to use. The LCD requires, at most, seven I/O pins to operate. The Pin argument serves a double purpose; specifying the first pin and, indirectly, the group of other required pins. See explanation below. All I/O pins will be set to output mode initially and the upper I/O pins (4 - 7 or 12 - 15) will be set to input mode by the end of the LCDIN command.
- Command is a variable/constant/expression (0 - 255) indicating the LCD command to send.
- InputData is a list of variables and formatters that tells LCDIN what to do with incoming data. LCDIN can store data in a variable or array, interpret numeric text (decimal, binary, or hex) and store the corresponding value in a variable, wait for a fixed or variable sequence of bytes, or ignore a specified number of bytes. These actions can be combined in any order in the InputData list.

## Quick Facts

| 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
Special Notes | LCDIN is designed to use the LCD's 4-bit mode only.
Related Commands | LCDCMD, LCDOUT

## Explanation

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 LCDIN command is used to send one instruction and then receive at least one data byte from the LCD's Character Generator RAM (CGRAM) or Display Data RAM (DDRAM). The following is an example of the LCDIN command:

    char    VAR     Byte

    Main:
      LCDIN 1, 128, [char]
      STOP

The preceding example will read the character value at location 0 of the DDRAM. See the "Character Positioning" section, below, for more information.

The LCDIN command actually uses more than just the I/O pin specified by the Pin argument. The LCDIN 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 LCDIN command's InputData argument is similar to the SERIN command's InputData argument. This means data can be received as ASCII character values, decimal, hexadecimal and binary translations and string data as in the examples below (assume the LCD display has "Value: 3A:101" starting at the first character of the first line on the screen).

    value   VAR     Byte(13)

    Main:
      LCDIN 1, 128, [value]                 ' receive ASCII code for "V"
      LCDIN 1, 128, [DEC value]             ' receive the number 3
      LCDIN 1, 128, [HEX value]             ' receive the number $3A
      LCDIN 1, 128, [BIN value]             ' receive the number %101
      LCDIN 1, 128, [STR value\13]          ' receive the string "Value: 3A:101"

The tables below list all the available conversion formatters and special formatters available to the LCDIN command. See the SERIN command for additional information and examples of their use.

Conversion Formatter | Type of Number | Numeric Characters Accepted | Notes
DEC{1..5} | Decimal, optionally limited to 1 - 5 digits | 0 through 9 | 1
SDEC{1..5} | Signed decimal, optionally limited to 1 - 5 digits | -, 0 through 9 | 1,2
HEX{1..4} | Hexadecimal, optionally limited to 1 - 4 digits | 0 through 9, A through F | 1,3
SHEX{1..4} | Signed hexadecimal, optionally limited to 1 - 4 digits | -, 0 through 9, A through F | 1,2,3
IHEX{1..4} | Indicated hexadecimal, optionally limited to 1 - 4 digits | $, 0 through 9, A through F | 1,3,4
ISHEX{1..4} | Signed, indicated hexadecimal, optionally limited to 1 - 4 digits | -, $, 0 through 9, A through F | 1,2,3,4
BIN{1..16} | Binary, optionally limited to 1 - 16 digits | 0, 1 | 1
SBIN{1..16} | Signed binary, optionally limited to 1 - 16 digits | -, 0, 1 | 1,2
IBIN{1..16} | Indicated binary, optionally limited to 1 - 16 digits | %, 0, 1 | 1,4
ISBIN{1..16} | Signed, indicated binary, optionally limited to 1 - 16 digits | -, %, 0, 1 | 1,2,4
NUM | Generic numeric input; hex or binary number must be indicated | $, %, 0 through 9, A through F | 1,3,4
SNUM | Similar to NUM with value treated as signed with range -32768 to +32767 | -, $, %, 0 through 9, A through F | 1,2,3,4

1. All numeric conversions will continue to accept new data until receiving either the specified number of digits (ex: three digits for DEC3) or a non-numeric character.
2. To be recognized as part of a number, the minus sign (-) must immediately precede a numeric character. The minus sign character occurring in non-numeric text is ignored and any character (including a space) between a minus and a number causes the minus to be ignored.
3. The hexadecimal formatters are not case-sensitive; "a" through "f" means the same as "A" through "F".
4. Indicated hexadecimal and binary formatters ignore all characters, even valid numerics, until they receive the appropriate prefix ($ for hexadecimal, % for binary). The indicated formatters can differentiate between text and hexadecimal (ex: ABC would be interpreted by HEX as a number but IHEX would ignore it unless expressed as $ABC). Likewise, the binary version can distinguish the decimal number 10 from the binary number %10. A prefix occurring in non-numeric text is ignored, and any character (including a space) between a prefix and a number causes the prefix to be ignored. Indicated, signed formatters require that the minus sign come before the prefix, as in -$1B45.

Special Formatter | Action
STR ByteArray \L {\E} | Input a character string of length L into an array. If specified, an end character E causes the string input to end before reaching length L. Remaining bytes are filled with 0s (zeros).
WAITSTR ByteArray {\L} | Wait for a sequence of bytes matching a string stored in an array variable, optionally limited to L characters. If the optional L argument is left off, the end of the array-string must be marked by a byte containing a zero (0).
SKIP Length | Ignore Length bytes of characters.
SPSTR Length | Buffer Length bytes (up to 126) of serial characters to Scratchpad RAM, starting at location 0. Use GET to retrieve the characters.

Some possible uses of the LCDIN command are 1) in combination with the LCDOUT command to store and read data from the unused DDRAM or CGRAM locations (as extra variable space), 2) to verify that the data from a previous LCDOUT command was received and processed properly by the LCD, and 3) to read character data from CGRAM for the purposes of modifying it and storing it as a custom character.

Go to Welcome page

BASIC Stamp Help Version 2.5.4

Copyright © Parallax Inc.

8/8/2012