public void begin(int cols, int lines) throws IOException { begin(cols, lines, LCD_5x8DOTS); }
public void setCursor(int col, int row) throws IOException { int[] rowOffsets = {0x00, 0x40, 0x14, 0x54}; if (row >= numlines) { row = numlines - 1; // we count rows starting w/0 } command(LCD_SETDDRAMADDR | (col + rowOffsets[row])); }
/********** * high level commands, for the user! */ public void clear() throws IOException { command(LCD_CLEARDISPLAY); // clear display, set cursor position to zero delayMicroseconds(2000); // this command takes a long time! }
delayMicroseconds(50000); write4bits(0x03); delayMicroseconds(4500); // wait min 4.1ms write4bits(0x03); delayMicroseconds(4500); // wait min 4.1ms write4bits(0x03); delayMicroseconds(150); write4bits(0x02); } else { command(LCD_FUNCTIONSET | displayfunction); delayMicroseconds(4500); // wait more than 4.1ms command(LCD_FUNCTIONSET | displayfunction); delayMicroseconds(150); command(LCD_FUNCTIONSET | displayfunction); command(LCD_FUNCTIONSET | displayfunction); display(); clear(); command(LCD_ENTRYMODESET | displaymode);
/************ * low level data pushing commands **********/ // write either command or data, with automatic 4/8-bit selection private void send(int value, boolean rsValue) throws IOException { rsGpio.setValue(rsValue); // if there is a RW pin indicated, set it low to Write if (rwGpio != null) { rwGpio.setValue(false); } if ((displayfunction & LCD_8BITMODE) == 0) { write4bits(value >> 4); write4bits(value); } else { write8bits(value); } }
/*********** * mid level commands, for sending data/cmds */ public void command(int value) throws IOException { send(value, false); }
private void write8bits(int value) throws IOException { for (int i = 0; i < 8; i++) { dataGpios[i].setValue(((value >> i) & 0x01) != 0); } pulseEnable(); }
public void print(String message) throws IOException { for (int i = 0; i < message.length(); i++) { write(message.charAt(i)); } }
@Override protected void onDestroy() { super.onDestroy(); if (lcd != null) { try { lcd.close(); } catch (Exception e) { Log.e(TAG, "Error closing", e); } finally { lcd = null; } } } }
private void pulseEnable() throws IOException { enableGpio.setValue(false); delayMicroseconds(1); enableGpio.setValue(true); delayMicroseconds(1); // enable pulse must be >450ns enableGpio.setValue(false); delayMicroseconds(100); // commands need > 37us to settle }
public void write(int value) throws IOException { send(value, true); }
private void write4bits(int value) throws IOException { for (int i = 0; i < 4; i++) { dataGpios[i].setValue(((value >> i) & 0x01) != 0); } pulseEnable(); }
public void leftToRight() throws IOException { displaymode |= LCD_ENTRYLEFT; command(LCD_ENTRYMODESET | displaymode); }
public void home() throws IOException { command(LCD_RETURNHOME); // set cursor position to zero delayMicroseconds(2000); // this command takes a long time! }
public void blink() throws IOException { displaycontrol |= LCD_BLINKON; command(LCD_DISPLAYCONTROL | displaycontrol); }
public void cursor() throws IOException { displaycontrol |= LCD_CURSORON; command(LCD_DISPLAYCONTROL | displaycontrol); }
public void autoscroll() throws IOException { displaymode |= LCD_ENTRYSHIFTINCREMENT; command(LCD_ENTRYMODESET | displaymode); }
public void noDisplay() throws IOException { displaycontrol &= ~LCD_DISPLAYON; command(LCD_DISPLAYCONTROL | displaycontrol); }