发射:TX
接收:RX
NRF24L01.c
#include "typedef.h"
#include <intrins.h>
#include <string.h>
#include "NRF24L01.h"
#include "delay.h"
#define uchar unsigned char
uchar const TX_ADDRESS[TX_ADR_WIDTH] = {0x34,0x43,0x10,0x10,0x01}; // Define a static TX address
idata uchar rx_buf[TX_PLOAD_WIDTH];
idata uchar tx_buf[TX_PLOAD_WIDTH];
uchar flag;
unsigned char bdata sta;
sbit RX_DR =sta^6;
sbit TX_DS =sta^5;
sbit MAX_RT =sta^4;
/**************************************************/
void init_nrf24l01_io(void)
{
CE=0; // chip enable
CSN=1; // Spi disable
SCK=0; // Spi clock line init high
}
/**************************************************
Function: SPI_RW();
Description:
Writes one byte to nRF24L01, and return the byte read
from nRF24L01 during write, according to SPI protocol
/**************************************************/
bdata unsigned char st=0;
sbit st_1=st^0;
sbit st_2=st^1;
sbit st_3=st^2;
sbit st_4=st^3;
sbit st_5=st^4;
sbit st_6=st^5;
sbit st_7=st^6;
sbit st_8=st^7;
bdata unsigned char st1=0;
sbit st_11=st1^0;
sbit st_12=st1^1;
sbit st_13=st1^2;
sbit st_14=st1^3;
sbit st_15=st1^4;
sbit st_16=st1^5;
sbit st_17=st1^6;
sbit st_18=st1^7;
/*
uchar SPI_RW(uchar byte)
{
uchar bit_ctr;
for(bit_ctr=0;bit_ctr<8;bit_ctr++) // output 8-bit
{
MOSI = (byte & 0x80); // output 'byte', MSB to MOSI
byte = (byte << 1); // shift next bit into MSB..
SCK = 1; // Set SCK high..
MISO=1;
byte |= MISO; // capture current MISO bit
SCK = 0; // ..then set SCK low again
}
return(byte); // return read byte
}
*/
uchar SPI_RW(uchar byte)
{
//uchar bit_ctr;
st=byte;
MOSI=st_8;
SCK = 1;
st_18=MISO;
SCK = 0;
MOSI=st_7;
SCK = 1;
st_17=MISO;
SCK = 0;
MOSI=st_6;
SCK = 1;
st_16=MISO;
SCK = 0;
MOSI=st_5;
SCK = 1;
st_15=MISO;
SCK = 0;
MOSI=st_4;
SCK = 1;
st_14=MISO;
SCK = 0;
MOSI=st_3;
SCK = 1;
st_13=MISO;
SCK = 0;
MOSI=st_2;
SCK = 1;
st_12=MISO;
SCK = 0;
MOSI=st_1;
SCK = 1;
st_11=MISO;
SCK = 0;
return(st1); // return read byte
}
/**************************************************/
/**************************************************
Function: SPI_RW_Reg();
Description:
Writes value 'value' to register 'reg'
/**************************************************/
uchar SPI_RW_Reg(BYTE reg, BYTE value)
{
uchar status;