CC2530开发试题(五)

试题

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                24         // 频道 11~26
#define PAN_ID                    0x8001     //网络id 
#define MY_ADDR                   0x1111     //本机模块地址
#define SEND_ADDR                 0x2222     //发送地址
/**************************************************/
static basicRfCfg_t basicRfConfig;
uint8 key_recv;
// 无线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();//选手不得在此函数内添加代码
    
    P1DIR &= ~0xFF;
    P1DIR |= 0x1B;
    P1 = 0x02;
    
    while(1)
    {
    /* user code start */
        if(basicRfPacketIsReady())
        {
            basicRfReceive(&key_recv, 1, NULL);
            if(key_recv == 0x01) P1 = 0x01;
            else if(key_recv == 0x02) P1 = 0x02;
            else if(key_recv == 0x08) P1 = 0x08;
            else if(key_recv == 0x10) P1 = 0x10;
        }
    /* 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                24         // 频道 11~26
#define PAN_ID                    0x8001     //网络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 registeLed[4] = {0x02, 0x01, 0x10, 0x08};
    uint8 cycleCount;
    uint8 running = 1, lastUp = 1;
    uint8 key_send;
    P1DIR &= ~0xFF;
    P1DIR |= 0x03;
    P1 = 0x01;
    
    while(1)
    {
    /* user code start */
        if(P1_2 == 1) lastUp = 1;
        
        uint16 time = 1000;
        while(time > 0)
        {
            halMcuWaitMs(1);
            --time;
            if(P1_2 == 0 && lastUp == 1)
            {
                halMcuWaitMs(10);
                if(P1_2 == 0) 
                {
                    running = running == 1 ? 0 : 1;
                    lastUp = 0;
                }
            }
        }
        
        
        if(running == 1)
        {
            key_send = registeLed[cycleCount];
            basicRfSendPacket(SEND_ADDR, &key_send, 1);
            
            if(cycleCount == 3) P1_1 = 1;
            else P1_1 = 0;
            
            if(cycleCount < 3) ++cycleCount;
            else cycleCount = 0;
        }
    /* user code end */
    }
}

演示

点击打开

上一篇:【STM32】NVIC嵌套中断向量控制器与外部中断


下一篇:踩了*