The receiving and sending program of wireless temperature monitoring system based on DS18B20 temperature sensor, LCD1602 liquid crystal display and nRF24L01 wireless transmission module
Author:ylmoira Time:2021-07-21 10:13 Browse(874)
/******************************Wireless temperature transmission***********************/
/******************************Wireless temperature transmission ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^_ ADDR_ Witdh 5 / / the width of the sending address is set to 5 bytes.

The receiving and sending program of wireless temperature monitoring system based on DS18B20 temperature sensor, LCD1602 liquid crystal display and nRF24L01 wireless transmission module

? Define RX_ ADDR_ WITDH 5.
#define TX_ DATA_ WITDH 5.
#define RX_ DATA_ Witdh 5.
/ * * * * * * * /.
/ / nRF24L01 instruction format:
* * * * * * * /.
# define R_ Register 0x00 / / read register.
? Define w_ Register 0x20 / / write register.
? Define R_ RX_ Pload 0x61 / / read RX FIFO valid data.
1-32 bytes,When the read data is completed, the data is cleared and applied to the receive mode_ TX_ Pload 0xa0 / / write TX FIFO valid data.
1-32 bytes. The write operation starts from byte 0 and applies to the transmit mode.
? Define flush_ TX 0xe1 / / clear TX FIFO register.
apply to transmit mode.
define flush_ RX 0xe2 / / clear RX FIFO register.
apply to receive mode.
? Define reuse_ TX_ PL 0xe3 / / reuses the last packet of valid data.
when CE is high, The data packets are retransmitted continuously.
# define NOP 0xff / / null operation.
can be used to read the status register.
/ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
/ / nRF24L01 register address.
# define EN_ AA 0x01 / "auto answer" function register_ RX_ Addr 0x02 / / receive channel enable register#define SETUP_ Aw 0x03 / / address width setting register.
? Define setup_ Retr 0x04 / / Auto retransmission setting register.
? Define RF_ Ch 0x05 / / RF channel frequency setting register_ Setup 0x06 / / RF setting register.
? Define status 0x07 / / status register.
? Define observe_ TX 0x08 / / transmit detect register.
? Define CD 0x09 / / carrier detect register.
? Define RX_ ADDR_ P0 0x0a / / data channel 0 receive address register.
? Define RX_ ADDR_ P1 0x0b / / data channel 1 receive address register.
? Define RX_ ADDR_ P2 0x0c / / data channel 2 receive address register.
? Define RX_ ADDR_ P3 0x0D / / data channel 3 receive address register.
? Define RX_ ADDR_ P4 0x0e / / data channel 4 receive address register.
? Define RX_ ADDR_ P5 0x0f / / data channel 5 receive address register.
? Define TX_ Addr 0x10 / / send address register#define RX_ PW_ P00x11 / / data channel 0 effective data width setting register.
? Define RX_ PW_ P1 0x12 / / data channel 1 effective data width setting register.
? Define RX_ PW_ P2 0x13 / / data channel 2 effective data width setting register.
? Define RX_ PW_ P3 0x14 / / data channel 3 effective data width setting register.
? Define RX_ PW_ P4 0x15 / / data channel 4 effective data width setting register.
? Define RX_ PW_ P5 0x16 / / valid data width setting register of data channel 5.
? Define FIFO_ Status 0x17 / / FIFO status register.
/ / uchar sta// State variable.
? Define Rx_ DR (STA & 0x40) / / receive successful interrupt flag.
? Define TX_ DS (STA & 0x20) / / transmit success interrupt flag.
? Define Max_ RT (STA & 0x10) / / resend overflow interrupt flag.
sbit CE=P1 ^ 5
sbit IRQ=P1^0;.
sbit CSN=P1^4;.
sbit MOSI=P1^2;.
sbit MISO=P1^1;.
sbit SCK=P1^3;.
//sbit key=P1^0;.
sbit LED=P0^0;.
sbit DQ=P1^6;.
uchar code TX_ Addr[]={0x34.
0x43,0x10,0x10,0x01};.
//uchar code TX_ Buffer[]={0xfe.
0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x00};.
uchar RX_ Buffer[RX_ DATA_ WITDH];.
uchar Temp_ Value[]={0x00.
0x00};.
uchar Temp=0;.
uchar Display_ Digit[]={0.
0,0,0};.
bit DS18B20_ IS_ OK=1;.
uchar code df_ tab[]={0.
1,1,2,3,3,4,4,5,6,6,7,8,8,9,9};// decimal fraction.
void _ delay_ tus(uint x).
{.
while(--x);.
}.
void _ delay_ us(uint x).
{.
uint i.
j;.
for (j=0; jfor (i=0; i<12; i++);.
}.
void _ delay_ ms(uint x).
{.
uint i.
j;.
for (j=0; jfor (i=0; i<120; i++);. / * entry parameter: no * /.
/ * exit function: status * /.
/ *
uchar DS18B20_ Init(void).
{.
uchar status;.
DQ=1;.
_ delay_ tus(10);.
DQ=0;.
_ delay_ tus(90);.
DQ=1;.
_ delay_ tus(8);.
status=DQ;.
_ delay_ tus(100);.
DQ=1;.
return status;.<
}.
/ * * * /.
/ * function function function: read one byte from DS18B20 * /.
/ * entry parameter: no * /.
/ * exit function: dat (return read data) * /.
/ * * * * * /.
uchar read_ One_ Byte(void).
{.
uchar i.
dat=0;.
DQ=1;.
_ nop_();.
for(i=8; i>0; i--).
{.
DQ=0;.
dat>>=1;.
DQ=1;.
_ nop_();_ nop_();.
if(DQ).
dat|=0x80;.
_ delay_ tus(30);.
DQ=1;.
}.
return dat;. / * exit function: none * /.
/ *_ One_ Byte(uchar dat).
{.
uchar i;.
for(i=8; i>0; i--).
{.
DQ=0;.
DQ=dat&0x01;.
_ delay_ tus(5);.
DQ=1;.
dat>>=1;.<
}.
}.
/ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -_ Temp(void).
{.
uchar ng=0;.
if(DS18B20_ Init()==1).
DS18B20_ IS_ OK=0;.
else.
{.
Write_ One_ Byte(0xcc);.
Write_ One_ Byte(0x44);.
DS18B20_ Init();.
Write_ One_ Byte(0xcc);.
Write_ One_ Byte(0xbe);.
Temp_ Value[0]=Read_ One_ Byte();.
Temp_ Value[1]=Read_ One_ Byte();.
DS18B20_ IS_ OK=1;.
}.
if((Temp_ Value[1]&0xf8)==0xf8).
{.
Temp_ Value[1]=~Temp_ Value[1];.
Temp_ Value[0]=~Temp_ Value[0]+1;.
if(Temp_ Value[0]==0x00).
Temp_ Value[1]++;.
ng=1;.
}.
Display_ Digit[0]=df_ tab[Temp_ Value[0]&0x0f];.
Temp=((Temp_ Value[0]&0xf0)>>4)|((Temp_ Value[1]&0x07)<<4);.
Display_ Digit[3]=Temp/100;.
Display_ Digit[2]=Temp%100/10;.
Display_ Digit[1]=Temp%10;. / * module * /.
/ * entry parameter: none * /.
/ * exit function: none * /.
function: none * /.
function: none * /.
/ * function: none * /.
function: none * /.
function: none * /.
function: none * //*************** ***********************************/.
/*void Display_ Temperature(void).
{.
uchar ng=0;.
if((Temp_ Value[1]&0xf8)==0xf8).
{.
Temp_ Value[1]=~Temp_ Value[1];.
Temp_ Value[0]=~Temp_ Value[0]+1;.
if(Temp_ Value[0]==0x00).
Temp_ Value[1]++;.
ng=1;.
}.
Display_ Digit[0]=df_ tab[Temp_ Value[0]&0x0f];.
Temp=((Temp_ Value[0]&0xf0)>>4)|((Temp_ Value[1]&0x07)<<4);.
Display_ Digit[3]=Temp/100;.
Display_ Digit[2]=Temp%100/10;.
Display_ Digit[1]=Temp%10;.
}.
Display_ LINE1[13]=0x43;.
Display_ LINE1[12]=0xdf;.
Display_ LINE1[11]=Display_ Digit[0]+'0';.
Display_ LINE1[10]='.';.
Display_ LINE1[9]=Display_ Digit[1]+'0';.
Display_ LINE1[8]=Display_ Digit[2]+'0';.
Display_ LINE1[7]=Display_ Digit[3]+'0';.
if(Display_ Digit[3]==0).
Display_ LINE1[7]=' ';.
if(Display_ Digit[2]==0&&Display_ Digit[3]==0).
Display_ LINE1[8]=' ';.
if(ng).
{.
if(Display_ LINE1[8]==' ').
Display_ LINE1[8]='-';.
else if(Display_ LINE1[7]==' ').
Display_ LINE1[7]='-';.
else .
Display_ LINE1[6]='-';.
}.
LCD_ POS(0);.
Show_ String(Display_ LINE0);.
LCD_ POS(0x40);.
Show_ String(Display_ LINE1);.
}.
void main(void).
{.
Init_ LCD();.
Read_ Temp();.
_ delay_ ms(1000);.
while(1).
{.
Read_ Temp();.
if(DS18B20_ IS_ OK).
Display_ Temperature();.
_ delay_ ms(200);.<
}.
} * /.
/ * nRF24L01 initialization * /.
void nRF24L01_ Init(void).
{.
_ delay_ us(2000);.
CE=0;// Standby mode I.
CSN=1
SCK=0;.
IRQ=1;.
}
/ * SPI time series function * /.
uchar SPI_ RW(uchar byte).
{.
uchar i;.
for(i=0; i<8;
{.
if (byte & 0x80) / / if the highest bit of data is 1 / / when accessing a multi byte register, the first thing to read / write is the highest bit of the lowest byte
MOSI=1;// Write 1.
else / / to nRF24L01, otherwise write 0.
MoSi=0
byte<<=1;// SCK=1// SCK is raised.
write one bit data and read one bit data at the same time.
if (MISO).
byte |=0x01
SCK=0;// SCK is pulled down.
}.
return byte// Return read one byte.
}.
/ * SPI write register one byte function * /.
/ * reg: register address * /.
/ * value: one byte (value) * /.
uchar SPI_ W_ Reg(uchar reg.
uchar value).
{.
uchar status;// Return status.
CSN=0//
status=SPI_ RW(reg);// Write register address.
read state at the same time.
SPI_ RW(value);// Write one byte.
CSN=1; / /
return status;// Return status.
}.
/ * spi * /.
uchar SPI_ R_ byte(uchar reg).
{.
uchar reg_ value;.
CSN=0;// SPI film selection.
SPI_ RW(reg);// Write the address.
reg_ value=SPI_ RW(0);// Read the value of the register.
CSN=1
return reg_ value;// Returns the read value.
}.
/ * SPI reads rxfifo register data * /.
/ * reg: register address * /.
/ * * dat_ Buffer: used to store read data * /.
/ * dlen: data length * /.
uchar SPI_ R_ DBuffer(uchar reg.
uchar *Dat_ Buffer,uchar Dlen).
{.
uchar status.
i;.
CSN=0;//
status=SPI_ RW(reg);// Write register address.
simultaneous state.
for (I=0; i{.
Dat_ Buffer[i]=SPI_ RW(0);// Storage data.
}.
CSN=1
return status;.<
}.
/ * SPI writes data to txfifo register * /.
SPI writes data to txfifo register/*Reg: write register address * /.
/ * TX_ Dat_ Buffer: store the data to be sent * /.
/ * dlen: data length * /.
uchar SPI_ W_ DBuffer(uchar reg.
uchar *TX_ Dat_ Buffer,uchar Dlen).
{.
uchar status.
i;.
CSN=0;// SPI chip selection.
start sequence.
status=SPI_ RW(reg);.
for(i=0; i{.
SPI_ RW(TX_ Dat_ Buffer[i]);// Send data.
}.
CSN=1
return status;.<
}.
/ * set the sending mode * /.
void nRF24L01_ Set_ TX_ Mode(uchar *TX_ Data).
{.
CE=0;// Standby (be sure to enter standby mode or power down mode before writing register).
SPI_ W_ DBuffer(W_ REGISTER+TX_ ADDR.
TX_ Addr,TX_ ADDR_ WITDH);/* Write register instruction + receive node address + address width * /.
SPI_ W_ DBuffer(W_ REGISTER+RX_ ADDR_ P0.
TX_ Addr,TX_ ADDR_ WITDH);/* In order to receive the response signal from the device, the address of the receiving channel 0 is the same as that of the sending channel * /.
0SPI_ W_ DBuffer(W_ TX_ PLOAD.
TX_ Data,TX_ DATA_ WITDH);/* Write valid data address + valid data + valid data width * /.
SPI_ W_ Reg(W_ REGISTER+EN_ AA.
0x01);/* Receive channel 0 auto response * /.
SPI_ W_ Reg(W_ REGISTER+EN_ RX_ ADDR.
0x01);/* Enable receive channel 0 * /.
SPI_ W_ Reg(W_ REGISTER+SETUP_ RETR.
0x0a);/* Automatic retransmission delay 250us + 86us, retransmission 10 times * /.
/ / SPI_ W_ Reg(W_ REGISTER+RX_ PW_ P0.
RX_ DATA_ WITDH);.
SPI_ W_ Reg(W_ REGISTER+RF_ CH.
0x40);/*( 2400 + 40) MHz select RF channel 0x40 * /.
SPI_ W_ Reg(W_ REGISTER+RF_ SETUP.
0x07);/* 1Mbps rate, transmit power: 0dbm, LNA gain * /.
SPI_ W_ Reg(W_ REGISTER+CONFIG.
0x0e);/* Transmission mode, power on, 16 bit CRC check, CRC enable * /.
CE=1// Launch.
start_ delay_ ms(5);/* The duration of CE high level is at least 10us * /.
}.
uchar check_ Rec(void).
{.
uchar status;.
sta=SPI_ R_ byte(R_ REGISTER+STATUS);.
if(RX_ DR).
{.
CE=0;.
SPI_ R_ DBuffer(R_ RX_ PLOAD.
RX_ Buffer,RX_ DATA_ WITDH);.
status=1;.
}.
SPI_ W_ Reg(W_ REGISTER+STATUS.
0xff);.
return status;.<
}.
/ * detect response signal * /.
uchar check_ Ack(void).
{.
sta=SPI_ R_ byte(R_ REGISTER+STATUS);/* Read register status * /.
if (TX)_ DS||MAX_ RT) / * if TX_ DS or max_ When RT is 1.
the interrupt and TX are cleared_ FIFO register value * /.
{.
SPI_ W_ Reg(W_ REGISTER+STATUS.
0xff);.
CSN=0;.
SPI_ RW(FLUSH_ TX);.
CSN=1;.
return 0;.
}.
else.
return 1;.
}.
void main(void).
{.
uchar i;.
P0=0xff;.
P1=0xff;.
P2=0xff;.
P3=0xff;.
nRF24L01_ Init();.
Read_ Temp();.
_ delay_ ms(1000);.
while(1).
{.
Read_ Temp();.
if(DS18B20_ IS_ OK).
{.
for(i=0; i {.
LED=~ LED
nRF24L01_ Set_ TX_ Mode(&Display_ Digit[i]);.
_ delay_ ms(100);.
while(Check_ Ack());.
//LED=0;.<
}.
}.
}.
}.
/ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -_ ADDR_ Witdh 5 / / the width of the sending address is set to 5 bytes.
? Define RX_ ADDR_ WITDH 5.
#define TX_ DATA_ WITDH 5.
#define RX_ DATA_ Witdh 5.
/ * * * * * * * /.
/ / nRF24L01 instruction format:
* * * * * * * /.
# define R_ Register 0x00 / / read register.
? Define w_ Register 0x20 / / write register.
? Define R_ RX_ Pload 0x61 / / read RX FIFO valid data.
1-32 bytes. After reading data, the data is cleared and applied to receive mode.
define w_ TX_ Pload 0xa0 / / write TX FIFO valid data.
1-32 bytes. The write operation starts from byte 0 and applies to the transmit mode.
? Define flush_ TX 0xe1 / / clear TX FIFO register.
apply to transmit mode.
define flush_ RX 0xe2 / / clear RX FIFO register.
apply to receive mode.
? Define reuse_ TX_ PL 0xe3 / / reuses the last packet of valid data.
when CE is high,The data packets are retransmitted continuously.
# define NOP 0xff / / null operation.
can be used to read the status register.
/ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
/ / nRF24L01 register address.
# define EN_ AA 0x01 / "auto answer" function register_ RX_ Addr 0x02 / / receive channel enable register.
? Define setup_ Aw 0x03 / / address width setting register.
? Define setup_ Retr 0x04 / / Auto retransmission setting register.
? Define RF_ Ch 0x05 / / RF channel frequency setting register_ Setup 0x06 / / RF setting register.
? Define status 0x07 / / status register.
? Define observe_ TX 0x08 / / transmit detection register.
the#Define CD 0x09 / / carrier detection register.
? Define RX_ ADDR_ P0 0x0a / / data channel 0 receive address register.
? Define RX_ ADDR_ P1 0x0b / / data channel 1 receive address register.
? Define RX_ ADDR_ P2 0x0c / / data channel 2 receive address register.
? Define RX_ ADDR_ P3 0x0D / / data channel 3 receive address register.
? Define RX_ ADDR_ P4 0x0e / / data channel 4 receive address register.
? Define RX_ ADDR_ P5 0x0f / / data channel 5 receive address register.
? Define TX_ Addr 0x10 / / send address register.
? Define RX_ PW_ P00x11 / / data channel 0 effective data width setting register.
? Define RX_ PW_ P1 0x12 / / data channel 1 effective data width setting register.
? Define RX_ PW_ P2 0x13 / / data channel 2 effective data width setting register.
? Define RX_ PW_ P3 0x14 / / data channel 3 effective data width setting register.
? Define RX_ PW_ P4 0x15 / / valid data width setting register of data channel 4.
this register is used to set the valid data width of data channel 4#define RX_ PW_ P5 0x16 / / valid data width setting register of data channel 5.
? Define FIFO_ Status 0x17 / / FIFO status register.
/ / uchar sta// State variable.
? Define Rx_ DR (STA & 0x40) / / receive successful interrupt flag.
? Define TX_ DS (STA & 0x20) / / transmit success interrupt flag.
? Define Max_ RT (STA & 0x10) / / retransmit overflow interrupt flag.
.
sbit CE=P1 ^ 5// Rx / TX mode selection terminal.
sbit IRQ=P1 ^ 0// The interrupt can be masked.
sbit CSN=P1 ^ 4// SPI chip selector / / is SS.
sbit MoSi=P1 ^ 2// SPI host output slave input.
sbit miso=P1 ^ 1// SPI host output slave output.
sbit SCK=P1 ^ 3// SPI clock end.
sbit led=P0 ^ 0
sbit key=P2^0;.
sbit LCD_ RS=P2^2;.
sbit LCD_ RW=P2^1;.
sbit LCD_ EN=P2^0;.
uchar code TX_ Addr[]={0x34.
0x43,0x10,0x10,0x01};.
uchar code TX_ Buffer[]={0xfe.
0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};.
uchar RX_ Buffer[RX_ DATA_ WITDH];.
uchar code Display_ LINE0[]={" FROM NRF24L01:"};.
uchar Display_ LINE1[]={" TEMP: "};.
void _ delay_ us(uint x).
{.
uint i.
j;.
for (j=0; jfor (i=0; i<12; i++);.
}.
void _ delay_ ms(uint x).
{.
uint i.
j;.
for (j=0; jfor (i=0; i<120; i++);.
}.
bit LCD_ Busy (void) / / busy.
{.
bit LCD_ Status;// Return value variable.
LCD_ RS=0;// Read status.
LCD_ RW=1;.
LCD_ EN=1;.
_ nop_();_ nop_();_ nop_();_ nop_();.
LCD_ Status=(bit)(P3&0x80);.
LCD_ EN=0;.
return LCD_ Status;.
}.
void LCD_ Write_ Command (uchar CMD) / / write instruction.
{.
/ / while (LCD)_ Busy());.
LCD_ RS=0;//.
LCD_ RW=0;.
LCD_ EN=0;.
_ nop_();_ nop_();.
P3=cmd;.
_ nop_();_ nop_();_ nop_();_ nop_();.
LCD_ EN=1;.
_ nop_();_ nop_();_ nop_();_ nop_();.
LCD_ EN=0;.
}.
void LCD_ Write_ Data (uchar DAT) / / write data.
{.
/ / while (LCD)_ Busy());// The busy signal should be detected before each write operation.
LCD_ RS=1;.
LCD_ RW=0;.
LCD_ EN=0;.
P3=dat;.
_ nop_();_ nop_();_ nop_();_ nop_();.
LCD_ EN=1;.
_ nop_();_ nop_();_ nop_();_ nop_();.
LCD_ EN=0;.
}.
void Init_ LCD (void) / / initialization of liquid crystal.
{.
1_ delay_ ms(15);// Delay 15ms.
LCD_ Write_ Command(0x38);.
_ delay_ ms(5);.
LCD_ Write_ Command(0x38);.
_ delay_ ms(5);.
LCD_ Write_ Command(0x38);// The busy signal should be detected before each write operation.
/ / while (LCD)_ Busy());.
_ delay_ ms(5);.
LCD_ Write_ Command(0x01);// Clear the screen.
/ / while (LCD)_ Busy());.
_ delay_ ms(5);.
LCD_ Write_ Command(0x38);// Set 16 * 2 display.
5 * 7 dot matrix, 8-bit data interface.
2_ delay_ ms(5);.
//while(LCD_ Busy());.
LCD_ Write_ Command(0x0c);// The cursor is on.
the cursor is not displayed.
_ delay_ ms(5);.
//while(LCD_ Busy());.
LCD_ Write_ Command(0x06);// When a character is read or written, the address pointer is added with one.
and the cursor is added with one.
}.
void LCD_ POS (uchar POS) / / character display position.
the{.
LCD_ Write_ Command(0x80|pos);.
}.
void Show_ String (uchar * STR) / / display string.
{.
while (* STR!=)\ 0').
LCD_ Write_ Data(*str++);.
}.
void nRF24L01_ Init(void).
{.
_ delay_ us(2000);.
CE=0;.
CSN=1;.
SCK=0;.
IRQ=1;.
}.
uchar SPI_ RW(uchar byte).
{.
uchar i;.
for(i=0; i<8; i++).
{.
if(byte&0x80).
MOSI=1;.
else .
MOSI=0;.
byte<<=1;.
SCK=1;.
if(MISO).
byte|=0x01;.
SCK=0;.
}.
return byte;.
}.
uchar SPI_ W_ Reg(uchar reg.
uchar value).
{.
uchar status;.
CSN=0;.
status=SPI_ RW(reg);.
SPI_ RW(value);.
CSN=1;.
return status;.
}.
uchar SPI_ R_ byte(uchar reg).
{.
uchar status;.
CSN=0;.
SPI_ RW(reg);.
status=SPI_ RW(0);.
CSN=1;.
return status;.
}.
uchar SPI_ R_ DBuffer(uchar reg.
uchar *Dat_ Buffer,uchar Dlen).
{.
uchar reg_ value.
i;.
CSN=0;.
reg_ value=SPI_ RW(reg);.
for(i=0; i{.
Dat_ Buffer[i]=SPI_ RW(0);.
}.
CSN=1;.
return reg_ value;.
}.
uchar SPI_ W_ DBuffer(uchar reg.
uchar *TX_ Dat_ Buffer,uchar Dlen).
{.
uchar reg_ value.
i;.
CSN=0;.
reg_ value=SPI_ RW(reg);.
for(i=0; i{.
SPI_ RW(TX_ Dat_ Buffer[i]);.
}.
CSN=1;.
return reg_ value;.
}.
void nRF24L01_ Set_ RX_ Mode(void).
{.
CE=0;// Standby.
/ / SPI_ W_ DBuffer(W_ REGISTER+TX_ ADDR.
TX_ Addr,TX_ ADDR_ WITDH);.
SPI_ W_ DBuffer(W_ REGISTER+RX_ ADDR_ P0.
TX_ Addr,TX_ ADDR_ WITDH);.
SPI_ W_ Reg(W_ REGISTER+EN_ AA.
0x01);.
SPI_ W_ Reg(W_ REGISTER+EN_ RX_ ADDR.
0x01);.
//SPI_ W_ Reg(W_ REGISTER+SETUP_ RETR.
0x0a);.
SPI_ W_ Reg(W_ REGISTER+RX_ PW_ P0.
RX_ DATA_ WITDH);.
SPI_ W_ Reg(W_ REGISTER+RF_ CH.
0x40);.
SPI_ W_ Reg(W_ REGISTER+RF_ SETUP.
0x07);.
SPI_ W_ Reg(W_ REGISTER+CONFIG.
0x0f);.
CE=1;.
_ delay_ ms(5);.
}.
uchar nRF24L01_ RX_ Data(void).
{.
//uchar i.
status;.
sta=SPI_ R_ byte(R_ REGISTER+STATUS);.
if(RX_ DR).
{.
CE=0;.
SPI_ R_ DBuffer(R_ RX_ PLOAD.
RX_ Buffer,RX_ DATA_ WITDH);.
//P3=RX_ Buffer[0];.
SPI_ W_ Reg(W_ REGISTER+STATUS.
0xff);.
CSN=0;.
SPI_ RW(FLUSH_ RX);.
CSN=1;.
return 1;.
}.
else.
return 0;.
}.
void main(void).
{.
uchar i.
RX_ Temp_ Value[RX_ DATA_ WITDH];// ng;.
P0=0xff;.
P1=0xff;.
P2=0xff;.
P3=0xff;.
Init_ LCD();.
nRF24L01_ Init();.
_ delay_ us(1000);.
LCD_ POS(0);.
Show_ String(Display_ LINE0);.
while(1).
{.
nRF24L01_ Set_ RX_ Mode();.
//_ delay_ ms(100);.
if(nRF24L01_ RX_ Data()).
{.
for(i=0; i{.
RX_ Temp_ Value[i]=RX_ Buffer[i];.
LED=~LED;.
}.
}.
Display_ LINE1[7]=RX_ Temp_ Value[3]+'0';.
Display_ LINE1[8]=RX_ Temp_ Value[2]+'0';.
Display_ LINE1[9]=RX_ Temp_ Value[1]+'0';.
Display_ LINE1[10]='.';.
Display_ LINE1[11]=RX_ Temp_ Value[0]+'0';.
Display_ LINE1[12]=0xdf;.
Display_ LINE1[13]=0x43;.
if(RX_ Temp_ Value[3]==0).
Display_ LINE1[7]=' ';.
/*if(RX_ Temp_ Value[2]==0&&RX_ Temp_ Value[3]==0).
Display_ LINE1[8]=' ';.
if(ng).
{.
if(Display_ LINE1[8]==' ').
Display_ LINE1[8]='-';.
else if(Display_ LINE1[7]==' ').
Display_ LINE1[7]='-';.
else .
Display_ LINE1[6]='-';*/.
LCD_ POS(0x40);.
Show_ String(Display_ LINE1);.<
}.
}.
have passed the test.
hope to help you but I have used 315MHz and 433MHz wireless transceiver modules. The receiver module is low-level when there is no received signal, and high-level when there is a signal. There are two ways to play. You can simply receive data through interrupt. This way will occupy your interrupt port, but it is efficient.
another way is to query.
it seems to be less efficient than interrupt, However, due to high-speed processing, there is no sense.
.
you need to know the meaning of the data you wear before you see whether the data is transmitted.
the data is the high-level and low-level signal of 0101.
you can't measure it with a multimeter. If you use an oscilloscope, you have to let it communicate for a long time, and simply add led and large resistance to the data output pin, 5K is OK, When there is data, it will flash.
you can see it even if the low level light is on or the high level light is on.
your data should not be too short.
if it is too short, you can't see it.
.
.
.
Related topics