#include <reg51.h> #include <intrins.h>
sbit LED0 = P1^0; sbit LED1 = P1^1; sbit LED2 = P1^2; sbit LED3 = P1^3; sbit LED4 = P1^4; sbit JDQ1 = P3^2; sbit JDQ2 = P2^4;
sbit beep = P2^3;
sbit mode = P3^3;sbit up = P3^4; sbit down = P3^5; sbit star = P3^6;sbit wei = P3^7;
void delay(unsigned int z); //函数声名void led_disp(unsigned int x);void init();unsigned char D5,D4,D3,D2,D1,flag;unsigned int t,a=20;
//此表为 LED 的字模, 共阳数码管 0-9
//unsigned char code Disp_Tab[] = {0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}; //段码控制unsigned char code Disp_Tab[] = {0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xa3,0xc8,0x8e}; //段码控制0\1\2\3\4\5\6\7\8\9\o\n\f/************主函数**********************/ main(){ unsigned int disp_val=00000; init(); //初始化子程序 flag=0;if(!star) flag=1; led_disp(disp_val);
if(!star) //*若按键0按下 { delay(10); //*延时10毫秒 这一段就是防抖动, if(!star) //*若还是按下 { while(!star) { if(star)//如果拿起了 { break; } } flag=1;//置标示位,说明按键已经经历了按下和抬起,可以做按键处理了 }
while(1) { if(t==a) { t=0; disp_val++; if(disp_val==100000) { disp_val=00000; } D1 = disp_val/100000; D2 = (disp_val%10000)/1000; D3 = (disp_val%1000)/100; D4 = (disp_val%100)/10; D5 = disp_val%10; } led_disp(disp_val); }
}
// if (!up) a=a+20; /* if (!down) a=a-20; while(1) { if(t==a) { t=0; disp_val++; if(disp_val==100000) { disp_val=00000; } D1 = disp_val/100000; D2 = (disp_val%10000)/1000; D3 = (disp_val%1000)/100; D4 = (disp_val%100)/10; D5 = disp_val%10; } led_disp(disp_val); }*/ // } /*unsigned int i;