《温度采集系统中文版.doc》由会员分享,可在线阅读,更多相关《温度采集系统中文版.doc(8页珍藏版)》请在三一办公上搜索。
1、Piogramming is relatively plex,precision is not hingh LM35.Port configuraturation:Conclusion:pared with TLC549 and LM35 temperature display circuit.This circuit is omitted by the A/D converter TLC549 will temperature digital quantity value transfer to the process of SCM system,so as to simplify the
2、circuit, shortens the working time of the system.So I choose DS18B20 temperature measurement display circuit.Port configuration:Table1AT89C51DS18B20LCD1602Crystal oscillatorRESPACK-8VCCGNDConnectDO-D71-7ConnectDQConnectXTAL1-XTAL21-2ConnectEA(VCC)VCCVDDVCCVCCConnectGNDGNDGNDGNDConnectRSConnectRWConn
3、ectESimulation circuit:When the DS18B20 temperature sensor showed a temperature of 72,the LCD display temperature is also 72.When the DS18B20 temperature sensor showed a temperature of 50,the LCD display temperature is also 50.When the DS18B20 temperature sensor showed a temperature of 20,the LCD di
4、splay temperature is also 20.According to the above figure I can know, my circuit design, the program can be piled to achieve the requirements of the problem. Debugging success.Calculation part:lcd1602_write(0x88);/第二行第一个字符的地址,以后每写入一个字符地址自动加一lcd1602_writedata(a/100)+0x30);lcd1602_writedata(a%100)/10
5、+0x30);/给定数字1的ASC码lcd1602_writedata(a%100)%10+0x30);Reference procedures are as follows:#include #include #include intrins.h #define uchar unsigned char #define uint unsigned int/以上为预编译typedef unsigned char BYTE;bdata unsigned char data_tmp; sbit b_in=data_tmp0; sbit ck=P27; sbit cs=P26; sbit b_data
6、=P25;sbit DQ = P33; /DS18B20的数据口位BYTE TPH; /存放温度值的高字节BYTE TPL; /存放温度值的低字节 sbit RS=P20; sbit RW=P21; sbit ENABLE=P22;/以上设置LCD1602的控制端口void DelayXus(BYTE n);void DS18B20_Reset();void DS18B20_WriteByte(BYTE dat);BYTE DS18B20_ReadByte();unsigned int ADC_DS();unsigned char ADC_TLC() unsigned char dd,x,y;
7、 ck=1; cs=1; b_data=1; cs=0;for(dd=0;dd200;dd+);for (y=0;y8;y+) /b_in=b_data; data_tmp=data_tmp1; b_in=b_data; ck=!ck; ck=!ck; x=data_tmp; cs=1; x=x/2; for(dd=0;dd0;x-)for(y=110;y0;y-);void lcd1602_write(uchar )/写控制命令RW=0;RS=0;/W MODE INSRUCTIONP0=;/取指令ENABLE=0;_nop_();/Tsp1=60nsENABLE=1;_nop_();/Tp
8、w=450nsENABLE=0;_nop_();/Thd2=5ns delay(1);/Tc=1msvoid lcd1602_writedata(uchar date)/写显示数据内容RW=0;RS=1;/W MODE DATAP0=date;/取数据ENABLE=0;_nop_();/Tsp1=60nsENABLE=1;_nop_();/Tpw=450nsENABLE=0;_nop_();/Thd2=5ns delay(1);/Tc=1msvoid lcd1602_init()/显示初始化delay(15);lcd1602_write(0x38);delay(5);lcd1602_write
9、(0x38);delay(5);lcd1602_write(0x38);delay(5);lcd1602_write(0x08);delay(5);/显示关闭lcd1602_write(0x01);delay(5);/显示清屏lcd1602_write(0x06);delay(5);/显示光标移动设置lcd1602_write(0x0c);delay(5);/显示开void main()unsigned char c;unsigned int a,b,x;lcd1602_init();while(1) a=ADC_DS(); c=ADC_TLC(); b=a;b=b&0x000f;x=(b*1
10、0)/16; a=a4;lcd1602_write(0x80);/第一行第一个字符的地址,以后每写入一个字符地址自动加一lcd1602_writedata(T);/给定字符编译器自动编译未ASC码lcd1602_writedata(E);lcd1602_writedata(M);lcd1602_writedata(P);lcd1602_writedata(:);lcd1602_write(0x88);/第二行第一个字符的地址,以后每写入一个字符地址自动加一lcd1602_writedata(a/100)+0x30);lcd1602_writedata(a%100)/10+0x30);/给定数字
11、1的ASC码lcd1602_writedata(a%100)%10+0x30);lcd1602_writedata(.);lcd1602_writedata(x+0x30);lcd1602_writedata(0xdf);lcd1602_writedata(C);lcd1602_write(0xc0);lcd1602_writedata(T);/给定字符编译器自动编译未ASC码lcd1602_writedata(E);lcd1602_writedata(M);lcd1602_writedata(P);lcd1602_writedata(m);lcd1602_writedata(a);lcd16
12、02_writedata(x);lcd1602_writedata(:);lcd1602_write(0xc8); lcd1602_writedata(c/100)+0x30);lcd1602_writedata(c%100)/10+0x30);/给定数字1的ASC码lcd1602_writedata(c%100)%10+0x30);lcd1602_writedata(0xdf);lcd1602_writedata(C);delay(150);/延时/while(1);/死循环 unsigned int ADC_DS() unsigned int a,b,TMP; DS18B20_Reset(
13、); /设备复位 DS18B20_WriteByte(0xCC); /跳过ROM命令 DS18B20_WriteByte(0x44); /开始转换命令 while (!DQ); /等待转换完成 DS18B20_Reset(); /设备复位 DS18B20_WriteByte(0xCC); /跳过ROM命令 DS18B20_WriteByte(0xBE); /读暂存存储器命令 TPL = DS18B20_ReadByte(); /读温度低字节 TPH = DS18B20_ReadByte(); /读温度高字节a=TPH;b=TPL;a=a4;/P1=a+b;TMP=a+b;return TMP;
14、 /while (1);/*延时X*10微秒(STC90C52RC12M)不同的工作环境,需要调整此函数当改用1T的MCU时,请调整此延时函数*/void DelayX0us(BYTE n) while (n-) _nop_(); _nop_(); /*复位DS18B20,并检测设备是否存在*/void DS18B20_Reset() CY = 1; while (CY) DQ = 0; /送出低电平复位信号 DelayX0us(48); /延时至少480us DQ = 1; /释放数据线 DelayX0us(6); /等待60us CY = DQ; /检测存在脉冲 DelayX0us(42)
15、; /等待设备释放数据线 /*从DS18B20读1字节数据*/BYTE DS18B20_ReadByte() BYTE i; BYTE dat = 0; for (i=0; i= 1; DQ = 0; /开始时间片 _nop_(); /延时等待 _nop_(); DQ = 1; /准备接收 _nop_(); /接收延时 _nop_(); if (DQ) dat |= 0x80; /读取数据 DelayX0us(6); /等待时间片完毕 return dat;/*向DS18B20写1字节数据*/void DS18B20_WriteByte(BYTE dat) char i; for (i=0; i= 1; /送出数据 DQ = CY; DelayX0us(6); /等待时间片完毕 DQ = 1; /恢复数据线