欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

標題: CC2530遠程控制燈亮滅程序 [打印本頁]

作者: fairy123    時間: 2019-9-27 09:25
標題: CC2530遠程控制燈亮滅程序
一,按 A模塊的按鍵---控制 B模塊的 LED 亮滅
1、實驗需求:
硬件需求:cc2530 模塊兩個、調(diào)試器一個。

單片機源程序如下:
  1. /***********************************************************************************
  2. 網(wǎng)蜂ZigBee-無線點燈實驗代碼 詳細解釋請參考《ZigBee實戰(zhàn)演練》中無線電燈相關內(nèi)容

  3. 實驗操作:
  4.        第一步: 找到下面內(nèi)容,把appLight();  注釋掉,下載到發(fā)射模塊。
  5.           appSwitch();        //節(jié)點為按鍵S1       P1_2
  6.        // appLight();        //節(jié)點為指示燈LED1    P1_0

  7.        第二步:找到相同位置,這次把appSwitch();注釋掉,下載到接收模塊。
  8.        //appSwitch();        //節(jié)點為按鍵S1       P0_4
  9.         appLight();         //節(jié)點為指示燈LED1   P1_0

  10. 完成燒寫后上電,按下發(fā)射模塊的S1按鍵,可以看到接收模塊的LED1被點亮。
  11. *********************************************************************************

  12.   Filename: light_switch.c

  13.   Description:  This application function either as a light or a
  14.   switch toggling the ligh. The role of the
  15.   application is chosen in the menu with the joystick at initialisation.

  16.   Push S1 to enter the menu. Choose either switch or
  17.   light and confirm choice with S1.
  18.   Joystick Up: Sends data from switch to light

  19. ***********************************************************************************/

  20. /***********************************************************************************
  21. * INCLUDES
  22. */
  23. #include <hal_lcd.h>
  24. #include <hal_led.h>
  25. #include <hal_joystick.h>
  26. #include <hal_assert.h>
  27. #include <hal_board.h>
  28. #include <hal_int.h>
  29. #include "hal_mcu.h"
  30. #include "hal_button.h"
  31. #include "hal_rf.h"
  32. #include "util_lcd.h"
  33. #include "basic_rf.h"


  34. /***********************************************************************************
  35. * CONSTANTS
  36. */
  37. // Application parameters
  38. #define RF_CHANNEL                25      // 2.4 GHz RF channel

  39. // BasicRF address definitions
  40. #define PAN_ID                0x2007
  41. #define SWITCH_ADDR           0x2520
  42. #define LIGHT_ADDR            0xBEEF
  43. #define APP_PAYLOAD_LENGTH        1
  44. #define LIGHT_TOGGLE_CMD          0

  45. // Application states
  46. #define IDLE                      0
  47. #define SEND_CMD                  1

  48. // Application role
  49. #define NONE                      0
  50. #define SWITCH                    1
  51. #define LIGHT                     2
  52. #define APP_MODES                 2

  53. /***********************************************************************************
  54. * LOCAL VARIABLES
  55. */
  56. static uint8 pTxData[APP_PAYLOAD_LENGTH];
  57. static uint8 pRxData[APP_PAYLOAD_LENGTH];
  58. static basicRfCfg_t basicRfConfig;

  59. // Mode menu
  60. static menuItem_t pMenuItems[] =
  61. {
  62. #ifdef ASSY_EXP4618_CC2420
  63.   // Using Softbaugh 7-seg display
  64.   " L S    ", SWITCH,
  65.   " LIGHT  ", LIGHT
  66. #else
  67.   // SRF04EB and SRF05EB
  68.   "Switch",   SWITCH,
  69.   "Light",    LIGHT
  70. #endif
  71. };

  72. static menu_t pMenu =
  73. {
  74.   pMenuItems,
  75.   N_ITEMS(pMenuItems)
  76. };


  77. #ifdef SECURITY_CCM
  78. // Security key
  79. static uint8 key[]= {
  80.     0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
  81.     0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
  82. };
  83. #endif

  84. /***********************************************************************************
  85. * LOCAL FUNCTIONS
  86. */
  87. static void appLight();
  88. static void appSwitch();
  89. static uint8 appSelectMode(void);


  90. /***********************************************************************************
  91. * @fn          appLight
  92. *
  93. * @brief       Application code for light application. Puts MCU in endless
  94. *              loop waiting for user input from joystick.
  95. *
  96. * @param       basicRfConfig - file scope variable. Basic RF configuration data
  97. *              pRxData - file scope variable. Pointer to buffer for RX data
  98. *
  99. * @return      none
  100. */
  101. static void appLight()
  102. {

  103.     halLcdWriteLine(HAL_LCD_LINE_1, "    W e B e e      ");
  104.     halLcdWriteLine(HAL_LCD_LINE_2, "  ZigBee CC2530  ");
  105.     halLcdWriteLine(HAL_LCD_LINE_4, "     LIGHT     ");

  106. #ifdef ASSY_EXP4618_CC2420
  107.     halLcdClearLine(1);
  108.     halLcdWriteSymbol(HAL_LCD_SYMBOL_RX, 1);
  109. #endif

  110.     // Initialize BasicRF
  111.     basicRfConfig.myAddr = LIGHT_ADDR;
  112.     if(basicRfInit(&basicRfConfig)==FAILED) {
  113.       HAL_ASSERT(FALSE);
  114.     }
  115.     basicRfReceiveOn();

  116.     // Main loop
  117.     while (TRUE) {
  118.         while(!basicRfPacketIsReady());

  119.         if(basicRfReceive(pRxData, APP_PAYLOAD_LENGTH, NULL)>0) {
  120.             if(pRxData[0] == LIGHT_TOGGLE_CMD) {
  121.                 halLedToggle(1);
  122.             }
  123.         }
  124.     }
  125. }


  126. /***********************************************************************************
  127. * @fn          appSwitch
  128. *
  129. * @brief       Application code for switch application. Puts MCU in
  130. *              endless loop to wait for commands from from switch
  131. *
  132. * @param       basicRfConfig - file scope variable. Basic RF configuration data
  133. *              pTxData - file scope variable. Pointer to buffer for TX
  134. *              payload
  135. *              appState - file scope variable. Holds application state
  136. *
  137. * @return      none
  138. */
  139. static void appSwitch()
  140. {
  141.     halLcdWriteLine(HAL_LCD_LINE_1, "      GEC-EDU      ");
  142.     halLcdWriteLine(HAL_LCD_LINE_2, "  ZigBee CC2530  ");
  143.     halLcdWriteLine(HAL_LCD_LINE_4, "     SWITCH    ");
  144.    
  145. #ifdef ASSY_EXP4618_CC2420
  146.     halLcdClearLine(1);
  147.     halLcdWriteSymbol(HAL_LCD_SYMBOL_TX, 1);
  148. #endif


  149.     // Initialize BasicRF
  150.     basicRfConfig.myAddr = SWITCH_ADDR;
  151.     if(basicRfInit(&basicRfConfig)==FAILED) {
  152.       HAL_ASSERT(FALSE);
  153.     }
  154.    
  155.     pTxData[0] = LIGHT_TOGGLE_CMD;

  156.     // Keep Receiver off when not needed to save power
  157.     basicRfReceiveOff();

  158.     // Main loop
  159.     while (TRUE) {
  160.         //if( halJoystickPushed() )**********************by boo
  161.       if(halButtonPushed()==HAL_BUTTON_1)//**************by boo
  162.         {

  163.             basicRfSendPacket(LIGHT_ADDR, pTxData, APP_PAYLOAD_LENGTH);

  164.             // Put MCU to sleep. It will wake up on joystick interrupt
  165.             halIntOff();
  166.             halMcuSetLowPowerMode(HAL_MCU_LPM_3); // Will turn on global
  167.             // interrupt enable
  168.             halIntOn();

  169.         }
  170.     }
  171. }


  172. /***********************************************************************************
  173. * @fn          main
  174. *
  175. * @brief       This is the main entry of the "Light Switch" application.
  176. *              After the application modes are chosen the switch can
  177. *              send toggle commands to a light device.
  178. *
  179. * @param       basicRfConfig - file scope variable. Basic RF configuration
  180. *              data
  181. *              appState - file scope variable. Holds application state
  182. *
  183. * @return      none
  184. */
  185. void main(void)
  186. {
  187.     uint8 appMode = NONE;

  188.     // Config basicRF
  189.     basicRfConfig.panId = PAN_ID;
  190.     basicRfConfig.channel = RF_CHANNEL;
  191.     basicRfConfig.ackRequest = TRUE;
  192. #ifdef SECURITY_CCM
  193.     basicRfConfig.securityKey = key;
  194. #endif

  195.     // Initalise board peripherals
  196.     halBoardInit();
  197.     halJoystickInit();

  198.     // Initalise hal_rf
  199.     if(halRfInit()==FAILED) {
  200.       HAL_ASSERT(FALSE);
  201.     }

  202.     // Indicate that device is powered
  203.     halLedSet(2);      //關閉LED2
  204.     halLedSet(1);      //關閉LED1


  205.     /***********************************************
  206.     // Print Logo and splash screen on LCD
  207.      utilPrintLogo("Light Switch");

  208.     // Wait for user to press S1 to enter menu
  209.     while (halButtonPushed()!=HAL_BUTTON_1);
  210.     halMcuWaitMs(350);
  211.     halLcdClear();

  212.     // Set application role
  213.     appMode = appSelectMode();
  214.     halLcdClear();

  215.     // Transmitter application
  216.     if(appMode == SWITCH) {
  217.         // No return from here
  218.         appSwitch();
  219.     }
  220.     // Receiver application
  221.     else if(appMode == LIGHT) {
  222.         // No return from here
  223.         appLight();
  224.     }
  225.     **************************************/
  226.    
  227.     /************Select one and shield to another***********by boo*/
  228.      //appSwitch();        //節(jié)點為按鍵S1      P1_2
  229.     appLight();         //節(jié)點為指示燈LED1   P1_0
  230.    
  231.    // Role is undefined. This code should not be reached
  232.     HAL_ASSERT(FALSE);
  233. }


  234. /****************************************************************************************
  235. * @fn          appSelectMode
  236. *
  237. * @brief       Select application mode
  238. *
  239. * @param       none
  240. *
  241. * @return      uint8 - Application mode chosen
  242. */
  243. static uint8 appSelectMode(void)
  244. {
  245.     halLcdWriteLine(1, "Device Mode: ");

  246.     return utilMenuSelect(&pMenu);
  247. }
復制代碼

所有資料51hei提供下載:
CC2530 BasicRF無線點燈部署.7z (525.14 KB, 下載次數(shù): 7)



作者: admin    時間: 2019-9-27 17:42
本帖需要重新編輯補全電路原理圖,源碼,詳細說明與圖片即可獲得100+黑幣(帖子下方有編輯按鈕)
作者: ssd4561    時間: 2019-9-28 13:25
學習了》》》厲害,英語牛逼




歡迎光臨 (http://m.raoushi.com/bbs/) Powered by Discuz! X3.1