演示:
Mar-05-2022 00-32-57.gif
代码:
exboard.h
#define uint unsigned int
#define uchar unsigned char
#define uint32 unsigned long
#define LED1 P1_0
#define LED2 P1_1
#define KEY1 P0_1
#define KEY2 P2_0
main.cpp
#include<ioCC2530.h>
#include "exboard.h"
void main(void)
{
// 按键
P0SEL &= ~0x01; // 设置P0_1为通用IO
P0DIR &= ~0x01; // 设置按键在P0_1口,设置P0_1为输入模式
P0INP |= 0x01; // 设置P1为上拉
// LED
P1SEL &= ~0x03; // P1SEl第0、1位设为通用IO
P1DIR |= 0x03; // P1DIR第0、1位设为输出模式
LED1 = 1;
LED2 = 1;
while(1)
{
if(KEY1 == 0) // 测试key1是否按下
{
while(KEY1 == 0);
LED1 = !LED1; // 闪动LED
LED2 = !LED2;
}
}
}
网友评论