#include <at89x52.h>
char table[]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};
sbit btn1=P2^0;
sbit btn2=P2^1;
int k=-1;
void delay_1ms(int k)
{
int i,j;
for(i=0;i<k;i++)
for(j=0;j<114;j++)
;
}
main()
{
while(1)
{
if(btn1==0)
{
delay_1ms(20);while(btn1!=1);delay_1ms(20);
k=k+1;
if(k>7)
k=0;
}
if(btn2==0)
{
delay_1ms(20);while(btn2!=1);delay_1ms(20);
k=k-1;
if(k<0)
k=7;
}
if(k==0){P1=~table[k];}
if(k==1){P1=~table[k];}
if(k==2){P1=~table[k];}
if(k==3){P1=~table[k];}
if(k==4){P1=~table[k];}
if(k==5){P1=~table[k];}
if(k==6){P1=~table[k];}
if(k==7){P1=~table[k];}
}
}
沒有留言:
張貼留言