基于nRF24E01的無(wú)線溫度采集系統(tǒng)設(shè)計(jì)
RF24E01的主要程序代碼如下:
(1)nRF24E01對(duì)DSl8B20的數(shù)據(jù)讀寫(xiě)是通過(guò)時(shí)間隙處理位和命令字來(lái)確認(rèn)信息交換。根據(jù)“單線復(fù)位脈沖時(shí)序和1-wire presence detect”的時(shí)序圖設(shè)計(jì)程序如下:
uint get_temperature()
{
float wendu;
uchar a,b;
ds_reset();
delay(1); //約2ms
ds_write_byte(0xcc);
ds_write_byte(0xbe);
a=ds_read_byte();
b=ds_read_byte();
temp=b;
return temp;
//返回溫度相關(guān)數(shù)據(jù)
}
(2)發(fā)送函數(shù),把溫度數(shù)據(jù)通過(guò)無(wú)線發(fā)射出去,實(shí)現(xiàn)函數(shù)如下:
void Transmitter(unsigned char b){//發(fā)送函數(shù)
unsigned char mtemp;
CS=1;
Delay100us(0);
for(mtemp=0;mtemptconf.n;mtemp++){
SpiReadWrite(tconf.buf[mtemp]);//發(fā)送發(fā)送器配置字
}
CS=0;
TransmitPacket(b);
//發(fā)送數(shù)據(jù)包
}
}
評(píng)論