YX ZHANG
/
NiXie
hello Nixie
Fork of NiXie by
Nixie/Nixie.cpp@3:f5ff314d5a4c, 2017-10-09 (annotated)
- Committer:
- zhangyx
- Date:
- Mon Oct 09 16:31:25 2017 +0000
- Revision:
- 3:f5ff314d5a4c
- Parent:
- 2:57e4a4136076
demo
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
heroistired | 0:b5bd2bc3c14d | 1 | /*************************************************************** |
heroistired | 0:b5bd2bc3c14d | 2 | 功能 : mbed的串联74HC595数码管驱动 |
heroistired | 0:b5bd2bc3c14d | 3 | 作者 : 陈欢 清华大学电机工程与应用电子技术系 |
heroistired | 0:b5bd2bc3c14d | 4 | 邮箱 : h-che14@mails.tsinghua.edu.cn OR heroistired@gmail.com |
heroistired | 0:b5bd2bc3c14d | 5 | 声明 : |
heroistired | 0:b5bd2bc3c14d | 6 | 本程序仅供学习与交流使用,如需他用,须联系作者 |
heroistired | 0:b5bd2bc3c14d | 7 | 本程序可以随意更改,但须保留本信息页 |
heroistired | 0:b5bd2bc3c14d | 8 | All rights reserved |
heroistired | 0:b5bd2bc3c14d | 9 | 2017.6.16 |
heroistired | 0:b5bd2bc3c14d | 10 | ***************************************************************/ |
heroistired | 0:b5bd2bc3c14d | 11 | |
heroistired | 0:b5bd2bc3c14d | 12 | #include "Nixie.h" |
heroistired | 0:b5bd2bc3c14d | 13 | |
heroistired | 0:b5bd2bc3c14d | 14 | Nixie::Nixie(PinName _DIO, PinName _SCK, PinName _RCK): DIO(_DIO), SCK(_SCK), RCK(_RCK) |
heroistired | 0:b5bd2bc3c14d | 15 | { |
heroistired | 0:b5bd2bc3c14d | 16 | DIO = 0; |
heroistired | 0:b5bd2bc3c14d | 17 | SCK = 0; |
heroistired | 0:b5bd2bc3c14d | 18 | RCK = 0; |
heroistired | 0:b5bd2bc3c14d | 19 | } |
heroistired | 0:b5bd2bc3c14d | 20 | |
zhangyx | 2:57e4a4136076 | 21 | void Nixie::NixieShowNumber(int Number, int dot) |
zhangyx | 1:ad106a887eb8 | 22 | { |
zhangyx | 1:ad106a887eb8 | 23 | int8_t pos = 7; |
zhangyx | 1:ad106a887eb8 | 24 | do{ |
zhangyx | 2:57e4a4136076 | 25 | NixieShow(Number%10,pos,dot==pos); |
zhangyx | 1:ad106a887eb8 | 26 | Number /= 10; |
zhangyx | 1:ad106a887eb8 | 27 | pos --; |
zhangyx | 1:ad106a887eb8 | 28 | }while(Number != 0 && pos >= 0); |
zhangyx | 1:ad106a887eb8 | 29 | } |
zhangyx | 1:ad106a887eb8 | 30 | |
heroistired | 0:b5bd2bc3c14d | 31 | void Nixie::NixieShow(int Num, int Pos, bool WithDot) |
heroistired | 0:b5bd2bc3c14d | 32 | { |
heroistired | 0:b5bd2bc3c14d | 33 | char c, num; |
heroistired | 0:b5bd2bc3c14d | 34 | |
heroistired | 0:b5bd2bc3c14d | 35 | if(WithDot) |
heroistired | 0:b5bd2bc3c14d | 36 | { |
heroistired | 0:b5bd2bc3c14d | 37 | num=NumCode[Num]-0x80; |
heroistired | 0:b5bd2bc3c14d | 38 | for(c=0;c<8;c++) |
heroistired | 0:b5bd2bc3c14d | 39 | { |
heroistired | 0:b5bd2bc3c14d | 40 | SCK=0; |
heroistired | 0:b5bd2bc3c14d | 41 | DIO=num&0x80; |
heroistired | 0:b5bd2bc3c14d | 42 | num<<=1; |
heroistired | 0:b5bd2bc3c14d | 43 | SCK=1; |
heroistired | 0:b5bd2bc3c14d | 44 | } |
heroistired | 0:b5bd2bc3c14d | 45 | } |
heroistired | 0:b5bd2bc3c14d | 46 | else |
heroistired | 0:b5bd2bc3c14d | 47 | { |
heroistired | 0:b5bd2bc3c14d | 48 | num=NumCode[Num]; |
heroistired | 0:b5bd2bc3c14d | 49 | for(c=0;c<8;c++) |
heroistired | 0:b5bd2bc3c14d | 50 | { |
heroistired | 0:b5bd2bc3c14d | 51 | SCK=0; |
heroistired | 0:b5bd2bc3c14d | 52 | DIO=num&0x80; |
heroistired | 0:b5bd2bc3c14d | 53 | num<<=1; |
heroistired | 0:b5bd2bc3c14d | 54 | SCK=1; |
heroistired | 0:b5bd2bc3c14d | 55 | } |
heroistired | 0:b5bd2bc3c14d | 56 | } |
heroistired | 0:b5bd2bc3c14d | 57 | |
heroistired | 0:b5bd2bc3c14d | 58 | num=SegBit[Pos]; |
heroistired | 0:b5bd2bc3c14d | 59 | for(c=0;c<8;c++) |
heroistired | 0:b5bd2bc3c14d | 60 | { |
heroistired | 0:b5bd2bc3c14d | 61 | SCK=0; |
heroistired | 0:b5bd2bc3c14d | 62 | DIO=num&0x80; |
heroistired | 0:b5bd2bc3c14d | 63 | num<<=1; |
heroistired | 0:b5bd2bc3c14d | 64 | SCK=1; |
heroistired | 0:b5bd2bc3c14d | 65 | } |
heroistired | 0:b5bd2bc3c14d | 66 | RCK=0; |
heroistired | 0:b5bd2bc3c14d | 67 | RCK=1; |
heroistired | 0:b5bd2bc3c14d | 68 | } |