CC2530开发试题(四)

试题

代码部分

#include <ioCC2530.h>

typedef unsigned int uint16;
typedef unsigned char uint8;

uint8 ledLightIndex;
uint8 ledRegister[4] = {0x06, 0x05, 0x14,0xC};
uint8 running;
uint16 checkKeyICycle = 2000;

void Init_Port()
{
    P1SEL &= ~0xFF;
    P1DIR |= 0xFF;
    P1DIR &= ~0x04;
    P1 = 0x04;
}


void DelayMs(uint16 ms)
{
    for(uint16 i = 0; i < ms; i++)
        for(uint16 j = 0; j < 535; j++);
}


void main(void)
{
    Init_Port();
    
    while(1)
    {
        for(uint16 i = 0; i < checkKeyICycle; i++)
        {
            DelayMs(1);
            if(P1_2 == 0)
            {
                DelayMs(10);
                if(P1_2 == 0)
                {
                    running = running == 1 ? 0 : 1;
                    
                    while(P1_2 == 0);
                }
            }
        }
        
        if (running == 1)
        {
            P1 = ledRegister[ledLightIndex];
            
            if(ledLightIndex == 2) P1_7 = P1_7 == 1 ? 0 : 1;
            
            if(ledLightIndex == 3) ledLightIndex = 0;
            else ++ledLightIndex;
        }
        else P1 = 0x04;
    }
}

演示

点击打开

posted @ 2021-11-10 15:38  yassine  阅读(264)  评论(0编辑  收藏  举报