#include
#define uchar unsigned charsbit DQ=P1^4;uchar data temp_data[2]={0x00,0x00};uchar data display[5]={0x00,0x00,0x00,0x00,0x00};unsigned char code ditab[16] ={0x00,0x01,0x01,0x02,0x03,0x03,0x04,0x04,0x05,0x06,0x06,0x07,0x08,0x08,0x09,0x09} ;//共阴数码管uchar code table[11] ={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x00};// 0,1,2,3,4,5 ,6,7,8,9,百位或当最高位十位为0时不显现uchar code table1[10]={0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef};// 0.,1.,2.,3.,4.,5.,6.,7.,8.,9.各位带有小数点的显现//以下为水位显现区域#define uchar unsigned char#define uint unsigned int#define ulong unsigned long#define _rrca_() CY = ACC & 0x01 //发生RRC A指令#define _rlca_() CY = ACC & 0x80 //发生RLC A指令sbit bADcs=P1^7;sbit bADcl=P1^6;sbit bADda=P1^5;sbit flag=P1^3;//sbit str=P2^7;//sbit d=P2^6;//sbit clk=P2^5;bit choose=0;unsigned char data1;unsigned char count;unsigned char cycle;uint ge,xiao1,xiao2;unsigned long data2;unsigned char code tablewe[]={0xFE,0xFD,0xFB,0xF7,0xEF,0xDF,0xBF,0x7F};//自己写的void delay_18b20(unsigned int i){while(i--);}//函数区域水位void Delayus(uchar i){while(--i);}void ad(void){ uchar i;//data1=0;bADcs = 0;//当ADC0832未作业时其CS输入端应为高电平,此刻芯片禁用.bADcl=0;bADda=1;bADcl=1;bADcl=0;//i downbADda=1;bADcl=1;bADcl=0; // 2 downbADda=0;bADcl=1;bADcl=0; // 3 downbADda=1;bADcl=1;bADcl=0; // 4 downfor(i=8;i>0;i--){data1<<=1;bADcl=0;bADcl=1;if(bADda==1) data1|=0x01;bADda=1;}bADcs=1;}void cal(){data2=((ulong)data1*493)/252.5;ge=data2/100;xiao1=(data2%100)/10;xiao2=data2%10;}display2(){P2=tablewe[4]; //P2口低四位位选P0=0x00; //P0口数码管段选第五个数码管不必delay_18b20(50);P2=tablewe[5];P0=table1[ge];delay_18b20(50);P2=tablewe[6];P0=table[xiao1];delay_18b20(50);P2=tablewe[7];P0=table[xiao2];}//以上为水位函数//初始化函数Init_DS18B20(void){unsigned char x=0;DQ=1; //DQ复位delay_18b20(8); //稍做延时DQ=0; //单片机将DQ拉低delay_18b20(80); //准确延时 大于 480usDQ=1; //拉高总线delay_18b20(14);x=DQ; //稍做延时后 假如x=0则初始化成功 x=1则初始化失利delay_18b20(20);}ReadOneChar(void){unsigned char i=0;unsigned char dat=0;for(i=8;i>0;i--){DQ=0; // 给脉冲信号dat>>=1;DQ=1; // 给脉冲信号if(DQ)dat|=0x80 ;delay_18b20(4) ;}return (dat) ;}