Before you start...
You need to either set your LCD for TTL levels or add a RS232 chip to you circuit. For setting the LCD to TTL levels, please consult the manual for your display.
Connecting the LCD to the Javelin Stamp (Hardware)...
We used one of our serial cables, cut the end off and then soldered connectors to pin #2, #3 and #5.
Pin #2 is connected to P0
Pin #3 is connected to P1
Pin #5 is connectod to Vss, which is ground
Code Examples
Connecting the LCD to the Javelin Stamp (Software)...
Before you can communicate with the LCD you need to create a Virtual UART Peripheral to communicate with the LCD.
Code: Select all
// Uart.dirTransmit -> Uart will be used to transmit data only.
// CPU.pin0 -> Pin used to transmit data
// Uart.dontInvert -> data is not inverted
// Uart.speed19200 -> serial data transfer speed (baud rate)
// Uart.stop1 -> Number of stop bits used is 1
static Uart txUart = new Uart(Uart.dirTransmit, CPU.pin0, Uart.dontInvert, Uart.speed19200, Uart.stop1 );
Sending text to the screen:
Now that you have a connection to the LCD sending text is very easy. Just send each byte (character) at a time like this...
Code: Select all
txUart.sendByte(0x43); // letter 'C' ASCII code
txUart.sendByte(0x6F); // letter 'o' ASCII code
txUart.sendByte(0x6F); // letter 'o' ASCII code
txUart.sendByte(0x6C); // letter 'l' ASCII code
OR even better send the whole string at once...
Code: Select all
txUart.sendString("Cool"); // Send string "Cool"
Your LCD should display the word "Cool" after running this code.
Sending a Command to the display:
Sending a command to the display is as easy as sending characters to the display except that you need to send it the command prefix '0xFE' first and then the command and any arguments if required. Note that you cannot use sendString to send a command to the LCD. You need to send each character individually.
For example to clear the screen...
Code: Select all
txUart.sendByte(0xFE); // Command Prefix in HEX
txUart.sendByte(0x58); // Clear command
In this example the command to clear the screen is sent to the display. Every command requires a "Command Prefix". In Matrix Orbital displays, that's Hex: FE Decimal: 254 ASCII: 254, you can send these bytes in any format you want, as long as you do it properly. In our example we sent them as HEX, if you prefer DECIMAL then don't include 0x.
i.e.
txUart.sendByte(254); // Command Prefix in DECIMAL
Setting the Backlight to go off in 2 minute:
Code: Select all
txUart.sendByte(0xFE); // Command Prefix
txUart.sendByte(0x42); // Backlight ON command
txUart.sendByte(0x02); // Stay ON for 2 minutes only
To permanently turn the backlight on, you would send 0 as the third byte. When the display recieves the command, it will know how many more bytes of information it should get. In the backlight on case, the display knows to expect one more byte of information.