CC2530开发试题(三)
作者:互联网
试题
代码部分
ZigbeeA - rf_set.c
#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 25 // 频道 11~26
#define PAN_ID 0x1234 //网络id
#define MY_ADDR 0x1111 //本机模块地址
#define SEND_ADDR 0x2222 //发送地址
/**************************************************/
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************************/
void main(void)
{
halBoardInit();//选手不得在此函数内添加代码
ConfigRf_Init();//选手不得在此函数内添加代码
uint8 ledArray[4] = {0x06, 0x05, 0x14, 0xC};
uint8 ledCurrCount, cycleCount;
uint8 key_send;
P1SEL &= ~0xFF;
P1DIR &= ~0xFF;
P1DIR |= 0x1F;
P1 = 0x04;
while(1)
{
/* user code start */
if(P1_2 == 0)
{
halMcuWaitMs(10);
if(P1_2 == 0)
{
key_send = 0x01;
basicRfSendPacket(SEND_ADDR, &key_send, 1);
while(cycleCount < 3)
{
P1 = ledArray[ledCurrCount];
halMcuWaitMs(2000);
if(ledCurrCount == 3) ++cycleCount;
if(ledCurrCount < 3) ++ledCurrCount;
else ledCurrCount = 0;
if(cycleCount == 3)
{
key_send = 0x00;
basicRfSendPacket(SEND_ADDR, &key_send, 1);
}
}
while(P1_2 == 0);
//松手后
ledCurrCount = 0;
cycleCount = 0;
P1 = 0x04;
}
}
/* user code end */
}
}
ZigbeeB - rf_set.c
#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 25 // 频道 11~26
#define PAN_ID 0x1234 //网络id
#define MY_ADDR 0x2222 //本机模块地址
#define SEND_ADDR 0x1111 //发送地址
/**************************************************/
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************************/
void main(void)
{
halBoardInit();//选手不得在此函数内添加代码
ConfigRf_Init();//选手不得在此函数内添加代码
uint8 key_recv;
P1SEL &= ~0xFF;
P1DIR &= ~0xFF;
P1DIR |= 0x81;
P1 = 0x00;
while(1)
{
/* user code start */
if(basicRfPacketIsReady())
{
basicRfReceive(&key_recv, 1, NULL);
if(key_recv == 0x01)
{
//打开ledlight
P1_0 = 1;
P1_7 = 1;
}
else if(key_recv == 0x00)
{
//关闭ledlight
halMcuWaitMs(3000);
P1_0 = 0;
P1_7 = 0;
}
}
/* user code end */
}
}
演示
标签:key,P1,hal,试题,void,开发,basicRfConfig,CC2530,include 来源: https://www.cnblogs.com/godshadow/p/15532645.html