32dot x 16dot LED matrix display driving library.

Dependents:   KP1632D_char_demo KP1632D_Gsens_demo KP1632D_move_mbed_demo

Files at this revision

API Documentation at this revision

Comitter:
morita
Date:
Sat May 31 14:26:47 2014 +0000
Commit message:
Fix first program.;

Changed in this revision

CG.h Show annotated file Show diff for this revision Revisions of this file
kp1632d.cpp Show annotated file Show diff for this revision Revisions of this file
kp1632d.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/CG.h	Sat May 31 14:26:47 2014 +0000
@@ -0,0 +1,109 @@
+#ifndef MBED_CG_H
+#define MBED_CG_H
+
+const uint8_t CG5x7[16*6][8]={
+//20-2F
+{0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0},
+{0x4,0x4,0x4,0x4,0x0,0x0,0x4,0x0},
+{0xa,0xa,0xa,0x0,0x0,0x0,0x0,0x0},
+{0xa,0xa,0x1f,0xa,0x1f,0xa,0xa,0x0},
+{0x4,0xf,0x14,0xe,0x5,0x1e,0x4,0x0},
+{0x18,0x19,0x2,0x4,0x8,0x13,0x3,0x0},
+{0xc,0x12,0x14,0x8,0x15,0x12,0xd,0x0},
+{0xc,0x4,0x8,0x0,0x0,0x0,0x0,0x0},
+{0x2,0x4,0x8,0x8,0x8,0x4,0x2,0x0},
+{0x8,0x4,0x2,0x2,0x2,0x4,0x8,0x0},
+{0x0,0x4,0x15,0xe,0x15,0x4,0x0,0x0},
+{0x0,0x4,0x4,0x1f,0x4,0x4,0x0,0x0},
+{0x0,0x0,0x0,0x0,0xc,0x4,0x8,0x0},
+{0x0,0x0,0x0,0x1f,0x0,0x0,0x0,0x0},
+{0x0,0x0,0x0,0x0,0x0,0xc,0xc,0x0},
+{0x0,0x1,0x2,0x4,0x8,0x10,0x0,0x0},
+//30-3F
+{0xe,0x11,0x11,0x11,0x11,0x11,0xe,0},
+{0x4,0xc,0x4,0x4,0x4,0x4,0xe,0},
+{0xe,0x11,0x1,0x2,0x4,0x8,0x1f,0},
+{0x1f,0x2,0x4,0x2,0x1,0x11,0xe,0},
+{0x2,0x6,0xa,0x12,0x1f,0x2,0x2,0},
+{0x1f,0x10,0x1e,0x1,0x1,0x11,0xe,0},
+{0x6,0x8,0x10,0x1e,0x11,0x11,0xe,0},
+{0x1f,0x1,0x2,0x4,0x8,0x8,0x8,0},
+{0xe,0x11,0x11,0xe,0x11,0x11,0xe,0},
+{0xe,0x11,0x11,0xf,0x1,0x2,0xc,0},
+{0x0,0xc,0xc,0x0,0xc,0xc,0x0,0},
+{0x0,0xc,0xc,0x0,0xc,0x4,0x8,0},
+{0x2,0x4,0x8,0x10,0x8,0x4,0x2,0},
+{0x0,0x0,0x1f,0x0,0x1f,0x0,0x0,0},
+{0x8,0x4,0x2,0x1,0x2,0x4,0x8,0},
+{0xe,0x11,0x1,0x2,0x4,0x0,0x4,0},
+//40-4F
+{0xe,0x11,0x1,0xd,0x15,0x15,0xe,0},
+{0xe,0x11,0x11,0x11,0x1f,0x11,0x11,0},
+{0x1e,0x11,0x11,0x1e,0x11,0x11,0x1e,0},
+{0xe,0x11,0x10,0x10,0x10,0x11,0xe,0},
+{0x1c,0x12,0x11,0x11,0x11,0x12,0x1c,0},
+{0x1f,0x10,0x10,0x1e,0x10,0x10,0x1f,0},  //<--------?
+{0x1f,0x10,0x10,0x1e,0x10,0x10,0x10,0},
+{0xe,0x11,0x10,0x17,0x11,0x11,0xf,0},
+{0x11,0x11,0x11,0x1f,0x11,0x11,0x11,0},
+{0xe,0x4,0x4,0x4,0x4,0x4,0xe,0},
+{0x7,0x2,0x2,0x2,0x2,0x12,0xc,0},
+{0x11,0x12,0x14,0x18,0x14,0x12,0x11,0},
+{0x10,0x10,0x10,0x10,0x10,0x10,0x1f,0},
+{0x11,0x1b,0x15,0x15,0x11,0x11,0x11,0},
+{0x11,0x11,0x19,0x15,0x13,0x11,0x11,0},
+{0xe,0x11,0x11,0x11,0x11,0x11,0xe,0},
+//50-5F
+{0x1e,0x11,0x11,0x1e,0x10,0x10,0x10,0},
+{0xe,0x11,0x11,0x11,0x15,0x12,0xd,0},
+{0x1e,0x11,0x11,0x1e,0x14,0x12,0x11,0},
+{0xf,0x10,0x10,0xe,0x1,0x1,0x1e,0},
+{0x1f,0x4,0x4,0x4,0x4,0x4,0x4,0},
+{0x11,0x11,0x11,0x11,0x11,0x11,0xe,0},
+{0x11,0x11,0x11,0x11,0x11,0xa,0x4,0},
+{0x11,0x11,0x11,0x15,0x15,0x15,0xa,0},
+{0x11,0x11,0xa,0x4,0xa,0x11,0x11,0},
+{0x11,0x11,0x11,0xa,0x4,0x4,0x4,0},
+{0x1f,0x1,0x2,0x4,0x8,0x10,0x1f,0},
+{0xe,0x8,0x8,0x8,0x8,0x8,0xe,0},
+{0x11,0xa,0x1f,0x4,0x1f,0x4,0x4,0},
+{0xe,0x2,0x2,0x2,0x2,0x2,0xe,0},
+{0x4,0xa,0x11,0x0,0x0,0x0,0x0,0},
+{0x0,0x0,0x0,0x0,0x0,0x0,0x1f,0},
+//60-6F
+{0x8,0x4,0x2,0x0,0x0,0x0,0x0,0},
+{0x0,0x0,0xe,0x1,0xf,0x11,0xf,0},
+{0x10,0x10,0x16,0x19,0x11,0x11,0x1e,0},
+{0x0,0x0,0xe,0x10,0x10,0x11,0xe,0},
+{0x1,0x1,0xd,0x13,0x11,0x11,0xf,0},
+{0x0,0x0,0xe,0x11,0x1f,0x10,0xe,0},
+{0x6,0x9,0x8,0x1c,0x8,0x8,0x8,0},
+{0x0,0xf,0x11,0x11,0xf,0x1,0xe,0},
+{0x10,0x10,0x16,0x19,0x11,0x11,0x11,0},
+{0x4,0x0,0xc,0x4,0x4,0x4,0xe,0},
+{0x2,0x0,0x6,0x2,0x2,0x12,0xc,0},
+{0x10,0x10,0x12,0x14,0x18,0x14,0x12,0},
+{0xc,0x4,0x4,0x4,0x4,0x4,0xe,0},
+{0x0,0x0,0x1a,0x15,0x15,0x11,0x11,0},
+{0x0,0x0,0x16,0x19,0x11,0x11,0x11,0},
+{0x0,0x0,0xe,0x11,0x11,0x11,0xe,0},
+//70-7F
+{0x0,0x0,0x1e,0x11,0x1e,0x10,0x10,0},
+{0x0,0x0,0xd,0x13,0xf,0x1,0x1,0},
+{0x0,0x0,0x16,0x19,0x10,0x10,0x10,0},
+{0x0,0x0,0xe,0x10,0xe,0x1,0x1e,0},
+{0x8,0x8,0x1c,0x8,0x8,0x9,0x6,0},
+{0x0,0x0,0x11,0x11,0x11,0x13,0xd,0},
+{0x0,0x0,0x11,0x11,0x11,0xa,0x4,0},
+{0x0,0x0,0x11,0x11,0x15,0x15,0xa,0},
+{0x0,0x0,0x11,0xa,0x4,0xa,0x11,0},
+{0x0,0x0,0x11,0x11,0xf,0x1,0xe,0},
+{0x0,0x0,0x1f,0x2,0x4,0x8,0x1f,0},
+{0x2,0x4,0x4,0x8,0x4,0x4,0x2,0},
+{0x4,0x4,0x4,0x4,0x4,0x4,0x4,0},
+{0x8,0x4,0x4,0x2,0x4,0x4,0x8,0},
+{0x0,0x4,0x2,0x1f,0x2,0x4,0x0,0},
+{0x0,0x4,0x8,0x1f,0x8,0x4,0x0,0}
+};
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/kp1632d.cpp	Sat May 31 14:26:47 2014 +0000
@@ -0,0 +1,118 @@
+#include "mbed.h"
+#include "kp1632d.h"
+#include "CG.h"
+
+KP1632D::KP1632D(PinName BD7851_COM, PinName BD7851_CA, PinName BD7851_CB, PinName BD7851_CLK, PinName BD7851_LT, PinName BD7851_ENB, uint16_t period) :
+    _BD7851_COM(BD7851_COM), _BD7851_CA(BD7851_CA), _BD7851_CB(BD7851_CB), _BD7851_CLK(BD7851_CLK), _BD7851_LT(BD7851_LT), _BD7851_ENB(BD7851_ENB) {
+
+    tranfer_sw=false;
+    _BD7851_ENB=1;
+    for(uint8_t i=0;i<16;i++)pbuf[i].i32=0;
+    _ticker.attach_us(this,&KP1632D::disp_isr, period);//defalut value (int=5KHz frame rate=300Hz)
+    wait_us(200*3);
+    _BD7851_ENB=0;
+    xp=0;
+    yp=0;
+}
+
+void KP1632D::disp_isr(){
+    static uint8_t pos=0;
+    static uint16_t ptn,ssr_A=0,ssr_B=0,ssr_COM=0;
+    uint8_t i;
+ 
+    if(pos==0)ptn=0x8000;
+    ssr_A=pbuf[pos].i16[0]; ssr_B=pbuf[pos].i16[1]; ssr_COM=ptn;
+    for(i=0;i<16;i++){
+        _BD7851_CA=(ssr_A & 0x8000)==0x8000;
+        _BD7851_CB=(ssr_B & 0x8000)==0x8000;
+        _BD7851_COM=ssr_COM & 1;
+        ssr_COM >>= 1;
+        _BD7851_CLK=1;
+        ssr_A <<= 1;
+        _BD7851_CLK=0;
+        ssr_B <<= 1;
+    }
+    _BD7851_LT=1;
+    ptn >>= 1;
+    _BD7851_LT=0;
+    pos = (pos+1) & 15;
+    if((pos==0) && (tranfer_sw)){
+        tranfer_sw=false;
+        memcpy(pbuf,abuf,sizeof(pbuf));//4byte 16line
+    }
+}
+
+void KP1632D::pset_XY(uint8_t X , uint8_t Y){
+  if((X>31)||(Y>15))return;
+  pbuf[Y].i8[X>>3] |= 1<<(X & 7);
+}
+
+void KP1632D::preset_XY(uint8_t X , uint8_t Y){
+  if((X>31)||(Y>15))return;
+  pbuf[Y].i8[X>>3] &= ~(1<<(X & 7));
+}
+
+void KP1632D::posline_X(uint8_t X , uint8_t pos){
+  uint8_t i;
+
+  if((X>31)||(pos>15))return;
+  for(i=0;i<16;i++){
+    if(i<=pos)pset_XY(X,i); else preset_XY(X,i);
+  }
+}
+
+void KP1632D::cls(){
+    for(uint8_t i=0;i<16;i++)pbuf[i].i32=0;
+    xp=0;
+    yp=0;
+}
+
+void KP1632D::gotoxy(uint8_t x,uint8_t y){
+    xp=x; if(xp>4)xp=4;
+    yp=y; if(yp>1)yp=1;
+}
+
+int KP1632D::_putc(int value) {
+    uint8_t c,i,y;
+    
+    if(value==13){
+        xp=0;
+        return value;
+    }
+    if(yp>1)yp=1;
+    if(value==10){
+        yp++;
+        if(yp>1){
+            for(i=0;i<8;i++){
+                pbuf[i].i32=pbuf[i+8].i32;
+                pbuf[i+8].i32=0;
+            }
+            yp=1;
+        }
+        return value;
+    }
+
+    if(xp>4){
+        xp=0; yp++;
+        if(yp>1){
+            for(i=0;i<8;i++){
+                pbuf[i].i32=pbuf[i+8].i32;
+                pbuf[i+8].i32=0;
+            }
+            yp=1;
+        }
+    }
+    if((value>=0x20)&&(value<0x80)){
+        c=value-0x20;
+        y=yp*8;
+        for(i=0;i<8;i++){
+            pbuf[y+i].i32 |= (uint32_t)CG5x7[c][i]<<(4-xp)*6;
+        }
+        xp++;
+    }
+    return value;
+}
+
+int KP1632D::_getc() {
+    return -1;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/kp1632d.h	Sat May 31 14:26:47 2014 +0000
@@ -0,0 +1,35 @@
+#ifndef MBED_KP1632D_H
+#define MBED_KP1632D_H
+
+#include "mbed.h"
+
+class KP1632D : public Stream {
+public:
+
+union _buf{
+  uint32_t i32;
+  uint16_t i16[2];
+  uint8_t  i8[4];
+};
+
+typedef union _buf flame_buf;
+
+    KP1632D(PinName BD7851_COM, PinName BD7851_CA, PinName BD7851_CB, PinName BD7851_CLK, PinName BD7851_LT, PinName BD7851_ENB=NC, uint16_t period=200);
+    void pset_XY(uint8_t X , uint8_t Y);
+    void preset_XY(uint8_t X , uint8_t Y);
+    void posline_X(uint8_t X , uint8_t pos);
+    void cls();
+    void gotoxy(uint8_t x,uint8_t y);
+    flame_buf pbuf[16];
+    flame_buf abuf[16];
+    bool tranfer_sw;
+    
+protected:
+    DigitalOut _BD7851_COM, _BD7851_CA, _BD7851_CB, _BD7851_CLK, _BD7851_LT, _BD7851_ENB;
+    Ticker _ticker;
+    void disp_isr();
+    virtual int _getc();
+    virtual int _putc(int value);
+    uint8_t xp,yp;
+};
+#endif