单片机课程设计报告-基于stc89c52的温度测控系统设计内容摘要:

4。 sbit rd1=P2^5。 sbit beep=P3^2。 uchar buffer0,buffer1,zhi,zhi1。 uchar table[]={0x7f,0xbf,0xdf,0xef,0xff}。 //设置位选 uchar table1[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x7f}。 //前两位数码管码表 uchar table2[]={0xc0,0xcf,0xa4,0x86,0x8b,0x92,0x90,0xc7,0x80,0x82,0x7f,0xf0}。 //后两位数码管码表 uchar code table3[2]=00。 uchar value,num,num1,num2。 uchar temp,temp3,temp1,tempH,tempL,temp5,flag,flag1。 uchar temp55,temp33,tempxiaoH,tempxiaoL。 uint qq。 void delay(uint z) //延时子程序 { uint x,y。 for(x=z。 x0。 x) for(y=110。 y0。 y)。 } void delay_18B20(unsigned int i) //DS18B20 延时子程序,延时 1us { while(i)。 14 } void Init_DS18B20(void) //Ds18b20 初 始化函数 u { uchar x=0。 DQ = 1。 //DQ 复位 delay_18B20(8)。 //稍做延时 ,稳定数据 DQ = 0。 //单片机将 DQ 拉低 delay_18B20(100)。 //精确延时 大于 480us DQ = 1。 //拉高总线 delay_18B20(14)。 //(1560)us x=DQ。 //稍做延时后 如果 x=0 则初始化成功 x=1 则初始化失败 ,采样 delay_18B20(20)。 } void Write_18b20byte(uchar dat)//向 18B20 写一个节, dat 为入口函数 { uchar i。 for (i=8。 i0。 i) //一字节 8 位 { DQ = 0。 DQ = datamp。 0x01。 delay_18B20(5)。 //18b20 采样 DQ = 1。 //拉高 DQ dat=1。 //出口函数, dat 为入口函数 } } uchar Read_18b20byte(void) { uchar i。 uchar dat。 for (i=8。 i0。 i)//判断 8 次移位 7 次 { DQ = 0。 // 给脉冲信号,拉低总线 dat=1。 //可以起延时作用 DQ = 1。 // 给脉冲信号,释放总线后才可以采样 if(DQ) 15 dat|=0x80。 delay_18B20(4)。 } return(dat)。 } void ReadTemp(void) //读取 ds18b20 当前温度 { uchar a,b。 Init_DS18B20()。 //18b20 初始化 Write_18b20byte(0xCC)。 // 跳过读序号列号的操作 Write_18b20byte(0x44)。 // 启动温度转换 delay_18B20(100)。 // 转换需要时间,延时 Init_DS18B20()。 Write_18b20byte(0xCC)。 //跳过读序号列号的操作 Write_18b20byte(0xBE)。 //读取温度寄存器等(共可读 9 个寄存器) 前两个就是温度 delay_18B20(100)。 a=Read_18b20byte()。 //读取温度值低位 b=Read_18b20byte()。 //读取温度值高位 temp=b*16+a/16。 temp1=(a%16)*10/16。 } void beepon(void) { beep=0。 } void beepoff(void) { beep=1。 } void display(uchar one,uchar two,uchar three) { P1=table[0]。 //选中第一个数码管 P0=table1[one]。 //显示 10 位 delay(3)。 16 P1=table[1]。 //选中第二个数码管 P0=table1[two]amp。 0x7f。 delay(3)。 P1=table[2]。 P0=table2[three]。 delay(3)。 P1=table[3]。 P0=table2[11]amp。 0x7f。 delay(3)。 } void keywendu() { uchar temp2,temp22。 temp2=temp。 //整数位 temp22=temp1。 //小数位 rd=0。 if(k1==0) //功能键 { delay(20)。 if(k1==0) { while(!k1)。 //按键消抖程序 flag=1。 P1=table[1]。 P0=0xff。 delay(10)。 //个位不显示 P1=table[2]。 P0=0xff。 delay(10)。 //小数位不显示 while(1) { display(temp2/10,temp2%10,temp22)。 17 if(k1==0) //K1 功能键 { delay(20)。 if(k1==0) { while(!k1)。 num1++。 if(num1==2) num1=0。 //num1=0 修改小数位 //num1=1 修改个位 } } switch(num1) { case 0://小数位 if(k2==0) //case0, K2 功 能键 { delay(20)。 if(k2==0)。
阅读剩余 0%
本站所有文章资讯、展示的图片素材等内容均为注册用户上传(部分报媒/平媒内容转载自网络合作媒体),仅供学习参考。 用户通过本站上传、发布的任何内容的知识产权归属用户或原始著作权人所有。如有侵犯您的版权,请联系我们反馈本站将在三个工作日内改正。