24L01無線模塊,要的可下
單片機源程序如下:
- /******************************************************************************/
- /*
- // 文件名:main.c
- // 說明:供客戶測試模塊通信使用程序
- // 編寫人員:
- // 編寫日期:
- // 程序維護:
- // 維護記錄:
- //
- //
- */
- // 免責聲明:該程序僅用于學習與交流
- // (c) Anxinke Corporation. All rights reserved.
- /******************************************************************************/
- #include "typedef.h"
- #include "gpio.h"
- #include "uart.h"
- #include "nrf24l01p.h"
- #include "delay.h"
- uchar txData[32] = {0x00};
- uchar rxData[32] = {0x00};
- /******************************************************************************/
- // 函數名稱:main
- // 輸入參數:
- // 輸出參數:
- // 函數功能:
- /******************************************************************************/
- void main(void)
- {
- unsigned char i=0;
- uartInit();
- Delay100ms();
- init_nrf24l01_io();
- led1ON();
- Delay100ms();
- led1OFF();
- Delay100ms();
- led1ON();
- Delay100ms();
- led1OFF();
-
- Delay100ms();
- uartSendString("System initialization is complete!\r\n");
- receive_mode_init();
-
- while(1)
- {
- KEY1 = 1;
- KEY2 = 1;
- /*
- * 判斷是否按下KEY
- */
- if (key1ON() || key2ON()) {
- _delay_us(500);
- txData[0] = 0;
- if (key1ON()) {
- txData[0] = 0xAA; // 如果按下K1 則將數據置為0xAA
- uartSendString("You press the left button\r\n");
- } else if (key2ON()){
- txData[0] = 0x55; // 如果按下K2 則將數據置為0x55
- uartSendString("You press the Right button\r\n");
- }
- /*
- * 根據不同的數據LED提示
- */
- if (send_data(txData) == 1) {
- uartSendString("Success of sending data\r\n");
- if (txData[0] == 0xAA) {
- led1ON();
- } else if (txData[0] == 0x55) {
- led2ON();
- }
- Delay100ms();
- led1OFF();
- led2OFF();
- } else {
- uartSendString("Failed to send data\r\n");
- }
- receive_mode_init();
- }
- rxData[0] = 0;
- led1OFF();
- led2OFF();
- if (receive_data(rxData)) {
- if (rxData[0] == 0xAA) {
- led1ON();
- uartSendString("Receiving the data, from the Left\r\n");
- } else if (rxData[0] == 0x55) {
- led2ON();
- uartSendString("Receiving the data, from the Right\r\n");
- }
- Delay100ms();
- }
-
- }
- }
復制代碼
所有資料51hei提供下載:
臺產24L01 資料.rar
(2.98 MB, 下載次數: 10)
2018-8-17 13:06 上傳
點擊文件名下載附件
|