最近一直比较迷惑按键和数码管的联系,用一个数码管实现从0-9 想让各位看一下 我这个代码哪里出错了,理顺一下头绪 谢谢
#include<reg52.h> #define uchar unsigned char #define uint unsigned int sbit PH595RCLK=P2^5; sbit PH595SRCLK=P2^6; sbit PH595SER=P2^7; sbit s5=P3^0; uchar smgduan[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F}; uchar a,b; void DelayMs(uint n) { uchar j; while(n--) { for(j=0;j<113;j++); } } void send595(uchar date) { uchar i; for(i=0;i<8;i++) { if(date&0x80) PH595SER=1; else PH595SER=0; PH595SRCLK=0; PH595SRCLK=1; PH595SRCLK=0; date=date<<1; } } void smginit() { send595(0x00); send595(0x00); PH595RCLK=0; PH595RCLK=1; } void KeyScan() { if(s5==0) { DelayMs(10); if(s5==0) { a=1; } while(!s5); } } void main() { smginit(); while(1) { if(a==1) { a=0; if(b==9) b=0; else b++; send595(0xfe); send595(smgduan[b]); PH595RCLK=0; PH595RCLK=1; } } }