#include<reg52.h> #define uchar unsigned char #define uint unsigned int sbit key1=P3^0; sbit key2=P3^1; sbit key3=P3^2; sbit key4=P3^3; sbit PH595SRCLK=P2^6; sbit PH595RCLK=P2^5; sbit PH595SER=P2^7; uchar code smgwei[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f}; uchar code smgduan[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,0x77,0x7C,0x39,0x5E,0x79,0x71,0x76,0x00}; void anjian1(); void anjian2(); void anjian3(); void anjian4(); void DelayMs(uint n) { uchar j; while(n--) for(j=0;j<113;j++); } void send595(uchar dat) { if(dat&0x80) PH595SER=1; else PH595SER=0; PH595SRCLK=0; PH595SRCLK=1; PH595SRCLK=0; dat=dat<<1; } void smgqingling() { send595(0x00); send595(0x00); PH595RCLK=0; PH595RCLK=1; } void keyscan() { if(key1==0) { DelayMs(10); if(key1==0) { anjian1(); } while(!key1); } else if(key2==0) { DelayMs(10); if(key2==0) { anjian2(); } while(!key2); } else if(key3==0) { DelayMs(10); if(key3==0) { anjian3(); } while(!key3); } else if(key4==0) { DelayMs(10); if(key4==0) { anjian4(); } while(!key4); } } void anjian1() { send595(smgwei[0]); send595(smgduan[1]); PH595RCLK=0; PH595RCLK=1; } void anjian2() { send595(smgwei[1]); send595(smgduan[2]); PH595RCLK=0; PH595RCLK=1; } void anjian3() { send595(smgwei[2]); send595(smgduan[3]); PH595RCLK=0; PH595RCLK=1; } void anjian4() { send595(smgwei[3]); send595(smgduan[4]); PH595RCLK=0; PH595RCLK=1; } void main() { while(1) { smgqingling(); keyscan(); } }
用小红版做这个独立按键显示1-4 自我感觉没有什么差错,但是在板子上显示不出来,请求各位大神看一下是哪里出现了问题,谢谢!