單片機(jī)控制的計(jì)數(shù)簡(jiǎn)單程序
#include
unsigned char c,i,k,p;
sbit p10=P1^0;
unsigned char s[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
main()
{unsigned char key1,key2;
unsigned char i,k;
void delay();
void delay2();
unsigned char getkey();
while(1){
delay2();//消除程序執(zhí)行太快 引起的多次判斷
key1=0;key2=0;
key1=getkey();
if(key1==0) continue;//沒有鍵按下 繼續(xù)循環(huán)檢測(cè)
delay();
key2=getkey();
if(key1==key2) {P2=s[i];P3=s[k];k++;if(k==10) {k=0;i++;if(i==10)i=0;}}
void delay()
{unsigned char a,b;
for(a=20;a>0;a--)
for(b=248;b>0;b--)
{}
}
unsigned char getkey()
{if(p10==0) {return 1;}
else return 0;}
void delay2()
{unsigned char a,b,c;
for(c=20;c>0;c--)
for(b=248;b>0;b--)
{}}
評(píng)論