单片机按键数码管程序显示0到99
sbit p1_0=0x90; sfr p2=0xa0; sfr p3=0xb0; void delay (unsigned int);
code unsigned char tab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}; void main (void) { unsigned int xssj; p1_0=1; xssj=0; while(1) { do{
p2 = tab[ xssj%10 ]; p3 = tab[ xssj/10 ]; if(p1_0==0) {delay(10); xssj++; if(xssj==99) {xssj=0;} delay(10); do{;}
while(p1_0!=1); } }
while (xssj!=100); }
}
void delay (unsigned int n) {
unsigned int x,y; for (x=0;x sbit p1_0=0x90; sbit p1_1=0x91; sbit p1_2=0x92; sbit p1_3=0x93; sbit p1_5=0x95; void delay (unsigned int); void main (void) { p1_0=1; p1_1=1; p1_2=1; p1_3=1; p1_4=1; p1_5=1; while(1) { unsigned int i; p1_0=0; //南红 p1_5=0; //东黄 for(i=0;i<5;i++) //延时 { p1_5=0; delay(200); p1_5=1; delay(200); } //东绿 p1_4=0; delay(1000); p1_0=1; p1_4=1; p1_3=0; p1_2=0; //东红 //南黄 for(i=0;i<5;i++) { p1_2=0; delay(200); p1_2=1; delay(200); } p1_1=0; //南绿 p1_3=0; //东红 delay(1200); p1_1=1; p1_3=1; } } void delay (unsigned int n) {unsigned int x, y; for (x=0 ; x sbit p1_0=0x90; sbit p1_4=0x94; sbit p1_1=0x91; sbit p1_5=0x95; sbit p1_2=0x92; sbit p1_6=0x96; void delay (unsigned int); void main (){ p1_0=1; p1_4=1; p1_1=1; p1_5=1; p1_2=1; p1_6=1; while(1){ if(p1_0==0){ delay(10); if(p1_0==0){ p1_4=0; do{ do{;} while(p1_0==0); delay(10); }while(p1_0==0); } } p1_4=1; if(p1_1==0){ delay(10); if(p1_1==0){ p1_5=0; do{ do{;} while(p1_1==0); delay(10); }while(p1_1==0); } } p1_5=1; if(p1_2==0){ delay(10); if(p1_2==0){ p1_6=0; do{ do{;} while(p1_2==0); delay(10); }while(p1_2==0); 因篇幅问题不能全部显示,请点此查看更多更全内容