Temperature is:: 1234567890+-,./?
4.2.2温度采集测试及数据
温度采集测试方式:单片机AT89S51接收到DS18B20传来的数据后,在LCD1602上显示原始温度数据及处理过后的温度数据。测试数据如下表: 实际温度℃ -6 -3
原始数据 测试温度℃ 误差 4.2.3无线接收发送测试及数据
无线接收发测试方法:被监测端(发射端)在LCD1602上显示要发射的数据,通过NRF905发射出去;监测端(接收端)接收到数据后,在LCD1602上显示接收到的数据;收发2字节数据。测试数据如下表: 相距(M) <1 3
发射数据 接收数据 16
4.2.4上位计算机通信测试及数据
上位计算机端采用“串口调试器”;我们用一下方式测试串口通信:单片机端接收“串口调试器”发送过来的数据,然后单片机在LCD1602上显示接收到的数据,最后在把数据传回“串口调试器”。 “串口调试器”发送的数据 LCD1602显示的数据 “串口调试器”接收的数据
5总结
我们的设计完成了题目中的基本部分和发挥部分,采用DS18B20温度传感器很准确及时的采集到当前的温度。通过使用NRF905无线发送接收模块将所采集的温度数据能够在0m~300m的范围内准确无误的发送给监控端(接收端)。采用LCD1602显示模块完成了显示部分,利用串口通信完成了在计算机上显示所接收到的温度数据,同时也给系统增加了报警功能。
17
附录
计算机监控软件使用说明:
由于我们把JAVA语言的运行平台JDK进行了集成,所以计算机监控软件无需安装即可使用。其使用方法如下:
1. 解压文件夹下的“PC串口通信程序”。
2. 进入解压后的文件夹,打开“温度监控”文件夹下的“温度监控.exe”即可。
被检测端(发射端)主程序:
#include \#include \#include \#include \ //0 1 2 3 4 5 6 7 8 9 .
unsigned code lcdtable[]={0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x2e};//lcd显示代码;
uchar d1,d2,d3,po4,po3,po2,po1; //个位,十位,百位,1/10位,1/100位,1/1000位,1/10000位; uchar low,tdatalow,tdataheight; //温度低字节,未处理温度的小数位
uint temp,tempold,tempnew,point;//采集温度,旧温度,新温度,实际温度的小数位
void convert(uchar c) { d1=0x00; d2=0x00; d3=0x00; po1=0x00; po2=0x00; po3=0x00; po4=0x00;
d3=(c00)/100; //取百位 d2=(c0)/10; //取十位 d1=(c)/1; //取个位 po4=(point000)/1000; //取1/10位 po3=(point00)/100; //取1/100位 po2=(point0)/10; //取1/1000位 po1=(point)/1; //取1/10000位
18
}
void display()//LCD显示函数 { //显示温度 wr_byte_ram(1,0x42,lcdtable[d3]); //显示百位 wr_byte_ram(1,0x43,lcdtable[d2]); //显示十位 wr_byte_ram(1,0x44,lcdtable[d1]); //显示个位
wr_byte_ram(1,0x45,lcdtable[10]); //显示小数点 wr_byte_ram(1,0x46,lcdtable[po4]); //显示1/10位 wr_byte_ram(1,0x47,lcdtable[po3]); //显示1/100位 wr_byte_ram(1,0x48,lcdtable[po2]); //显示1/1000位 wr_byte_ram(1,0x49,lcdtable[po1]); //显示1/10000位 wr_length_ram(1,0x4A,\显示温度单位 }
void dispNegativeTemp(uchar l) //LCD显示负温度 { convert(l);//转换 wr_length_ram(1,0x40,\ \擦除字符 wr_length_ram(1,0x40,\显示负温度 display(); //LCD显示函数 }
void dispPositiveTemp(uchar l) //LCD显示正温度 { convert(l); //转换 wr_length_ram(1,0x40,\ \擦除字符 wr_length_ram(1,0x40,\显示正温度 display(); //LCD显示函数 }
main() {
19
ini_lcd1602(); //初始化LCD; Config905(); //配置905
wr_length_ram(1,0x00,\显示提示字符 while(1) { temp=0x0000;
temp=read_temp();//读取温度
if(temp!=tempold) //数据有变化者,重新显示 { tempnew=temp; tdatalow=temp&0xff; tdataheight=temp>>8;
point=temp&0x000F;//取小数位; point=point*625;//转换为实际温度
if(temp & 0x8000) //处理负温度 { temp=temp&0x0FFF;//去除高4位的符号; temp=temp^0x0FFF;//取反; temp+=1; temp>>=4; //计算温度,除以16; low=temp|0x00; //取低字节
dispNegativeTemp(low); //LCD显示负温度
low=low|0x80; }
else //处理正温度 { temp>>=4;//计算温度,除以16; low=temp|0x00;//取低字节 }
dispPositiveTemp(low); //LCD显示正温度
SetTxMode();//设置为发送模式
TxPacket(tdataheight,tdatalow);//发送函数 tempold=tempnew;//存最新数据
20