试题
Main.c
#include <ioCC2530.h>
#define uint16 unsigned int
#define uint8 unsigned char
uint8 ledArray[2] = {0x05, 0x06};
uint8 ledCount;
uint16 clickCount = 0;
void Init()
{
P1SEL |= ~0x07;
P1DIR |= ~0xFF;
P1DIR |= 0x07;
P1 = 0x04;
}
void DelayMs(uint16 ms)
{
for(uint16 i = 0; i < ms; i++)
for(uint16 j = 0; j < 535; j++);
}
void main(void)
{
uint8 cycleCount = 200;
Init();
while(1)
{
while(cycleCount > 0)
{
DelayMs(10);
if(P1_2 == 0)
{
DelayMs(10);
if(P1_2 == 0)
{
++clickCount;
while(P1_2 == 0);
break;
}
}
--cycleCount;
}
cycleCount = 200;
if(clickCount % 2 != 0)
{
P1 = ledArray[ledCount];
if(ledCount < 1) ++ledCount;
else ledCount = 0;
}
else
{
P1 = 0x04;
}
}
}
演示视频
点击打开