NRF24L01無線模塊發(fā)送-AVR程序代碼
#include
#include
#include"lcd12864.h"
#defineuintunsignedint
#defineucharunsignedchar
#defineMISOPINB.6
#defineSCKPORTB.7
#defineMOSIPORTB.5
#defineCSNPORTC.0
#defineCEPORTC.1
#defineIRQPORTC.2
#defineCONFIG0x00//配置收發(fā)狀態(tài),CRC校驗(yàn)?zāi)J揭约笆瞻l(fā)狀態(tài)響應(yīng)方式
#defineEN_AA0x01//自動(dòng)應(yīng)答使能
#defineEN_RXADDR0x02//接收地址允許
#defineSETUP_AW0x03//設(shè)置地址寬度
#defineSETUP_RETR0x04//建立自動(dòng)重發(fā)
#defineRF_CH0x05//射頻通道
#defineRF_SETUP0x06//射頻寄存器
#defineSTATUS0x07//狀態(tài)寄存器
#defineOBSTERVE_TX0x08//發(fā)送檢測(cè)寄存器
#defineCD0x09//載波檢測(cè)
#defineRX_ADDR_P00x0a//數(shù)據(jù)通道0接收地址
#defineRX_ADDR_P10x0b//數(shù)據(jù)通道0接收地址
#defineRX_ADDR_P20x0c//數(shù)據(jù)通道0接收地址
#defineRX_ADDR_P30x0d//數(shù)據(jù)通道0接收地址
#defineRX_ADDR_P40x0e//數(shù)據(jù)通道0接收地址
#defineRX_ADDR_P50x0f//數(shù)據(jù)通道0接收地址
#defineTX_ADDR0x10//發(fā)送地址
#defineRX_PW_P00x11//
#defineRX_PW_P10x12//
#defineRX_PW_P20x13//
#defineRX_PW_P30x14//
#defineRX_PW_P40x15//
#defineRX_PW_P50x16//
#defineFIFO_STATUS0x17//FIFO狀態(tài)寄存器
#defineREAD_REG0x00//讀寄存器指令
#defineWRITE_REG0x20//寫寄存器指令
#defineRD_RX_PLOAD0x61//讀取接收數(shù)據(jù)指令
#defineWR_TX_PLOAD0xA0//寫待發(fā)數(shù)據(jù)指令
#defineFLUSH_TX0xE1//沖洗發(fā)送FIFO指令
#defineFLUSH_RX0xE2//沖洗接收FIFO指令
#defineREUSE_TX_PL0xE3//定義重復(fù)裝載數(shù)據(jù)指令
#defineNOP0xFF//保留
#defineTX_ADR_WIDTH5//5uintsTXaddresswidth
#defineRX_ADR_WIDTH5//5uintsRXaddresswidth
#defineTX_PLOAD_WIDTH20//20uintsTXpayload
#defineRX_PLOAD_WIDTH20//20uintsTXpayload
ucharstatus;
ucharstr[30];
ucharTX_ADDRESS[TX_ADR_WIDTH]={0x05,0x04,0x03,0x02,0x01};//本地地址
ucharRX_ADDRESS[RX_ADR_WIDTH]={0x05,0x04,0x03,0x02,0x01};//接收地址
ucharTxBuf[17]="anywhereyouare";
ucharSPI_RW(ucharuuchar)//SPI寫時(shí)序
{
ucharbit_ctr;
for(bit_ctr=0;bit_ctr<8;bit_ctr++)
{
MOSI=(uuchar&0x80);
uuchar=(uuchar<<1);
SCK=1;
uuchar|=MISO;
SCK=0;
}
return(uuchar);
}
ucharSPI_Read(ucharreg)//SPI讀取一個(gè)字節(jié)
{
ucharreg_val;
CSN=0;
SPI_RW(reg);
delay_ms(1);
reg_val=SPI_RW(0);
delay_ms(1);
CSN=1;
return(reg_val);
}
ucharSPI_RW_Reg(ucharreg,ucharvalue)//寫一個(gè)自接到寄存器函數(shù)
{
ucharstatus;
CSN=0;
status=SPI_RW(reg);
delay_ms(1);
SPI_RW(value);
delay_ms(1);
CSN=1;
return(status);
}
uchar*ucharostr(ucharnum)
{
ucharx00,xx,x0,x,n;
x00=num/100;
xx=num0;
x0=xx/10;
x=xx;
n=0;
if(x00!=0)
{
str[n]=x00+48;
n++;
}
if(!(x00==0&x0==0))
{
str[n]=x0+48;
n++;
}
str[n]=x+48;
n++;
str[n]='