实验一CC2530开发环境与基础开发
1 实验目的
掌握在IAR8.20环境下创建工程和工程配置;
掌握CC2530单片机的I/O口的基本使用和UART外设的配置;
理解BasicRF工程的射频发送和接收。
2 实验内容
在IAR8.20环境下创建工程,编写程序实现按键控制LED亮灭,并进行工程配置、编译和下载;
在BasicRF工程中添加串口功能,配置UART寄存器,实现串口的接收和发送;实现两台电脑的串口射频无线数据传输。
3 查看CC2530模块和底板的硬件电路设计原理图,用查询的方式完成以下实验现象:按键控制LED的亮灭,具体效果可以自由发挥。写出关键实验代码。
/***********************************************************************************
Filename: light_switch.c
Description: This application function either as a light or a
switch toggling the ligh. The role of the
application is chosen in the menu with the joystick at initialisation.
Push S1 to enter the menu. Choose either switch or
light and confirm choice with S1.
Joystick Up: Sends data from switch to light
***********************************************************************************/
/*******************************************************************************
*文件名 : light_switch.c
*实现功能 : 基于BasicRF的无线light_switch
*实验平台 : Zigbee 开发板
*硬件连接 : LED1 P1_0
LED2 P1_1
LED3 P1_4
KEY1 P0_4
KEY2 P0_5
*******************************************************************************/
/***********************************************************************************
* INCLUDES
*/
#include <hal_lcd.h>
#include <hal_led.h>
#include <hal_joystick.h>
#include <hal_assert.h>
#include <hal_board.h>
#include <hal_int.h>
#include "hal_mcu.h"
#include "hal_button.h"
#include "hal_rf.h"
#include "util_lcd.h"
#include "basic_rf.h"
#include <ioCC2530.h>
/***********************************************************************************
* CONSTANTS
*/
// Application parameters
#define RF_CHANNEL 25 // 2.4 GHz RF channel
// BasicRF address definitions
#define PAN_ID 0x2007
#define SWITCH_ADDR 0x2520
#define LIGHT_ADDR 0xFFFF
#define APP_PAYLOAD_LENGTH 1
#define LIGHT_TOGGLE_CMD 0
// Application states
#define IDLE 0
#define SEND_CMD 1
// Application role
#define NONE 0
#define SWITCH 1
#define LIGHT 2
#define APP_MODES 2
#define State_Send 0
#define State_Receive 1
#define uint unsigned int
#define uchar unsigned char
/***********************************************************************************
* LOCAL VARIABLES
*/
static uint8 pTxData[APP_PAYLOAD_LENGTH];
static uint8 pRxData[APP_PAYLOAD_LENGTH];
static basicRfCfg_t basicRfConfig;
// Mode menu
static menuItem_t pMenuItems[] =
{
#ifdef ASSY_EXP4618_CC2420
// Using Softbaugh 7-seg display
" L S ", SWITCH,
" LIGHT ", LIGHT
#else
// SRF04EB and SRF05EB
"Switch", SWITCH,
"Light", LIGHT
#endif
};
static menu_t pMenu =
{
pMenuItems,
N_ITEMS(pMenuItems)
};
#ifdef SECURITY_CCM
// Security key
static uint8 key[]= {
0xc0