nrf24l01傳送和接收程式

2021-09-19 09:37:10 字數 2784 閱讀 3848

1、傳送

#include

#include

typedef unsigned char uchar;

typedef unsigned char uint;

io埠定義

sbit miso =p1^2;

sbit mosi =p3^2;

sbit sck =p1^6;

sbit ce =p1^5;

sbit csn =p1^7;

sbit irq =p1^3;

數碼管0-9編碼

uchar seg[10]=; //本地位址

uint const rx_address[rx_adr_width]= ; //接收位址

nrf24l01暫存器指令

#define read_reg 0x00 // 讀暫存器指令

#define write_reg 0x20 // 寫暫存器指令

#define rd_rx_pload 0x61 // 讀取接收資料指令

#define wr_tx_pload 0xa0 // 寫待發資料指令

#define flush_tx 0xe1 // 沖洗傳送 fifo指令

#define flush_rx 0xe2 // 沖洗接收 fifo指令

#define reuse_tx_pl 0xe3 // 定義重複裝載資料指令

#define nop0xff // 保留

spi(nrf24l01)暫存器位址

#define config0x00 // 配置收發狀態,crc校驗模式以及收發狀態響應方式

#define en_aa0x01 // 自動應答功能設定

#define en_rxaddr 0x02 // 可用通道設定

#define setup_aw 0x03 // 收發位址寬度設定

#define setup_retr 0x04 // 自動重發功能設定

#define rf_ch0x05 // 工作頻率設定

#define rf_setup 0x06 // 發射速率、功耗功能設定

#define status0x07 // 狀態暫存器

#define observe_tx 0x08 // 傳送監測功能

#define cd0x09 // 位址檢測

#define rx_addr_p0 0x0a // 頻道0接收資料位址

#define rx_addr_p1 0x0b // 頻道1接收資料位址

#define rx_addr_p2 0x0c // 頻道2接收資料位址

#define rx_addr_p3 0x0d // 頻道3接收資料位址

#define rx_addr_p4 0x0e // 頻道4接收資料位址

#define rx_addr_p5 0x0f // 頻道5接收資料位址

#define tx_addr 0x10 // 傳送位址暫存器

#define rx_pw_p0 0x11 // 接收頻道0接收資料長度

#define rx_pw_p1 0x12 // 接收頻道0接收資料長度

#define rx_pw_p2 0x13 // 接收頻道0接收資料長度

#define rx_pw_p3 0x14 // 接收頻道0接收資料長度

#define rx_pw_p4 0x15 // 接收頻道0接收資料長度

#define rx_pw_p5 0x16 // 接收頻道0接收資料長度

#define fifo_status 0x17 // fifo棧入棧出狀態暫存器設定

void delay(unsigned int s);

void inerdelay_us(unsigned char n);

void init_nrf24l01(void);

uint spi_rw(uint uchar);

uchar spi_read(uchar reg);

void setrx_mode(void);

uint spi_rw_reg(uchar reg, uchar value);

uint spi_read_buf(uchar reg, uchar *pbuf, uchar uchars);

uint spi_write_buf(uchar reg, uchar *pbuf, uchar uchars);

unsigned char nrf24l01_rxpacket(unsigned char* rx_buf);

void nrf24l01_txpacket(unsigned char * tx_buf);

長延時void delay(unsigned int s)

uint bdata sta; //狀態標誌

sbit rx_dr =sta^6;

sbit tx_ds =sta^5;

sbit max_rt =sta^4;

/*延時函式

void inerdelay_us(unsigned char n)

/*nrf24l01初始化

NRF24L01接收程式

標頭檔案 檔名 建立人 動車組 日期 2012 8 21 功能描述 用nrf24l01傳送一定位元組數的資料或者接收資料 占用資源 四位控制spi匯流排的io線和 1位nrf24l01模式控制引腳 占用乙個中段 include uchar code tx address tx adr width 本...

NRF24L01 中斷方式 接收部分

小強號車體程式 irq中斷 接收端 stc12c5052ad date 11 11 02 作者 phoenix include stc12c2052ad.h include include typedef unsigned char uchar typedef unsigned char uint ...

nrf24L01工作流程圖型

第1頁nrf24l01 流程圖 引腳定義 n yy n n 開始 時鐘ic lcd 液晶 溫度感測器 初始化nrf24l01 配置模式 判斷鍵盤是 否有動作 資料採集 和顯示將採集到的資料 裝入發射暫存器 啟動發射 發射是否完成 按鍵處理子程式 是否處理完 第2頁 nn y yn 開始 序列通訊 初...