/*********************************************
功 能:读取序列号并匹配序列号,并读温度值
多功能试验板显示多路温度采集
正常显示2个DS18B20温度
正常读取DS18B20序列号
单片机:STC12C5A60S2
晶 振:11.0592M
作 者:苏义江改编自网络
时 间:2016-8-25
************************************************/
#include #include #define uchar unsigned char #define uint unsigned int sbit RS=P2^7; sbit RW=P2^6; sbit EN=P2^5; sbit DQ=P3^4; //传感器引脚 sbit key=P3^7; sbit d1=P1^3;//指示灯 sbit d2=P1^4; bit st=1; uchar code table0[]={"DuoLuWenDuXS:U "}; uchar code table2[]={"SD: "}; //湿度 uchar code table1[]={"0123456789ABCDEF"}; //现有的2个DS18B20传感器的序列号ROM1,ROM2 uchar DSrom[4][8]={//4个器件每个64位序列号 {0x28,0xff,0x2a,0x0A,0x22,0x04,0x00,0xf6},//ROM1 {0x28,0xFF,0x0b,0x0d,0x20,0x04,0x00,0x0a},//ROM2 {0x28,0x0C,0xBA,0xBA,0x02,0x00,0x00,0x54},//ROM3 {0x28,0xff,0x91,0x14,0x22,0x04,0x00,0xe4}//ROM4 }; int f[4]; //温度数组 int tvalue; //温度值变量 float ftvalue; //温度值变量 uchar fCode[8];//序列号数组 uint warnl=300; //设定温度值高 uint warnh=992;//设定温度值低 void ds1820wr(uchar dat);//写数据 void ds1820rst();//ds1820复位 uchar ds1820rd();//读数据 void DispCode();//读取序列号 uchar tflag;//温度正负标志 //////////lcd1602程序//////////// void delay1ms(uint ms)//延时1毫秒(不够精确的) { uint i,j; for(i=0;i } void wr_com(uchar com)//写指令// { delay1ms(1); RS=0; RW=0; EN=0; P0=com; delay1ms(1); EN=1; delay1ms(1); EN=0; } void wr_dat(uchar dat)//写数据// { delay1ms(1);; RS=1; RW=0; EN=0; P0=dat; delay1ms(1); EN=1; delay1ms(1); EN=0; } void lcd_init()//1602初始化设置// { delay1ms(15); wr_com(0x38); delay1ms(5); wr_com(0x08);delay1ms(5); wr_com(0x01);delay1ms(5); wr_com(0x06);delay1ms(5); wr_com(0x0c);delay1ms(5); } void display(uchar *p)//显示字符串 { while(*p!='