|
74HC595显示多个数码管- #include <reg52.h>
- #include <intrins.h>
- #define uint unsigned int
- #define uchar unsigned char
- sbit ClOCK = P2^0; //HC595第11脚,串行时钟输入端
- sbit DATA = P2^1; //HC595第14脚,串行数据输入端
- sbit LATCH = P2^2; //HC595第12脚,输出锁存脉冲输入端
- //定义共阴数码管段码0-9
- uchar code segment[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x27,0x7F,0x6F};
- //串行输出一个字节
- void HC595(uchar word)
- {
- uchar i;
- for (i=8;i>0;i--)
- {
- ClOCK=0;
- DATA=0x80&word;
- word=_crol_(word,1);
- ClOCK=1;
- _nop_();
- }
- }
- void display(uchar S1, uchar S2, uchar S3, uchar S4, uchar S5, uchar S6)
- {
- HC595(segment[S6]);
- HC595(segment[S5]);
- HC595(segment[S4]);
- HC595(segment[S3]);
- HC595(segment[S2]);
- HC595(segment[S1]);
- LATCH=1;
- _nop_();
- LATCH=0;
- }
- void main()
- {
- LATCH = 0;
- while(1)
- display(2, 0, 1, 3, 1, 4);
- }
复制代码
|
|