74HC595 Nixie Driver

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
heroistired
Date:
Fri Jun 16 07:07:15 2017 +0000
Commit message:
Chen Huan; EEA of THU

Changed in this revision

Nixie/Nixie.cpp Show annotated file Show diff for this revision Revisions of this file
Nixie/Nixie.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r b5bd2bc3c14d Nixie/Nixie.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Nixie/Nixie.cpp	Fri Jun 16 07:07:15 2017 +0000
@@ -0,0 +1,58 @@
+/***************************************************************
+功能 : mbed的串联74HC595数码管驱动
+作者 : 陈欢 清华大学电机工程与应用电子技术系
+邮箱 : h-che14@mails.tsinghua.edu.cn OR heroistired@gmail.com
+声明 : 
+本程序仅供学习与交流使用,如需他用,须联系作者
+本程序可以随意更改,但须保留本信息页
+All rights reserved
+2017.6.16
+***************************************************************/
+
+#include "Nixie.h"
+
+Nixie::Nixie(PinName _DIO, PinName _SCK, PinName _RCK): DIO(_DIO), SCK(_SCK), RCK(_RCK)
+{
+    DIO = 0;
+    SCK = 0;
+    RCK = 0;
+}
+
+void Nixie::NixieShow(int Num, int Pos, bool WithDot)
+{
+    char c, num;
+    
+    if(WithDot)
+    {
+        num=NumCode[Num]-0x80;
+        for(c=0;c<8;c++)
+        {
+            SCK=0;
+            DIO=num&0x80;
+            num<<=1;
+            SCK=1;
+        }
+    }
+    else
+    {
+        num=NumCode[Num];
+        for(c=0;c<8;c++)
+        {
+            SCK=0;
+            DIO=num&0x80;
+            num<<=1;
+            SCK=1;
+        }
+    }
+      
+    num=SegBit[Pos];
+    for(c=0;c<8;c++)
+    {
+        SCK=0;
+        DIO=num&0x80;
+        num<<=1;
+        SCK=1;
+    }
+    RCK=0;
+    RCK=1;
+}
\ No newline at end of file
diff -r 000000000000 -r b5bd2bc3c14d Nixie/Nixie.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Nixie/Nixie.h	Fri Jun 16 07:07:15 2017 +0000
@@ -0,0 +1,32 @@
+#ifndef __NIXIE_H
+#define __NIXIE_H
+
+/***************************************************************
+功能 : mbed的串联74HC595数码管驱动
+作者 : 陈欢 清华大学电机工程与应用电子技术系
+邮箱 : h-che14@mails.tsinghua.edu.cn OR heroistired@gmail.com
+声明 : 
+本程序仅供学习与交流使用,如需他用,须联系作者
+本程序可以随意更改,但须保留本信息页
+All rights reserved
+2017.6.16
+***************************************************************/
+
+#include "mbed.h"
+
+const char NumCode[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
+const char SegBit[]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};
+
+//数码管类 
+class  Nixie
+{
+    public:
+        Nixie(PinName _DIO, PinName _SCK, PinName _RCK);
+        void NixieShow(int Num, int Pos, bool WithDot);
+  
+    protected:
+        DigitalOut DIO;
+        DigitalOut SCK;
+        DigitalOut RCK;
+};
+#endif
\ No newline at end of file
diff -r 000000000000 -r b5bd2bc3c14d main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Jun 16 07:07:15 2017 +0000
@@ -0,0 +1,29 @@
+#include "mbed.h"
+#include "Nixie.h"
+
+//数码管驱动示例
+
+Nixie myNixie(PA_0,PA_1,PA_4); //声明数码管类 依次是 DIO SCK RCK 任意GPIO脚都可以
+ 
+int pos = 0, num = 0;
+bool WithDot = false;
+int main() 
+{
+    while(1) 
+    {
+        wait(0.15);
+        myNixie.NixieShow(num,pos,WithDot);//在数码管上显示数字 num 要显示的数字 pos 数字显示的位置 从左到右 0-7 WithDot 是否显示小数点
+        num++;
+        pos++;
+        if(num == 10)
+        {
+            num = 0;
+            if(WithDot)
+                WithDot = false;
+            else
+                WithDot = true;
+        }
+        if(pos == 8)
+            pos = 0;
+    }
+}
diff -r 000000000000 -r b5bd2bc3c14d mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri Jun 16 07:07:15 2017 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/mbed_official/code/mbed/builds/0f02307a0877
\ No newline at end of file