CC2530-———非中断方式实现按键中断2

#include<iocc2530.h>
#define uchar unsigned char
#define uint unsigned int
#define LED1 P1_5
#define LED2 P1_0
#define LED3 P1_3
#define LED4 P1_4
uint count=0;
void Initial(void)
{
P1SEL&=~0x39;
P1DIR|=0x39;
P1SEL&=~0x04;
P1DIR&=~0x04;
P1INP&=~0x04;
P1INP&=~0x40;
P1&=~0x39;
}
uchar KeyScan(void)
{
if(P1_20)
{
if(P1_2
0)
{
while(!P1_2)
return 1;
}
}
return 0;
}
void Delay(uint time)
{
uint i;
uchar j;
for(i=0;i<time;i++)
for(j=0;j<240;j++)
{
asm(“NOP”);
asm(“NOP”);
asm(“NOP”);
}
}
main()
{
Initial();
while(1)
{
if(KeyScan()==1)
{
count++;
if(count<=4)
{
switch(count)
{
case 1:LED1=!LED1;break;
case 2:LED2=!LED2;break;
case 3:LED3=!LED3;break;
case 4:LED4=!LED4;break;
}
}
if(count>4)
{
LED1=LED2=LED3=LED4=0;
count=0;
}
}

}

}

猜你喜欢

转载自blog.csdn.net/News53231323/article/details/113186769
今日推荐