Character LCD based on HD44780-compartible controller is supported by external device library, so it's simple to work with it. MCU Java source works with LCDs with any number of characters arranged in 1, 2, 3 or 4 rows. Rows 3 and 4 are treated as continuation of rows 1 and 2.
Only write operations are performed, R/W pin of LCD is connected to GND.
LCD could be connected to MCU in following ways:
In every mode, except external memory mode, pins RS and E of LCD could be connected to any port line of MCU. In following tutorial board character LCD is connected using mode 1 (4-bit, data pins connected to one port sequentially: DB4 to PD4, DB5 to PD5, DB6 to PD6, DB7 to PD7).
Schematic of board with character LCD
Download schematic of board with character LCD in TinyCad format (.dsn)
This simple test program shows "Hello, LCD!" text in the first line and "This is line 2" in the second. First string is loaded from Flash memory, and second is stored in RAM. Note that rows and character numbers (as arguments of setPosition
method) are counted starting from 0
import mcujavasource.mcu.*;
import mcujavasource.mcu.external.lcd.CharacterLcd;
/** Tutorial 9: Character LCD.
*/
public class Main extends Microcontroller
{
public static final String MESSAGE = "Hello, LCD!";
private CharacterLcd lcd;
private Port lcdPort = getHardware().getPort("D");
private Port lcdControlPort = getHardware().getPort("C");
private Pin rsPin = lcdControlPort.getPin(5);
private Pin ePin = lcdControlPort.getPin(3);
public void init()
{ getHardware().setAllPortsDirection(Pin.IN);
getHardware().setAllPortsPullUp(true);
lcd = new CharacterLcd(16, 2, rsPin, ePin, lcdPort, 4);
}
public void start()
{ lcd.init();
lcd.setPosition(0, 0);
lcd.write(MESSAGE);
lcd.setPosition(1, 0);
lcd.write("This is line 2");
getHardware().setInterruptsEnabled(true);
}
}