return d;
}
#else // Parallel
+static void _ACM1602_TC_WAIT(void)
+{
+#ifdef __SDCC
+ delay10tcy(4);
+#else
+ __delay_us(5);
+#endif
+}
+
static unsigned char lcd_busychk(unsigned char addr)
{
unsigned char b, d;
b |= _LCDPORT_READMASK;// Set mask for Tristate, direction = read.
_LCDPORT_TRIS_DATA = b;
- b = _LCDPORT_CONT_LATCH;
- b &= ~_LCDPORT_CONT_RS;
- b |= _LCDPORT_CONT_RW;
- _LCDPORT_CONT_LATCH = b;
+// b = _LCDPORT_CONT_LATCH;
+ _LCDPORT_CONT_RS = 0;
+ _LCDPORT_CONT_RW = 1;
+// _LCDPORT_CONT_LATCH = b;
_ACM1602_TC_WAIT(); // Wait 2.5?us
- b |= _LCDPORT_CONT_EN; // Send CMD
- _LCDPORT_CONT_LATCH = b;
+ _LCDPORT_CONT_EN = 1; // Send CMD
+// _LCDPORT_CONT_LATCH = b;
_ACM1602_TC_WAIT(); // Wait 2.5?us
d = _LCDPORT_DATA;
_ACM1602_TC_WAIT(); // Wait 2.5?us
- b &= ~_LCDPORT_CONT_EN; // Disable EN
- _LCDPORT_CONT_LATCH = b;
+ _LCDPORT_CONT_EN = 0; // Disable EN
+// _LCDPORT_CONT_LATCH = b;
_ACM1602_TC_WAIT(); // Wait 2.5?us
- b |= _LCDPORT_CONT_EN; // Disable EN
- _LCDPORT_CONT_LATCH = b;
+ _LCDPORT_CONT_EN = 1; // Disable EN
+// _LCDPORT_CONT_LATCH = b;
_ACM1602_TC_WAIT(); // Wait 2.5?us
- b &= ~_LCDPORT_CONT_EN; // Disable EN
- _LCDPORT_CONT_LATCH = b;
+
+ _LCDPORT_CONT_EN = 0;; // Disable EN
+// _LCDPORT_CONT_LATCH = b;
_ACM1602_TC_WAIT(); // Wait 2.5?us
b = _LCDPORT_TRIS_DATA;
d &= ~_LCDPORT_READMASK; // Clear mask for Tristate, direction = write.
_LCDPORT_TRIS_CONT = d;
-
- b = _LCDPORT_CONT_LATCH;
- b &= ~(_LCDPORT_CONT_RW | 0xf0 | _LCDPORT_CONT_EN | _LCDPORT_CONT_RS); // DATA=blank,RW='0',RS='0"
- b |= h;
- _LCDPORT_CONT_LATCH = b;
+ _LCDPORT_CONT_RW = 0;
+ _LCDPORT_CONT_EN = 0;
+ _LCDPORT_CONT_RS = 0;
+ _LCDPORT_CONT_LATCH &= 0x0f; // Upper
+// b &= ~(_LCDPORT_CONT_RW | 0xf0 | _LCDPORT_CONT_EN | _LCDPORT_CONT_RS); // DATA=blank,RW='0',RS='0"
+ _LCDPORT_CONT_LATCH |= h;
+// _LCDPORT_CONT_LATCH = b;
_ACM1602_TC_WAIT(); // Wait 2.5?us
- b |= _LCDPORT_CONT_EN;
- _LCDPORT_CONT_LATCH = b;
+
+ _LCDPORT_CONT_EN = 1;
+ //_LCDPORT_CONT_LATCH = b;
_ACM1602_TC_WAIT(); // Wait 2.5?us
- b &= ~_LCDPORT_CONT_EN; // Disable EN
- _LCDPORT_CONT_LATCH = b;
+
+ _LCDPORT_CONT_EN = 0; // Disable EN
+// _LCDPORT_CONT_LATCH = b;
_ACM1602_TC_WAIT();
// Lower NIBBLE
// if(busyflag != 0) lcd_waitbusy(addr, 0);
- d = _LCDPORT_TRIS_CONT;
- d &= ~_LCDPORT_READMASK; // Clear mask for Tristate, direction = write.
- _LCDPORT_TRIS_CONT = d;
- b = _LCDPORT_CONT_LATCH;
- b &= ~(_LCDPORT_CONT_RW | 0xf0 | _LCDPORT_CONT_EN | _LCDPORT_CONT_RS); // DATA=blank,RW='0',RS='0"
- b |= l;
- _LCDPORT_CONT_LATCH = b;
+// d = _LCDPORT_TRIS_CONT;
+// d &= ~_LCDPORT_READMASK; // Clear mask for Tristate, direction = write.
+// _LCDPORT_TRIS_CONT = d;
+
+ _LCDPORT_CONT_RW = 0;
+ _LCDPORT_CONT_EN = 0;
+ _LCDPORT_CONT_RS = 0;
+ _LCDPORT_CONT_LATCH &= 0x0f; // Lower
+
+ _LCDPORT_CONT_LATCH |= l;
_ACM1602_TC_WAIT(); // Wait 2.5?us
- b |= _LCDPORT_CONT_EN;
- _LCDPORT_CONT_LATCH = b;
+ _LCDPORT_CONT_EN = 1;
+// _LCDPORT_CONT_LATCH = b;
_ACM1602_TC_WAIT(); // Wait 2.5?us
- b &= ~_LCDPORT_CONT_EN; // Disable EN
- _LCDPORT_CONT_LATCH = b;
+ _LCDPORT_CONT_EN = 0; // Disable EN
+// _LCDPORT_CONT_LATCH = b;
- d = _LCDPORT_TRIS_CONT;
- d &= ~_LCDPORT_READMASK; // Clear mask for Tristate, direction = write.
- _LCDPORT_TRIS_CONT = d;
+// d = _LCDPORT_TRIS_CONT;
+ // d &= ~_LCDPORT_READMASK; // Clear mask for Tristate, direction = write.
+ // _LCDPORT_TRIS_CONT = d;
#else
unsigned char b,d;
h = cmd & 0xf0; // Higher bit is used.
// Higher NIBBLE
+ //d = _LCDPORT_TRIS_CONT;
+// d = TRIS_D_VAL; // Clear mask for Tristate, direction = write.
+// _LCDPORT_TRIS_CONT = d;
d = _LCDPORT_TRIS_CONT;
d &= ~_LCDPORT_READMASK; // Clear mask for Tristate, direction = write.
_LCDPORT_TRIS_CONT = d;
- b = _LCDPORT_CONT_LATCH;
- b &= ~(_LCDPORT_CONT_RS | _LCDPORT_CONT_RW | _LCDPORT_CONT_EN); // RS='0',RW='0'
- b |= h;
- _LCDPORT_CONT_LATCH = b;
+ _LCDPORT_CONT_RS = 0;
+ _LCDPORT_CONT_RW = 0;
+ _LCDPORT_CONT_EN = 0; // RS='0',RW='0'
+ _LCDPORT_CONT_LATCH &= 0x0f;
+ _LCDPORT_CONT_LATCH |= h;
_ACM1602_TC_WAIT(); // Wait 2.5?us
- b |= _LCDPORT_CONT_EN; // Send CMD
- _LCDPORT_CONT_LATCH = b;
+ _LCDPORT_CONT_EN = 1; // Send CMD
_ACM1602_TC_WAIT(); // Wait 2.5?us
- b &= ~_LCDPORT_CONT_EN; // Disable EN
- _LCDPORT_CONT_LATCH = b;
+ _LCDPORT_CONT_EN = 0; // Disable EN
_ACM1602_TC_WAIT();
- d = _LCDPORT_TRIS_CONT;
- d &= ~_LCDPORT_READMASK; // Clear mask for Tristate, direction = write.
- _LCDPORT_TRIS_CONT = d;
+// d = _LCDPORT_TRIS_CONT;
+// d &= ~_LCDPORT_READMASK; // Clear mask for Tristate, direction = write.
+// _LCDPORT_TRIS_CONT = d;
#else
unsigned char b, d;
// lcd_waitbusy(0);
_ACM1602_LONG_LONG_WAIT();
#ifdef _LCD_IF_4BIT
- b = _LCDPORT_TRIS_CONT;
- b &= ~(_LCDPORT_CONT_RS | _LCDPORT_CONT_RW | _LCDPORT_CONT_EN | 0xf0);
- _LCDPORT_TRIS_CONT = b; // Clear Tristate bits, output.
+ _LCDPORT_TRIS_CONT = TRIS_D_VAL;
- b = _LCDPORT_CONT_LATCH;
- b &= ~(_LCDPORT_CONT_RS | _LCDPORT_CONT_RW | _LCDPORT_CONT_EN | 0xf0);
- _LCDPORT_CONT_LATCH = b;
+ _LCDPORT_CONT_RS = 0;
+ _LCDPORT_CONT_RW = 0;
+ _LCDPORT_CONT_EN = 0;
+ _LCDPORT_CONT_LATCH &= ~0xf0;
+// _LCDPORT_CONT_LATCH = b;
// _LCDPORT_TRIS_DATA = 0x00; // OUT
// _LCDPORT_LATCH_DATA = 0x00;
#else
l = (c & 0x0f)<<4;
lcd_waitbusy(addr, 0);
- d = _LCDPORT_TRIS_CONT;
- d &= ~(_LCDPORT_READMASK | _LCDPORT_CONT_RW | _LCDPORT_CONT_EN | _LCDPORT_CONT_RS); // Clear mask for Tristate, direction = write.
-// d = 0;
+// d = _LCDPORT_TRIS_CONT;
+// d &= 0x00; // Clear mask for Tristate, direction = write.
+ d = TRIS_D_VAL; // ALL OUT
_LCDPORT_TRIS_CONT = d;
_ACM1602_TC_WAIT(); // Wait 2.5?us
// Send high nibble
- b = _LCDPORT_CONT_LATCH;
- b &= ~(_LCDPORT_CONT_RW | 0xf0 | _LCDPORT_CONT_EN); // DATA=blank,RW='0'
- b |= _LCDPORT_CONT_RS; // RS='1"
- b |= h;
- _LCDPORT_CONT_LATCH = b;
+ //b = _LCDPORT_CONT_LATCH;
+ _LCDPORT_CONT_RW = 0;
+ _LCDPORT_CONT_EN = 0; // DATA=blank,RW='0'
+ _LCDPORT_CONT_LATCH &= ~0xf0;
+ _LCDPORT_CONT_RS = 1; // RS='1"
+// _LCDPORT_CONT_LATCH = b;
_ACM1602_TC_WAIT(); // Wait 2.5?us
- b |= _LCDPORT_CONT_EN; // Do high write.
- _LCDPORT_CONT_LATCH = b;
+ _LCDPORT_CONT_EN = 1; // Do high write.
+// b |= h;
+ _LCDPORT_CONT_LATCH |= h;
_ACM1602_TC_WAIT(); // Wait 2.5?us
- b &= ~_LCDPORT_CONT_EN; // Disable EN
- _LCDPORT_CONT_LATCH = b;
+ _LCDPORT_CONT_EN = 0; // Disable EN
+// _LCDPORT_CONT_LATCH = b;
_ACM1602_SHORT_WAIT();
// lcd_waitbusy(addr, 0);
- b &= ~(_LCDPORT_CONT_RW | 0xf0 | _LCDPORT_CONT_EN); // DATA=blank,RW='0'
- b |= _LCDPORT_CONT_RS; // RS='1"
- b |= l;
-// _LCDPORT_CONT_LATCH = b;
-// _ACM1602_TC_WAIT(); // Wait 2.5?us
-
- b |= _LCDPORT_CONT_EN;
- _LCDPORT_CONT_LATCH = b; // Do low write.
+ _LCDPORT_CONT_LATCH &= ~0xf0;
+ _LCDPORT_CONT_RS = 1; // RS='1"
_ACM1602_TC_WAIT(); // Wait 2.5?us
- b &= ~_LCDPORT_CONT_EN; // Disable EN
- _LCDPORT_CONT_LATCH = b;
+ _LCDPORT_CONT_LATCH |= l; // Do low write.
+ _LCDPORT_CONT_EN = 1;
_ACM1602_TC_WAIT(); // Wait 2.5?us
+ _LCDPORT_CONT_EN = 0; // Disable EN
+ _ACM1602_SHORT_WAIT();
+
#else
lcd_waitbusy(addr, 0);
#endif
}
-unsigned char acm1602_getchar(unsigned char addr)
-{
- unsigned char b, d;
-#ifdef _LCD_IF_4BIT
- unsigned char h, l;
-
- lcd_waitbusy(addr, 0);
- d = _LCDPORT_TRIS_CONT;
- d |= _LCDPORT_READMASK; // Set mask for Tristate, direction = read.
- _LCDPORT_TRIS_CONT = d;
-
- // Recv high nibble
- b = _LCDPORT_CONT_LATCH;
- b &= ~(0xf0 | _LCDPORT_CONT_EN); // DATA=blank
- b |= (_LCDPORT_CONT_RS | _LCDPORT_CONT_RW); // RS='1", RW='1'
- _LCDPORT_CONT_LATCH = b;
- _ACM1602_TC_WAIT(); // Wait 2.5?us
-
- b |= _LCDPORT_CONT_EN;
- _LCDPORT_CONT_LATCH = b;
- _ACM1602_TC_WAIT(); // Wait 2.5?us
-
- h = _LCDPORT_DATA & 0xf0;
- _ACM1602_TC_WAIT(); // Wait 2.5?us
-
- b &= ~_LCDPORT_CONT_EN; // Disable EN
- _LCDPORT_CONT_LATCH = b;
- _ACM1602_TC_WAIT();
-
- lcd_waitbusy(addr, 0);
- // Recv Low nibble.
- d = _LCDPORT_TRIS_CONT;
- d |= _LCDPORT_READMASK; // Set mask for Tristate, direction = read.
- _LCDPORT_TRIS_CONT = d;
-
- b = _LCDPORT_CONT_LATCH;
- b &= ~(0xf0 | _LCDPORT_CONT_EN); // DATA=blank
- b |= (_LCDPORT_CONT_RS | _LCDPORT_CONT_RW); // RS='1", RW='1'
- _LCDPORT_CONT_LATCH = b;
- _ACM1602_TC_WAIT(); // Wait 2.5?us
-
- b |= _LCDPORT_CONT_EN;
- _LCDPORT_CONT_LATCH = b;
- _ACM1602_TC_WAIT(); // Wait 2.5?us
-
- l = _LCDPORT_DATA & 0xf0;
- _ACM1602_TC_WAIT(); // Wait 2.5?us
-
- b &= ~_LCDPORT_CONT_EN; // Disable EN
- _LCDPORT_CONT_LATCH = b;
- _ACM1602_TC_WAIT(); // Wait 2.5?us
-
- d = _LCDPORT_TRIS_CONT;
- d &= ~_LCDPORT_READMASK; // Set mask for Tristate, direction = write.
- _LCDPORT_TRIS_CONT = d;
-
- _ACM1602_SHORT_WAIT();
-
- d = h | (l >> 4);
- return d;
-#else
- unsigned char e;
- lcd_waitbusy(addr, 0);
- d = _LCDPORT_TRIS_DATA;
- d |= _LCDPORT_READMASK; // Set mask for Tristate, direction = read.
- _LCDPORT_TRIS_DATA = d;
-
- b = _LCDPORT_CONT_LATCH;
- b |= (_LCDPORT_CONT_RS | _LCDPORT_CONT_RW); // RW=1, RS=1
- b &= ~_LCDPORT_CONT_EN; // Clear Enable
- _LCDPORT_CONT_LATCH = b;
- _ACM1602_TC_WAIT();
-
- b |= _LCDPORT_CONT_EN; // Send character
- _LCDPORT_CONT_LATCH = b;
- _ACM1602_TC_WAIT(); // Wait 2.5?us
-
- e = _LCDPORT_DATA; // Read BYTE
- _ACM1602_TC_WAIT();
-
- b &= ~_LCDPORT_CONT_EN; // Disable EN
- _LCDPORT_CONT_LATCH = b;
-
- d = _LCDPORT_TRIS_DATA;
- d &= ~_LCDPORT_READMASK; // Clear mask for Tristate, direction = read.
- _LCDPORT_TRIS_DATA = d;
-
- _ACM1602_SHORT_WAIT(); // Wait 0.1ms
- return e;
-#endif
-}
-
#endif
void acm1602_cls(unsigned char addr)
{
sendcmd(addr, 0x01, 0xff);
- _ACM1602_LONG_LONG_WAIT(); // Wait 5ms
+ _ACM1602_LONG_WAIT(); // Wait 5ms
}
void acm1602_setdataramaddress(unsigned char addr, unsigned char pos)
sendcmd(addr, cmd, 0xff);
}
-void acm1602_locate_16x2(unsigned char addr, char x, char y)
+
+void acm1602_locate_16x2(unsigned char addr, unsigned char x, unsigned char y)
{
unsigned char ramaddr;
- if((x < 0) || (x > 15)) return;
- if((y < 0) || (y > 1)) return;
- ramaddr = (y == 0)? x & 0x0f : (x & 0x0f) | 0x40;
+ if(x > 16) return;
+ if(y > 1) return;
+ ramaddr = (y == 0)? x : (x | 0x40);
acm1602_setdataramaddress(addr, ramaddr);
}
/*
* For using
*/
-void acm1602_locate_8x2(unsigned char addr, char x, char y)
+void acm1602_locate_8x2(unsigned char addr, unsigned char x, unsigned char y)
{
unsigned char ramaddr;
- if((x < 0) || (x > 8)) return;
- if((y < 0) || (y > 1)) return;
- ramaddr = (y == 0)? x & 0x0f : (x & 0x0f) | 0x40;
+ if(x > 8) return;
+ if(y > 1) return;
+ ramaddr = (y == 0)? x : x | 0x40;
acm1602_setdataramaddress(addr, ramaddr);
}
void acm1602_home(unsigned char addr)
{
sendcmd(addr, 0x02, 0xff);
- _ACM1602_LONG_LONG_WAIT(); // Wait 5ms
+ _ACM1602_LONG_WAIT(); // Wait 5ms
}
-void acm1602_printf(unsigned char addr, const char *fmt, ...)
+
+void acm1602_cursordir(unsigned char addr, unsigned char right)
{
- char strbuf[32]; // Max 32 bytes.
- va_list args;
- int i;
- int l;
-
- strbuf[0] = '\0';
- va_start(args, fmt );
- sprintf(strbuf, args);
- l = strlen(strbuf);
- if((l >= 32) || (l <= 0))return;
- for(i = 0; i < l; i++) {
- acm1602_putchar(addr, strbuf[i]);
+ unsigned char cmd;
+
+ cmd = 0x14;
+ if(right == 0) {
+ cmd = 0x10;
}
+ sendcmd(addr, cmd, 0xff);
}
-void acm1602_cursordir(unsigned char addr, unsigned char right)
+void acm1602_dispcursor(unsigned char addr, unsigned char flag)
{
unsigned char cmd;
- if(right == 0) {
- cmd = 0x18;
- } else {
- cmd = 0x1c;
+ cmd = 0x0d; // Cursor ON
+ if(flag == 0x00) {
+ cmd = 0x0c; // Cursor off
}
sendcmd(addr, cmd, 0xff);
}
#else // 4Bit
_ACM1602_LONG_LONG_WAIT();
sendonce(addr, 0x30); // 2lines, 8x10dot fonts.
- _ACM1602_SHORT_WAIT();
+// _ACM1602_SHORT_WAIT();
sendonce(addr, 0x30); // 2lines, 8x10dot fonts.
- _ACM1602_SHORT_WAIT();
+// _ACM1602_SHORT_WAIT();
sendonce(addr, 0x30); // 2lines, 8x10dot fonts.
- _ACM1602_SHORT_WAIT();
+// _ACM1602_SHORT_WAIT();
sendonce(addr, 0x20); // 2lines, 8x10dot fonts.
- _ACM1602_SHORT_WAIT();
+// _ACM1602_SHORT_WAIT();
// Send twice on 4Bit Mode.
// sendonce(addr, 0x30); // 2lines, 8x10dot fonts.
- sendcmd(addr, 0x28, 0x00); // 2lines, 8x10dot fonts.
-// sendcmd(addr, 0x28, 0x00); // 2lines, 8x10dot fonts.
+ sendcmd(addr, 0x28, 0xff); // 2lines, 8x5dot fonts.
#endif
#endif
// sendcmd(addr, 0x08, 0xff); // Display OFF.
sendcmd(addr, 0x0c, 0xff); // Display ON.
- sendcmd(addr, 0x06, 0xff); // Cursor increment,not shift.
+// sendcmd(addr, 0x06, 0xff); // Cursor increment,not shift.
if(cls == 0){
acm1602_home(addr);
} else {
acm1602_cls(addr);
}
+// _ACM1602_LONG_WAIT();
+ sendcmd(addr, 0x06, 0xff);
+}
+
+/*
+ * Suspend lcd
+ */
+void acm1602_suspend(unsigned char addr)
+{
+ sendcmd(addr, 0x08, 0xff);
+ _ACM1602_LONG_WAIT();
+}
+
+void acm1602_resume(unsigned char addr)
+{
+ sendcmd(addr, 0x0c, 0xff);
_ACM1602_LONG_WAIT();
- //sendcmd(addr, 0x06, 0xff);
}
+
+
+#ifdef _USE_I2C_1602
/*
* st7032 extensions.
*/
val |= 0x70;
st7032_extcmd(addr, 0x38, val, busyf);
}
+#endif