Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ashevchuk/08087e86cfd7dad4c3a7d025cbcee1e1 to your computer and use it in GitHub Desktop.
Save ashevchuk/08087e86cfd7dad4c3a7d025cbcee1e1 to your computer and use it in GitHub Desktop.
Patch to make LCDproc work with Chineese version of the HD44780 extender which has different wiring than the original version
--- server/drivers/hd44780-i2c.c 2014-03-23 11:22:09.000000000 +0100
+++ server/drivers/hd44780-i2c.c 2015-12-27 00:55:15.528659000 +0100
@@ -85,10 +85,10 @@
void i2c_HD44780_backlight(PrivateData *p, unsigned char state);
void i2c_HD44780_close(PrivateData *p);
-#define RS 0x10
-#define RW 0x20
-#define EN 0x40
-#define BL 0x80
+#define RS 0x01
+#define RW 0x02
+#define EN 0x04
+#define BL 0x08
// note that the above bits are all meant for the data port of PCF8574
#define I2C_ADDR_MASK 0x7f
@@ -191,12 +191,12 @@
if (p->port & I2C_PCAX_MASK) { // we have a PCA9554 or similar, that needs special config
char data[2];
- data[0] = 2; // command: set polarity inversion
+ data[0] = 2 << 4; // command: set polarity inversion
data[1] = 0; // -> no polarity inversion
if (write(p->fd,data,2) != 2) {
report(RPT_ERR, "HD44780: I2C: i2c set polarity inversion failed: %s", strerror(errno));
}
- data[0] = 3; // command: set output direction
+ data[0] = 3 << 4; // command: set output direction
data[1] = 0; // -> all pins are outputs
if (write(p->fd,data,2) != 2) {
report(RPT_ERR, "HD44780: I2C: i2c set output direction failed: %s", strerror(errno));
@@ -210,43 +210,43 @@
// powerup the lcd now
/* We'll now send 0x03 a couple of times,
* which is in fact (FUNCSET | IF_8BIT) >> 4 */
- i2c_out(p, 0x03);
+ i2c_out(p, 0x30);
if (p->delayBus)
hd44780_functions->uPause(p, 1);
- i2c_out(p, enableLines | 0x03);
+ i2c_out(p, enableLines | 0x30);
if (p->delayBus)
hd44780_functions->uPause(p, 1);
- i2c_out(p, 0x03);
+ i2c_out(p, 0x30);
hd44780_functions->uPause(p, 15000);
- i2c_out(p, enableLines | 0x03);
+ i2c_out(p, enableLines | 0x30);
if (p->delayBus)
hd44780_functions->uPause(p, 1);
- i2c_out(p, 0x03);
+ i2c_out(p, 0x30);
hd44780_functions->uPause(p, 5000);
- i2c_out(p, enableLines | 0x03);
+ i2c_out(p, enableLines | 0x30);
if (p->delayBus)
hd44780_functions->uPause(p, 1);
- i2c_out(p, 0x03);
+ i2c_out(p, 0x30);
hd44780_functions->uPause(p, 100);
- i2c_out(p, enableLines | 0x03);
+ i2c_out(p, enableLines | 0x30);
if (p->delayBus)
hd44780_functions->uPause(p, 1);
- i2c_out(p, 0x03);
+ i2c_out(p, 0x30);
hd44780_functions->uPause(p, 100);
// now in 8-bit mode... set 4-bit mode
- i2c_out(p, 0x02);
+ i2c_out(p, 0x20);
if (p->delayBus)
hd44780_functions->uPause(p, 1);
- i2c_out(p, enableLines | 0x02);
+ i2c_out(p, enableLines | 0x20);
if (p->delayBus)
hd44780_functions->uPause(p, 1);
- i2c_out(p, 0x02);
+ i2c_out(p, 0x20);
hd44780_functions->uPause(p, 100);
// Set up two-line, small character (5x8) mode
@@ -280,8 +280,8 @@
i2c_HD44780_senddata(PrivateData *p, unsigned char displayID, unsigned char flags, unsigned char ch)
{
unsigned char enableLines = 0, portControl = 0;
- unsigned char h = (ch >> 4) & 0x0f; // high and low nibbles
- unsigned char l = ch & 0x0f;
+ unsigned char h = ch & 0xf0; // high and low nibbles
+ unsigned char l = ch << 4;
if (flags == RS_INSTR)
portControl = 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment