太原科技大学毕业设计(论文)
32
太原科技大学毕业设计(论文)
附录
控制系统总电路图:
1
太原科技大学毕业设计(论文)
源程序清单:
程序头函数 #include
#include
#define uint unsigned int #define uchar unsigned char //管脚声明 sbit jdq= P1^0;
//继电器
sbit Feng = P2^6; //蜂鸣器 //按键
sbit Key1=P1^4; //设置 sbit Key2=P1^5; //加 sbit Key3=P1^6; //减 sbit Key4=P1^7; //确定 sbit DQ=P2^2;
//定义DS18B20
总线I/O
signed char w,bj,bjx,bjd;
//
温度值全局变量 uint c;
//温度值全局变量
bit bdata flag=0,flag_BJ,flag_off=1; //时间计算
#define Imax 14000 //此处为晶振为11.0592时的取值,
#define Imin 8000 //如用其它频率的晶振时, #define Inum1 1450 //要改变相应的取值。 #define Inum2 700 #define Inum3 3000 //解码变量
unsigned char Im[4]={0x00,0x00,0x00,0x00}; //全局变量 uchar f;
unsigned long m,Tc; unsigned char IrOK; //设置变量 uchar xx=29; //下限 uchar sx=35; //上限 int ds=0; uchar Mode=0; void delay(uint z) { uint i,j; for(i=0;i for(j=0;j<121;j++); } /*****延时子程序*****/ void Delay_DS18B20(int num) { while(num--) ; } /*****初始化DS18B20*****/ void Init_DS18B20(void) { unsigned char x=0; DQ = 1; //DQ复位 Delay_DS18B20(8); //稍做延时 DQ = 0; //单片机将DQ拉低 1 太原科技大学毕业设计(论文) Delay_DS18B20(80); //精确延时,大于480us DQ = dat&0x01; DQ = 1; //拉高总线 Delay_DS18B20(14); x = DQ; //稍做延时后,如果x=0则初始化成功,x=1则初始化失败 Delay_DS18B20(20); } /*****读一个字节*****/ unsigned char 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_DS18B20(4); } return(dat); } /*****写一个字节*****/ void WriteOneChar(unsigned char dat) { unsigned char i=0; for (i=8; i>0; i--) { DQ = 0; Delay_DS18B20(5); DQ = 1; dat>>=1; } } /*****读取温度*****/ unsigned int ReadTemperature(void) { unsigned char a=0; unsigned char b=0; unsigned int t=0; float tt=0; Init_DS18B20(); WriteOneChar(0xCC); //跳过读序号列号的操作 WriteOneChar(0x44); //启动温度转换 Init_DS18B20(); WriteOneChar(0xCC); //跳过读序号列号的操作 WriteOneChar(0xBE); //读取温度寄存器 a=ReadOneChar(); //读低8位 b=ReadOneChar(); //读高8位 t=b; t<<=8; t=t|a; tt=t*0.0625; t= tt*10+0.5; //放大10倍输出并四舍五入return(t); } 2 太原科技大学毕业设计(论文) //=================================== /*****读取温度*****/ write_com(0x06);//当读或写一个字符 是指针后一一位 void check_wendu(void) { c=ReadTemperature()-5; // 获取温度值并减去DS18B20的温漂误差 w=c/10; //计算得到整数位 if(w<0){w=0;} //设置 温度显示上限 if(w>99){w=99;} // 设置温度显示上限 } void Key() { //模式选择 if(Key1==0) { while(Key1==0); Feng=0; Mode++; Display_wd(); if(Mode==4) { Mode=1; Feng=1; } write_com(0x38);//屏幕初始化 write_com(0x0d);//打开显示无光标光 标闪烁 置 位置 3 switch(Mode) { case 1: { write_com(0x80+15);//位置 Feng=1; break; } case 2: { write_com(0x80+0x40+5);//位 Feng=1; break; } case 3: { write_com(0x80+0x40+14);// Feng=1; break; } } } if(Key2==0&&Mode!=0) { while(Key2==0); Feng=0;