基于nRF24E01的無線溫度采集系統(tǒng)設計
RF24E01的主要程序代碼如下:
(1)nRF24E01對DSl8B20的數(shù)據(jù)讀寫是通過時間隙處理位和命令字來確認信息交換。根據(jù)“單線復位脈沖時序和1-wire presence detect”的時序圖設計程序如下:
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;
//返回溫度相關數(shù)據(jù)
}
(2)發(fā)送函數(shù),把溫度數(shù)據(jù)通過無線發(fā)射出去,實現(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ù)包
}
}
評論