#include "hal_defs.h"
#include "hal_cc8051.h"
#include "hal_int.h"
#include "hal_mcu.h"
#include "hal_board.h"
#include "hal_led.h"
#include "hal_rf.h"
#include "basic_rf.h"
#include "hal_uart.h"
#include "sensor_drv/sensor.h"
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
/*****点对点通讯地址设置******/
#define RF_CHANNEL 11 // 频道 11~26
#define PAN_ID 0x1111 //网络id
#define MY_ADDR 0x1111 //本机模块地址
#define SEND_ADDR 0x2222 //发送地址
/**************************************************/
#define LED1 P1_0
#define LED2 P1_1
#define SW1 P1_2
static basicRfCfg_t basicRfConfig;
// 无线RF初始化
void ConfigRf_Init(void)
{
basicRfConfig.panId = PAN_ID;
basicRfConfig.channel = RF_CHANNEL;
basicRfConfig.myAddr = MY_ADDR;
basicRfConfig.ackRequest = TRUE;
while(basicRfInit(&basicRfConfig) == FAILED);
basicRfReceiveOn();
}
/********************MAIN************************/
uint8 startFlag=0;
uint8 count=0;
uint8 countResult;
void keyScan(){
if(SW1==0){
halMcuWaitMs(10);
if(SW1==0){
startFlag=1;
count++;
if(count>3)
count=3;
while(SW1==0);
//如果在0.5秒内,再次按下,重新进入按键函数
for(int i=0;i<50;i++){
halMcuWaitMs(10);
if(SW1==0) return;
}
//如果0.5秒内没有按下,记录按下的次数,并重新计数
countResult =count;
count=0;
startFlag=0;
}
}
}
void main(void)
{
halBoardInit();//选手不得在此函数内添加代码
ConfigRf_Init();//选手不得在此函数内添加代码
P1DIR = 0X03;
LED2 = 0;
LED1 = 0;
while(1)
{
/* user code start */
keyScan();
if(startFlag==0){
switch(countResult){
case 0: LED1 = 0;
LED2 = 0; break;
case 1: LED1 = 1;
LED2 = 0; break;
case 2: LED1 = 0;
LED2 = 1; break;
case 3: LED1 = 1;
LED2 = 1; break;
}
}
/* user code end */
}
}
zigbee 单击、双击、三连击程序
于 2023-05-19 15:09:42 首次发布
该程序初始化了RF通信模块,设置为点对点模式,定义了频道、网络ID和地址。同时,有一个按键扫描函数用于检测用户输入,根据不同的按键次数控制两个LED灯的状态。主循环中处理按键扫描的结果并更新LED状态。
摘要由CSDN通过智能技术生成