欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136
標題:
CC2530遠程控制燈亮滅程序
[打印本頁]
作者:
fairy123
時間:
2019-9-27 09:25
標題:
CC2530遠程控制燈亮滅程序
一,按 A模塊的按鍵---控制 B模塊的 LED 亮滅
1、實驗需求:
硬件需求:cc2530 模塊兩個、調(diào)試器一個。
單片機源程序如下:
/***********************************************************************************
網(wǎng)蜂ZigBee-無線點燈實驗代碼 詳細解釋請參考《ZigBee實戰(zhàn)演練》中無線電燈相關內(nèi)容
實驗操作:
第一步: 找到下面內(nèi)容,把appLight(); 注釋掉,下載到發(fā)射模塊。
appSwitch(); //節(jié)點為按鍵S1 P1_2
// appLight(); //節(jié)點為指示燈LED1 P1_0
第二步:找到相同位置,這次把appSwitch();注釋掉,下載到接收模塊。
//appSwitch(); //節(jié)點為按鍵S1 P0_4
appLight(); //節(jié)點為指示燈LED1 P1_0
完成燒寫后上電,按下發(fā)射模塊的S1按鍵,可以看到接收模塊的LED1被點亮。
*********************************************************************************
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
***********************************************************************************/
/***********************************************************************************
* 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"
/***********************************************************************************
* 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 0xBEEF
#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
/***********************************************************************************
* 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, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
};
#endif
/***********************************************************************************
* LOCAL FUNCTIONS
*/
static void appLight();
static void appSwitch();
static uint8 appSelectMode(void);
/***********************************************************************************
* @fn appLight
*
* @brief Application code for light application. Puts MCU in endless
* loop waiting for user input from joystick.
*
* @param basicRfConfig - file scope variable. Basic RF configuration data
* pRxData - file scope variable. Pointer to buffer for RX data
*
* @return none
*/
static void appLight()
{
halLcdWriteLine(HAL_LCD_LINE_1, " W e B e e ");
halLcdWriteLine(HAL_LCD_LINE_2, " ZigBee CC2530 ");
halLcdWriteLine(HAL_LCD_LINE_4, " LIGHT ");
#ifdef ASSY_EXP4618_CC2420
halLcdClearLine(1);
halLcdWriteSymbol(HAL_LCD_SYMBOL_RX, 1);
#endif
// Initialize BasicRF
basicRfConfig.myAddr = LIGHT_ADDR;
if(basicRfInit(&basicRfConfig)==FAILED) {
HAL_ASSERT(FALSE);
}
basicRfReceiveOn();
// Main loop
while (TRUE) {
while(!basicRfPacketIsReady());
if(basicRfReceive(pRxData, APP_PAYLOAD_LENGTH, NULL)>0) {
if(pRxData[0] == LIGHT_TOGGLE_CMD) {
halLedToggle(1);
}
}
}
}
/***********************************************************************************
* @fn appSwitch
*
* @brief Application code for switch application. Puts MCU in
* endless loop to wait for commands from from switch
*
* @param basicRfConfig - file scope variable. Basic RF configuration data
* pTxData - file scope variable. Pointer to buffer for TX
* payload
* appState - file scope variable. Holds application state
*
* @return none
*/
static void appSwitch()
{
halLcdWriteLine(HAL_LCD_LINE_1, " GEC-EDU ");
halLcdWriteLine(HAL_LCD_LINE_2, " ZigBee CC2530 ");
halLcdWriteLine(HAL_LCD_LINE_4, " SWITCH ");
#ifdef ASSY_EXP4618_CC2420
halLcdClearLine(1);
halLcdWriteSymbol(HAL_LCD_SYMBOL_TX, 1);
#endif
// Initialize BasicRF
basicRfConfig.myAddr = SWITCH_ADDR;
if(basicRfInit(&basicRfConfig)==FAILED) {
HAL_ASSERT(FALSE);
}
pTxData[0] = LIGHT_TOGGLE_CMD;
// Keep Receiver off when not needed to save power
basicRfReceiveOff();
// Main loop
while (TRUE) {
//if( halJoystickPushed() )**********************by boo
if(halButtonPushed()==HAL_BUTTON_1)//**************by boo
{
basicRfSendPacket(LIGHT_ADDR, pTxData, APP_PAYLOAD_LENGTH);
// Put MCU to sleep. It will wake up on joystick interrupt
halIntOff();
halMcuSetLowPowerMode(HAL_MCU_LPM_3); // Will turn on global
// interrupt enable
halIntOn();
}
}
}
/***********************************************************************************
* @fn main
*
* @brief This is the main entry of the "Light Switch" application.
* After the application modes are chosen the switch can
* send toggle commands to a light device.
*
* @param basicRfConfig - file scope variable. Basic RF configuration
* data
* appState - file scope variable. Holds application state
*
* @return none
*/
void main(void)
{
uint8 appMode = NONE;
// Config basicRF
basicRfConfig.panId = PAN_ID;
basicRfConfig.channel = RF_CHANNEL;
basicRfConfig.ackRequest = TRUE;
#ifdef SECURITY_CCM
basicRfConfig.securityKey = key;
#endif
// Initalise board peripherals
halBoardInit();
halJoystickInit();
// Initalise hal_rf
if(halRfInit()==FAILED) {
HAL_ASSERT(FALSE);
}
// Indicate that device is powered
halLedSet(2); //關閉LED2
halLedSet(1); //關閉LED1
/***********************************************
// Print Logo and splash screen on LCD
utilPrintLogo("Light Switch");
// Wait for user to press S1 to enter menu
while (halButtonPushed()!=HAL_BUTTON_1);
halMcuWaitMs(350);
halLcdClear();
// Set application role
appMode = appSelectMode();
halLcdClear();
// Transmitter application
if(appMode == SWITCH) {
// No return from here
appSwitch();
}
// Receiver application
else if(appMode == LIGHT) {
// No return from here
appLight();
}
**************************************/
/************Select one and shield to another***********by boo*/
//appSwitch(); //節(jié)點為按鍵S1 P1_2
appLight(); //節(jié)點為指示燈LED1 P1_0
// Role is undefined. This code should not be reached
HAL_ASSERT(FALSE);
}
/****************************************************************************************
* @fn appSelectMode
*
* @brief Select application mode
*
* @param none
*
* @return uint8 - Application mode chosen
*/
static uint8 appSelectMode(void)
{
halLcdWriteLine(1, "Device Mode: ");
return utilMenuSelect(&pMenu);
}
復制代碼
所有資料51hei提供下載:
CC2530 BasicRF無線點燈部署.7z
(525.14 KB, 下載次數(shù): 7)
2019-9-27 17:40 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
作者:
admin
時間:
2019-9-27 17:42
本帖需要重新編輯補全電路原理圖,源碼,詳細說明與圖片即可獲得100+黑幣(帖子下方有編輯按鈕)
作者:
ssd4561
時間:
2019-9-28 13:25
學習了》》》厲害,英語牛逼
歡迎光臨 (http://m.raoushi.com/bbs/)
Powered by Discuz! X3.1