系統(tǒng)源程序
發(fā)送側(cè)部分程序:
#include
#include"24l01.h"
#include"1602.h"
#include"18b20.h"
#include"delay.h"
#include"sensor.h"
void main(void)
{
uchar i;
LCD_Init();
TX_Mode();
LCD_Str(0,0,"TX");
while(NRF24L01_Check()) //檢測(cè)24L01
{
LCD_Str(3,0,"Failed!");
delay_ms(200);
LCD_Str(3,0,"Check! ");
delay_ms(200);
}
LCD_Str(3,0,"Ready! ");
delay_ms(500); //顯示Ready! 500ms后清空顯示
LCD_Str(3,0," ");
TX_Mode();
while(1)
{
Check_Sensor_Sta( );
for(i=15;i<18;i++) //發(fā)送傳感器信號(hào)
Buff[i]=SENSOR_STA[i-15]+0x30;
Buff[i]='';
for(i=0;i<8;i++) //發(fā)送溫度數(shù)
Buff[i]=str[i];
Temp_Change(++i);
if(NRF24L01_TxPacket(Buff)==TX_OK)
{
LCD_Str(12,1,"ok! ");
LCD_Str(3,0,"DO0:");
LCD_Str(0,1,"DO1:");
LCD_Str(6,1,"DO2:");
LCD_Char(7,0,Buff[15]);
LCD_Char(4,1,Buff[16]);
LCD_Char(10,1,Buff[15]);
}
else
{
LCD_Str(12,1,"Fail");
}
delay_ms(30000);
}
}
接受測(cè)部分程序
#include
#include"24l01.h"
#include"1602.h"
#include"delay.h"
#include"warn.h"
#define uint unsigned int
uchar Buff[32];
uchar Num[5];
sbit LED0=P0^0;
void Display_Num(uchar x,uchar y,uint num);
void main(void)
{
uint t;
LCD_Init();
LCD_Str(0,0,"RX");
RX_Mode();
while(NRF24L01_Check())//檢測(cè)不到24L01
{
LCD_Str(3,0,"Failed!");
delay_ms(200);
LCD_Str(3,0,"Check! ");
delay_ms(200);
}
LCD_Str(3,0,"Ready! ");
delay_ms(500);
LCD_Str(3,0," ");
while(1)
{
if(NRF24L01_RxPacket(Buff)==0)//一旦接收到信息,則顯示出來.
{
LCD_Str(9,1,"T:");
LCD_Str(3,0,"DO0:");
LCD_Str(9,0,"DO1:");
LCD_Str(3,1,"DO2:");
LCD_Str(12,1,&Buff[9]);
LCD_Char(7,0,Buff[15]);
LCD_Char(13,0,Buff[16]);
LCD_Char(7,1,Buff[17]);
if(Buff[15]==48||Buff[16]==48||Buff[17]==48||Buff[9]>=4+0x30)
warn(2);
}
else delay_ms(1);
t++;
if(t==100)//大約1s鐘改變一次
{t=0;
LED0=!LED0;
}}} |