Koji Tanikawa / kt_vfd_20170703

Dependents:   mbed_vfd_ntp

Files at this revision

API Documentation at this revision

Comitter:
kojie
Date:
Tue Jul 11 23:41:56 2017 +0000
Parent:
0:94347d9bbcf4
Commit message:
2017/07/12

Changed in this revision

kt_vfd.cpp Show annotated file Show diff for this revision Revisions of this file
kt_vfd.h Show annotated file Show diff for this revision Revisions of this file
diff -r 94347d9bbcf4 -r e1e942d03093 kt_vfd.cpp
--- a/kt_vfd.cpp	Mon Jul 03 14:14:06 2017 +0000
+++ b/kt_vfd.cpp	Tue Jul 11 23:41:56 2017 +0000
@@ -1,6 +1,6 @@
 /**
  * @bref VFD class imprementation
- * for GU140X16G-7040
+ * for GU256X128C-3900
  */
 #include "mbed.h"
 #include "kt_vfd.h"
@@ -15,41 +15,89 @@
     _wr = 1 ;
 
     wait_ms(100) ;
-    writeByte(0x1b) ;
-    writeByte(0x40) ;
+    write_byte(0x1b) ;
+    write_byte(0x40) ;
     wait_ms(100) ;
 }
 
-void KT_VFD::mode(unsigned char mode)
+void KT_VFD::write_mode(unsigned char mode)
+{
+    write_byte(0x1f) ;
+    write_byte(0x28) ;
+    write_byte(0x77) ;
+    write_byte(0x10) ;
+    write_byte(mode) ;
+}
+
+void KT_VFD::disp_mode(unsigned char mode)
+{
+    write_byte(0x1f) ;
+    write_byte(mode) ;
+}
+
+void KT_VFD::scroll_speed(unsigned char n)
 {
-    writeByte(0x1f) ;
-    writeByte(mode) ;
+    write_byte(0x1f) ;
+    write_byte(0x73) ;
+    write_byte(n) ; // 0x00 - 0x1f: 
+}
+
+void KT_VFD::scroll_act(unsigned int w, unsigned int c, unsigned char s)
+{
+    write_byte(0x1f) ;
+    write_byte(0x28) ;
+    write_byte(0x61) ;
+    write_byte(0x10) ;
+    write_byte(w%0x100) ;
+    write_byte(w/0x100) ;
+    write_byte(c%0x100) ;
+    write_byte(c/0x100) ;
+    write_byte(s) ;
 }
 
 void KT_VFD::cls()
 {
-    writeByte(0x0C) ;
+    write_byte(0x0C) ;
     locate(0, 0) ;
 }
 
 void KT_VFD::locate(unsigned int x, unsigned int y)
 {
-    writeByte(0x1f) ;
-    writeByte(0x24) ;
-    writeByte(x % 0x100) ; // xL
-    writeByte(x / 0x100) ; // xH
-    writeByte(y % 0x100) ; // yL
-    writeByte(y / 0x100) ; // yH
+    write_byte(0x1f) ;
+    write_byte(0x24) ;
+    write_byte(x % 0x100) ; // xL
+    write_byte(x / 0x100) ; // xH
+    write_byte(y % 0x100) ; // yL
+    write_byte(y / 0x100) ; // yH
 }
 
 void KT_VFD::lf()
 {
-    writeByte(0x0a) ;
+    write_byte(0x0a) ;
 }
 
 void KT_VFD::cr()
 {
-    writeByte(0x0d) ;
+    write_byte(0x0d) ;
+}
+
+void KT_VFD::font_size(unsigned char m)
+{
+    write_byte(0x1f) ;
+    write_byte(0x28) ;
+    write_byte(0x67) ;
+    write_byte(0x01) ;
+    write_byte(m) ;
+}
+
+void KT_VFD::char_ext(unsigned char x, unsigned char y)
+{
+    write_byte(0x1f) ;
+    write_byte(0x28) ;
+    write_byte(0x67) ;
+    write_byte(0x40) ;
+    write_byte(x) ;
+    write_byte(y) ;
 }
 
 int KT_VFD::_putc(int c)
@@ -58,7 +106,7 @@
         cr() ;
         lf() ;
     } else {
-        writeByte(c) ;
+        write_byte(c) ;
     }
     return 0 ;
 }
@@ -68,8 +116,9 @@
     return -1 ;
 }
 
-void KT_VFD::writeByte(unsigned char value)
+void KT_VFD::write_byte(unsigned char value)
 {
+#if 0
     bool ok ;
     _d[7] = 0 ;
     do {
@@ -79,10 +128,14 @@
         _rd = 1 ;
     } while (ok) ;
     _d[7] = 1 ;
+#else
+    while (!_rd) ;
+#endif
 
     _d = value ;
     _wr = 0 ;
     wait_us(0.11) ;
     _wr = 1 ;
-    wait_us(1.6) ;
+//    wait_us(1.6) ;
+    wait_us(16) ;
 }
diff -r 94347d9bbcf4 -r e1e942d03093 kt_vfd.h
--- a/kt_vfd.h	Mon Jul 03 14:14:06 2017 +0000
+++ b/kt_vfd.h	Tue Jul 11 23:41:56 2017 +0000
@@ -1,14 +1,26 @@
 /**
  * @bref VFD class definition
- * for GU140X16G-7040
+ * for GU256X128C-3900
  */
 #ifndef   __MBED_KT_VFD_H_
 #define   __MBED_KT_VFD_H_
 
-enum { // writing mode
-    MD1 = 0x01,
-    MD2,
-    MD3
+enum { // write mode
+    CURRENT = 0x00,
+    ALL     = 0x01
+} ;
+
+enum { // display mode
+    MODE1 = 0x01,   // overwrite
+    MODE2,          // horizontal scroll
+    MODE3           // vertical scroll
+} ;
+
+enum { // font size: 3900 only
+    FONT_SMALL  = 0x01,
+    FONT_MEDIUM = 0x02,
+    FONT_LARGE  = 0x03,
+    FONT_HUGE   = 0x04
 } ;
 
 class KT_VFD : public Stream
@@ -17,17 +29,22 @@
     KT_VFD(PinName rd, PinName wr,
            PinName d0, PinName d1, PinName d2, PinName d3,
            PinName d4, PinName d5, PinName d6, PinName d7) ;
-    void mode(unsigned char mode) ;
+    void write_mode(unsigned char mode) ;
+    void disp_mode(unsigned char mode) ;
+    void scroll_speed(unsigned char n) ;
+    void scroll_act(unsigned int w, unsigned int c, unsigned char s) ;
     void cls() ;
     void locate(unsigned int x, unsigned int y) ;
     void lf() ;
     void cr() ;
+    void font_size(unsigned char m) ; // 3900 only
+    void char_ext(unsigned char x, unsigned char y) ;
 
 protected:
     virtual int _putc(int c) ;
     virtual int _getc() ;
 
-    void writeByte(unsigned char value) ;
+    void write_byte(unsigned char value) ;
 
     DigitalOut _rd, _wr ;
     BusOut _d ;