OSDN Git Service

[LCD] Start to support real-machine, SC1602BBWB@4bit data bus mode.
[openi2cradio/OpenI2CRadio.git] / lcd_acm1602.c
index 9738fa6..ad74c94 100644 (file)
@@ -120,16 +120,30 @@ static unsigned char lcd_busychk(unsigned char addr)
     b &= ~_LCDPORT_CONT_RS;
     b |= _LCDPORT_CONT_RW;
     _LCDPORT_CONT_LATCH = b;
+    _ACM1602_TC_WAIT(); // Wait 2.5?us
+
     b |= _LCDPORT_CONT_EN; // 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;
+    _ACM1602_TC_WAIT(); // Wait 2.5?us
+
+    b |= _LCDPORT_CONT_EN; // Disable EN
+    _LCDPORT_CONT_LATCH = b;
+    _ACM1602_TC_WAIT(); // Wait 2.5?us
     b &= ~_LCDPORT_CONT_EN; // Disable EN
     _LCDPORT_CONT_LATCH = b;
+    _ACM1602_TC_WAIT(); // Wait 2.5?us
 
     b = _LCDPORT_TRIS_DATA;
     b &= ~_LCDPORT_READMASK; // Clear mask for Tristate, direction = write.
     _LCDPORT_TRIS_DATA = b;
+    _ACM1602_TC_WAIT(); // Wait 2.5?us
 
     if((d & _LCDPORT_BUSYMASK) != 0){
         d = 0xff; // BUSY
@@ -178,7 +192,7 @@ static void sendcmd(unsigned char addr, unsigned char cmd,unsigned char busyflag
     _ACM1602_TC_WAIT();
 
     // Lower NIBBLE
-    if(busyflag != 0) lcd_waitbusy(addr, 0);
+//    if(busyflag != 0) lcd_waitbusy(addr, 0);
     d = _LCDPORT_TRIS_CONT;
     d &= ~_LCDPORT_READMASK; // Clear mask for Tristate, direction = write.
     _LCDPORT_TRIS_CONT = d;
@@ -189,6 +203,7 @@ static void sendcmd(unsigned char addr, unsigned char cmd,unsigned char busyflag
     _ACM1602_TC_WAIT(); // Wait 2.5?us
     b |= _LCDPORT_CONT_EN;
     _LCDPORT_CONT_LATCH = b;
+
     _ACM1602_TC_WAIT(); // Wait 2.5?us
     b &= ~_LCDPORT_CONT_EN; // Disable EN
     _LCDPORT_CONT_LATCH = b;
@@ -243,6 +258,7 @@ static void sendonce(unsigned char addr, unsigned char cmd)
     b &= ~(_LCDPORT_CONT_RS | _LCDPORT_CONT_RW | _LCDPORT_CONT_EN); // RS='0',RW='0'
     b |= h;
     _LCDPORT_CONT_LATCH = b;
+    _ACM1602_TC_WAIT(); // Wait 2.5?us
 
     b |= _LCDPORT_CONT_EN; // Send CMD
     _LCDPORT_CONT_LATCH = b;
@@ -294,9 +310,8 @@ static void acm1602_ioinit(unsigned char addr)
     b = _LCDPORT_CONT_LATCH;
     b &= ~(_LCDPORT_CONT_RS | _LCDPORT_CONT_RW | _LCDPORT_CONT_EN | 0xf0);
     _LCDPORT_CONT_LATCH = b;
-
-    //_LCDPORT_TRIS_DATA = 0x00; // OUT
-    //_LCDPORT_LATCH_DATA = 0x00;
+  //  _LCDPORT_TRIS_DATA = 0x00; // OUT
+  //  _LCDPORT_LATCH_DATA = 0x00;
 #else
     b = _LCDPORT_TRIS_CONT;
     b &= ~(_LCDPORT_CONT_RS | _LCDPORT_CONT_RW | _LCDPORT_CONT_EN);
@@ -320,8 +335,10 @@ void acm1602_putchar(unsigned char addr, unsigned char c)
 
     lcd_waitbusy(addr, 0);
     d = _LCDPORT_TRIS_CONT;
-    d &= ~_LCDPORT_READMASK; // Clear mask for Tristate, direction = write.
+    d &= ~(_LCDPORT_READMASK | _LCDPORT_CONT_RW | _LCDPORT_CONT_EN | _LCDPORT_CONT_RS); // Clear mask for Tristate, direction = write.
+//    d = 0;
     _LCDPORT_TRIS_CONT = d;
+    _ACM1602_TC_WAIT(); // Wait 2.5?us
 
     // Send high nibble
     b = _LCDPORT_CONT_LATCH;
@@ -337,19 +354,14 @@ void acm1602_putchar(unsigned char addr, unsigned char c)
 
     b &= ~_LCDPORT_CONT_EN; // Disable EN
     _LCDPORT_CONT_LATCH = b;
-    _ACM1602_TC_WAIT();
-
-    lcd_waitbusy(addr, 0);
-    d = _LCDPORT_TRIS_CONT;
-    d &= ~_LCDPORT_READMASK; // Clear mask for Tristate, direction = write.
-    _LCDPORT_TRIS_CONT = d;
+    _ACM1602_SHORT_WAIT();
 
-    b = _LCDPORT_CONT_LATCH;
+//    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
+//    _LCDPORT_CONT_LATCH = b;
+//    _ACM1602_TC_WAIT(); // Wait 2.5?us
 
     b |= _LCDPORT_CONT_EN;
     _LCDPORT_CONT_LATCH = b; // Do low write.
@@ -357,7 +369,8 @@ void acm1602_putchar(unsigned char addr, unsigned char c)
 
     b &= ~_LCDPORT_CONT_EN; // Disable EN
     _LCDPORT_CONT_LATCH = b;
-    _ACM1602_SHORT_WAIT();
+    _ACM1602_TC_WAIT(); // Wait 2.5?us
+
 
 #else
     lcd_waitbusy(addr, 0);
@@ -479,7 +492,7 @@ unsigned char acm1602_getchar(unsigned char addr)
 void acm1602_cls(unsigned char addr)
 {
     sendcmd(addr, 0x01, 0xff);
-    _ACM1602_LONG_WAIT(); // Wait 5ms
+    _ACM1602_LONG_LONG_WAIT(); // Wait 5ms
 }
 
 void acm1602_setdataramaddress(unsigned char addr, unsigned char pos)
@@ -512,7 +525,7 @@ void acm1602_locate_8x2(unsigned char addr, char x, char y)
 void acm1602_home(unsigned char addr)
 {
     sendcmd(addr, 0x02, 0xff);
-    _ACM1602_LONG_WAIT(); // Wait 5ms
+    _ACM1602_LONG_LONG_WAIT(); // Wait 5ms
 }
 
 void acm1602_printf(unsigned char addr, const char *fmt, ...)
@@ -561,19 +574,31 @@ void acm1602_init(unsigned char addr, unsigned char cls)
     sendonce(addr, 0x38); // 2lines, 8x10dot fonts.
     sendcmd(addr, 0x38, 0x00); // 2lines, 8x10dot fonts.
   #else // 4Bit
+    _ACM1602_LONG_LONG_WAIT();
+    sendonce(addr, 0x30); // 2lines, 8x10dot fonts.
+    _ACM1602_SHORT_WAIT();
     sendonce(addr, 0x30); // 2lines, 8x10dot fonts.
+    _ACM1602_SHORT_WAIT();
+    sendonce(addr, 0x30); // 2lines, 8x10dot fonts.
+    _ACM1602_SHORT_WAIT();
+    sendonce(addr, 0x20); // 2lines, 8x10dot fonts.
+    _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, 0x00); // 2lines, 8x10dot fonts.
   #endif
 #endif
-    sendcmd(addr, 0x0f, 0xff); // Display ON.
-    sendcmd(addr, 0b00000110, 0xff); // Cursor increment,not shift.
+//    sendcmd(addr, 0x08, 0xff); // Display OFF.
+    sendcmd(addr, 0x0c, 0xff); // Display ON.
+    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);
 }
 /*
  * st7032 extensions.