NRF24L01多通道通信Word文档格式.docx
《NRF24L01多通道通信Word文档格式.docx》由会员分享,可在线阅读,更多相关《NRF24L01多通道通信Word文档格式.docx(65页珍藏版)》请在冰豆网上搜索。
sbitLCD_DC=P1^2;
sbitLCD_SCLK=P1^0;
sbitLCD_Din=P1^1;
/******************按键****************************************************/
sbitKEY1=P3^6;
sbitKEY2=P3^7;
/******************发光二极管*********************************************/
sbitled1=P1^6;
sbitled2=P1^7;
/******************NRF24L01地址宏定义*************************************/
#defineTX_ADR_WIDTH5//5uintsTXaddresswidth
#defineRX_ADR_WIDTH5//5uintsRXaddresswidth
#defineTX_PLOAD_WIDTH20//20uintsTXpayload
#defineRX_PLOAD_WIDTH20//20uintsTXpayload
uintconstTX_ADDRESS[TX_ADR_WIDTH]={0x34,0x43,0x10,0x10,0x01};
//本地地址
uintconstRX_ADDRESS[RX_ADR_WIDTH]={0x34,0x43,0x10,0x10,0x01};
//接收地址0
uintconstRX_ADDRESS1[RX_ADR_WIDTH]={0xf1,0xb3,0xb4,0xb5,0xb6};
//接收地址1
uintconstRX_ADDRESS2[RX_ADR_WIDTH]={0xcd,0xb3,0xb4,0xb5,0xb6};
//接收地址2
uintconstRX_ADDRESS3[RX_ADR_WIDTH]={0xa3,0xb3,0xb4,0xb5,0xb6};
//接收地址3
uintconstRX_ADDRESS4[RX_ADR_WIDTH]={0x0f,0xb3,0xb4,0xb5,0xb6};
//接收地址4
uintconstRX_ADDRESS5[RX_ADR_WIDTH]={0x05,0xb3,0xb4,0xb5,0xb6};
//接收地址5
/********************NRF24L01寄存器指令*************************************/
#defineREAD_REG0x00//读寄存器指令
#defineWRITE_REG0x20//写寄存器指令
#defineRD_RX_PLOAD0x61//读取接收数据指令
#defineWR_TX_PLOAD0xA0//写待发数据指令
#defineFLUSH_TX0xE1//冲洗发送FIFO指令
#defineFLUSH_RX0xE2//冲洗接收FIFO指令
#defineREUSE_TX_PL0xE3//定义重复装载数据指令
#defineNOP0xFF//保留
/**********************SPI(nRF24L01)寄存器地址*******************************/
#defineCONFIG0x00//配置收发状态,CRC校验模式以及收发状态响应方式
#defineEN_AA0x01//自动应答功能设置
#defineEN_RXADDR0x02//可用信道设置
#defineSETUP_AW0x03//收发地址宽度设置
#defineSETUP_RETR0x04//自动重发功能设置
#defineRF_CH0x05//工作频率设置
#defineRF_SETUP0x06//发射速率、功耗功能设置
#defineSTATUS0x07//状态寄存器
#defineOBSERVE_TX0x08//发送监测功能
#defineCD0x09//地址检测
#defineRX_ADDR_P00x0A//频道0接收数据地址
#defineRX_ADDR_P10x0B//频道1接收数据地址
#defineRX_ADDR_P20x0C//频道2接收数据地址
#defineRX_ADDR_P30x0D//频道3接收数据地址
#defineRX_ADDR_P40x0E//频道4接收数据地址
#defineRX_ADDR_P50x0F//频道5接收数据地址
#defineTX_ADDR0x10//发送地址寄存器
#defineRX_PW_P00x11//接收频道0接收数据长度
#defineRX_PW_P10x12//接收频道0接收数据长度
#defineRX_PW_P20x13//接收频道0接收数据长度
#defineRX_PW_P30x14//接收频道0接收数据长度
#defineRX_PW_P40x15//接收频道0接收数据长度
#defineRX_PW_P50x16//接收频道0接收数据长度
#defineFIFO_STATUS0x17//FIFO栈入栈出状态寄存器设置
/******************ASCII数组区**********************************/
codeunsignedcharfont6x8[92][6]=//数字和字母
{
{0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x2f,0x00,0x00},
{0x00,0x00,0x07,0x00,0x07,0x00},
{0x00,0x14,0x7f,0x14,0x7f,0x14},
{0x00,0x24,0x2a,0x7f,0x2a,0x12},
{0x00,0x62,0x64,0x08,0x13,0x23},
{0x00,0x36,0x49,0x55,0x22,0x50},
{0x00,0x00,0x05,0x03,0x00,0x00},
{0x00,0x00,0x1c,0x22,0x41,0x00},
{0x00,0x00,0x41,0x22,0x1c,0x00},
{0x00,0x14,0x08,0x3E,0x08,0x14},
{0x00,0x08,0x08,0x3E,0x08,0x08},
{0x00,0x00,0x00,0xA0,0x60,0x00},
{0x00,0x08,0x08,0x08,0x08,0x08},
{0x00,0x00,0x60,0x60,0x00,0x00},
{0x00,0x20,0x10,0x08,0x04,0x02},
{0x00,0x3E,0x51,0x49,0x45,0x3E},
{0x00,0x00,0x42,0x7F,0x40,0x00},
{0x00,0x42,0x61,0x51,0x49,0x46},
{0x00,0x21,0x41,0x45,0x4B,0x31},
{0x00,0x18,0x14,0x12,0x7F,0x10},
{0x00,0x27,0x45,0x45,0x45,0x39},
{0x00,0x3C,0x4A,0x49,0x49,0x30},
{0x00,0x01,0x71,0x09,0x05,0x03},
{0x00,0x36,0x49,0x49,0x49,0x36},
{0x00,0x06,0x49,0x49,0x29,0x1E},
{0x00,0x00,0x36,0x36,0x00,0x00},
{0x00,0x00,0x56,0x36,0x00,0x00},
{0x00,0x08,0x14,0x22,0x41,0x00},
{0x00,0x14,0x14,0x14,0x14,0x14},
{0x00,0x00,0x41,0x22,0x14,0x08},
{0x00,0x02,0x01,0x51,0x09,0x06},
{0x00,0x32,0x49,0x59,0x51,0x3E},
{0x00,0x7C,0x12,0x11,0x12,0x7C},
{0x00,0x7F,0x49,0x49,0x49,0x36},
{0x00,0x3E,0x41,0x41,0x41,0x22},
{0x00,0x7F,0x41,0x41,0x22,0x1C},
{0x00,0x7F,0x49,0x49,0x49,0x41},
{0x00,0x7F,0x09,0x09,0x09,0x01},
{0x00,0x3E,0x41,0x49,0x49,0x7A},
{0x00,0x7F,0x08,0x08,0x08,0x7F},
{0x00,0x00,0x41,0x7F,0x41,0x00},
{0x00,0x20,0x40,0x41,0x3F,0x01},
{0x00,0x7F,0x08,0x14,0x22,0x41},
{0x00,0x7F,0x40,0x40,0x40,0x40},
{0x00,0x7F,0x02,0x0C,0x02,0x7F},
{0x00,0x7F,0x04,0x08,0x10,0x7F},
{0x00,0x3E,0x41,0x41,0x41,0x3E},
{0x00,0x7F,0x09,0x09,0x09,0x06},
{0x00,0x3E,0x41,0x51,0x21,0x5E},
{0x00,0x7F,0x09,0x19,0x29,0x46},
{0x00,0x46,0x49,0x49,0x49,0x31},
{0x00,0x01,0x01,0x7F,0x01,0x01},
{0x00,0x3F,0x40,0x40,0x40,0x3F},
{0x00,0x1F,0x20,0x40,0x20,0x1F},
{0x00,0x3F,0x40,0x38,0x40,0x3F},
{0x00,0x63,0x14,0x08,0x14,0x63},
{0x00,0x07,0x08,0x70,0x08,0x07},
{0x00,0x61,0x51,0x49,0x45,0x43},
{0x00,0x00,0x7F,0x41,0x41,0x00},
{0x00,0x55,0x2A,0x55,0x2A,0x55},
{0x00,0x00,0x41,0x41,0x7F,0x00},
{0x00,0x04,0x02,0x01,0x02,0x04},
{0x00,0x40,0x40,0x40,0x40,0x40},
{0x00,0x00,0x01,0x02,0x04,0x00},
{0x00,0x20,0x54,0x54,0x54,0x78},
{0x00,0x7F,0x48,0x44,0x44,0x38},
{0x00,0x38,0x44,0x44,0x44,0x20},
{0x00,0x38,0x44,0x44,0x48,0x7F},
{0x00,0x38,0x54,0x54,0x54,0x18},
{0x00,0x08,0x7E,0x09,0x01,0x02},
{0x00,0x18,0xA4,0xA4,0xA4,0x7C},
{0x00,0x7F,0x08,0x04,0x04,0x78},
{0x00,0x00,0x44,0x7D,0x40,0x00},
{0x00,0x40,0x80,0x84,0x7D,0x00},
{0x00,0x7F,0x10,0x28,0x44,0x00},
{0x00,0x00,0x41,0x7F,0x40,0x00},
{0x00,0x7C,0x04,0x18,0x04,0x78},
{0x00,0x7C,0x08,0x04,0x04,0x78},
{0x00,0x38,0x44,0x44,0x44,0x38},
{0x00,0xFC,0x24,0x24,0x24,0x18},
{0x00,0x18,0x24,0x24,0x18,0xFC},
{0x00,0x7C,0x08,0x04,0x04,0x08},
{0x00,0x48,0x54,0x54,0x54,0x20},
{0x00,0x04,0x3F,0x44,0x40,0x20},
{0x00,0x3C,0x40,0x40,0x20,0x7C},
{0x00,0x1C,0x20,0x40,0x20,0x1C},
{0x00,0x3C,0x40,0x30,0x40,0x3C},
{0x00,0x44,0x28,0x10,0x28,0x44},
{0x00,0x1C,0xA0,0xA0,0xA0,0x7C},
{0x00,0x44,0x64,0x54,0x4C,0x44},
{0x14,0x14,0x14,0x14,0x14,0x14}
};
/***********标志位**********************************************/
/***************************************************************/
/***************函数声明区*****************************************************************/
voidLCD_write_byte(unsignedchardat,unsignedcharcommand);
//SPI写入数据函数
voidLCD_init(void);
//LCD5110初始化函数
voidLCD_set_XY(unsignedcharX,unsignedcharY);
//设置显示指针函数
voidLCD_write_char(unsignedcharc);
//写一个字符到LCD5110
voidLCD_clear(void);
//LCD初始化函数
voidinerDelay_us(unsignedcharn);
//延时函数
voidLCD_write_english_string(unsignedcharX,unsignedcharY,char*s);
//写字符串到LCD函数
voidLCD_write_english_char(unsignedcharX,unsignedcharY,unsignedcharch);
//写一个字符到LCD函数
voidDelay(unsignedints);
//场延时函数
voidNRF24L01_init(void);
//NRF24L01初始化
uintNRF24L01_SPI_RW(uintuchar);
//SPI写入和读出
ucharNRF24L01_SPI_Read(ucharreg);
//读寄存器reg
voidNRF24L01_SetRX_Mode(void);
//设置接收模式
uintNRF24L01_SPI_RW_Reg(ucharreg,ucharvalue);
//向寄存器reg中存入数据
uintNRF24L01_SPI_Read_Buf(ucharreg,uchar*pBuf,ucharuchars);
//读取寄存器reg的数据,存到pBuf中
uintNRF24L01_SPI_Write_Buf(ucharreg,uchar*pBuf,ucharuchars);
//向寄存器reg中写入数据pBuf
unsignedcharNRF24L01_RxPacket(unsignedchar*rx_buf);
//由MCU读取NRF24L01接收到的数据
voidNRF24L01_TxPacket(unsignedchar*tx_buf,unsignedcharxindaoji);
//由NRF24L01发送数据tx_buf
voidUSART_init(void);
//串口的初始化
voidUSART_TxPacket_char(ucharf_data);
//通过串口发送一个字节数据函数
voidUSART_TxPacket_buf(uchar*f_data);
//通过串口发送一个字符串的数据函数
/*****************************************************************************************/
/*****************************************长延时*****************************************/
voidDelay(unsignedints)
unsignedinti,j;
for(i=0;
i<
1000;
i++);
for(j=0;
j<
s;
j++);
}
/******************************************************************************************/
/***************************NRF2401*******************************************************/
uintbdatasta;
//状态标志
sbitRX_DR=sta^6;
//接收终端标示
sbitTX_DS=sta^5;
//发送中断标志
sbitMAX_RT=sta^4;
//重发次数中断标志,当重发次数超过了最发充许的重发次数该中断产生
/******************************************************************************************
/*延时函数
voidinerDelay_us(unsignedcharn)
for(;
n>
0;
n--)
_nop_();
/***********************************************************
函数名称:
LCD_write_byte
函数功能:
模拟SPI接口时序写数据/命令LCD
入口参数:
data:
写入的数据;
command