CC2530————非中断方式实现按键控制LED灯

#include<iocc2530.h>
#define uchar unsigned char
#define uint unsigned int
void Initial(void)
{
P1SEL&=~0X39;
P1DIR|=0X39;
P1SEL&=~0X04;
P1DIR&=~0X04;
P1INP&=~0X04;
P1&=~0X39;
}
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()
{
uchar count=0;
uchar stat[]={0x20,0x01,0x10,0x08};
Initial();
while(1)
{
if(P1_2==0)
{
switch(count)
{
case 0:P1=stat[count];Delay(1200);break;
case 1:P1=stat[count];Delay(1200);break;
case 2:P1=stat[count];Delay(1200);break;
case 3:P1=stat[count];Delay(1200);break;
}
if(count<=3)
count++;
else
count=0;
}
else
{
P1=stat[count];
Delay(1200);
}
}
}

猜你喜欢

转载自blog.csdn.net/News53231323/article/details/113186787