[51]简单按键计数程序

#include
unsigned int led[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e}; 
unsigned char ID;
sbit k1 = P3^4;     
void delay(unsigned int xms)                                                                                                           //延时程序
{
    unsigned int x,y;
    for(x=xms;x>0;x--)
        for(y=110;y>0;y--);
}
void main()
{       
P2=0x07;
ID=0;
    while(1)
    {
        if(k1==0)
        {
            delay(100);          
            if(k1==0)        
            {
                ID++;
                while(!k1);   
            }
        }
    P0=led[ID];
    if(ID==10)ID=0;
    }
}

你可能感兴趣的:(硬件开发)