func (l *LCD) pulseEnable() { rpi.DigitalWrite(l.enable, LOW) rpi.DelayMicroseconds(1) rpi.DigitalWrite(l.enable, HIGH) rpi.DelayMicroseconds(1) rpi.DigitalWrite(l.enable, LOW) rpi.DelayMicroseconds(100) }
func (l *LCD) write4bits(v uint8) { for i := uint8(0); i < 4; i++ { b := (v>>i)&0x01 == 0x01 rpi.PinMode(l.data[i], rpi.OUTPUT) rpi.DigitalWrite(l.data[i], b) } l.pulseEnable() }
func (l *LCD) Begin(cols, lines int) { if lines > 1 { l.displayfunction |= LCD_2LINE } rpi.DelayMicroseconds(50000) // Now we pull both RS and R/W low to begin commands rpi.DigitalWrite(l.rs, LOW) rpi.DigitalWrite(l.enable, LOW) // we start in 8bit mode, try to set 4 bit mode l.write4bits(0x03) rpi.DelayMicroseconds(4500) // wait min 4.1ms // we start in 8bit mode, try to set 4 bit mode l.write4bits(0x03) rpi.DelayMicroseconds(4500) // wait min 4.1ms // we start in 8bit mode, try to set 4 bit mode l.write4bits(0x03) rpi.DelayMicroseconds(150) // finally, set to 8-bit interface l.write4bits(0x02) // finally, set # lines, font size, etc. l.command(LCD_FUNCTIONSET | l.displayfunction) // turn the display on with no cursor or blinking default l.displaycontrol = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF l.Display() // clear it off l.Clear() // Initialize to default text direction (for romance languages) l.displaymode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT // set the entry mode l.command(LCD_ENTRYMODESET | l.displaymode) }
func (l *LCD) send(v uint8, mode bool) { rpi.DigitalWrite(l.rs, mode) l.write4bits(v >> 4) l.write4bits(v) }