新聞中心

LED顯示計數(shù)

作者: 時間:2016-11-21 來源:網(wǎng)絡(luò) 收藏
電路圖:
程序?qū)崿F(xiàn)功能:
每次按下芯片右下角的按鍵,LED顯示按鍵按下的次數(shù),代碼如下:
#include
sbit P3_7=P3^7;
unsigned char code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
char count;
void delay(unsigned int time){
unsigned int j = 0;
for(;time>0;time--)
for(j=0;j<125;j++);
}
void main(void) {
count=0; //計數(shù)器賦初值
P0=table[count/10]; //P0口顯示初值
P2=table[count]; //P2口顯示初值
while(1) { //進(jìn)入無限循環(huán)
if(P3_7==0){ //軟件消抖,檢測按鍵是否壓下
delay(10);
if(P3_7==0) { //若按鍵壓下
count++; //計數(shù)器增1
if(count==100) //判斷循環(huán)是否超限
count=0;
P0=table[count/10]; //P0口輸出顯示
P2=table[count]; //P2口輸出顯示
while(P3_7==0); //等待按鍵松開,防止連續(xù)計數(shù)
}
}
}
}



關(guān)鍵詞: LED顯示計

評論


技術(shù)專區(qū)

關(guān)閉