include
#define uchar unsigned char
#define uint unsigned int
#define dianji P2
void delay_50us(uint t);
uchar F_zhuan[8]={0xE2,0xE6,0xE4,0xEC,0xE8,0xF8,0xF0,0xF2};
uchar B_zhuan[8]={0xF2,0xF0,0xF8,0xE8,0xEC,0xE4,0xE6,0xE2};
sbit key1 = P0^6;
sbit key2 = P0^7;
void zheng(void)
{
uint i;
if(key2==0)
{
for(i=0;i<8;i++)
{
dianji=B_zhuan;
delay_50us(100);
}
}
}
void fan(void)
{
uint i;
if(key1==0)
{
for(i=0;i<8;i++)
{
dianji=F_zhuan;
delay_50us(100);
}
}
}
void main()
{
while(1)
{
dianji=0x00;
if(key1==1)
{
while(!key1)
fan();
}
if(key2==1)
{
while(!key2)
zheng();
}
}
}
void delay_50us(uint t)
{
uchar j;
for(;t>0;t--)
{
for(j=19;j>0;j--);
}
}
哪错了,按键有时有效又时失灵
程序没有错,就是按键是,应有一个去抖动,就是延时一下,一般20MS
http://shop34182318.taobao.com/
https://shop436095304.taobao.com/?spm=a230r.7195193.1997079397.37.69fe60dfT705yr