主程序,仿真,程序其余见附件
仿真
仿真
程序
单片机源程序如下:
- #include <reg52.h>
- #include "LCD1602.h"
- #include "PCF8591.h"
- #include "DS18B20.h"
- #include "stdio.h"
- unsigned int n1,s1,m1=30,h1=12,t1,i;
- unsigned int num1,num2,num3;
- sbit buzz= P2^3;
- sbit key1= P3^2;
- sbit user001= P2^7;
- sbit user002= P3^4;
- sbit user003= P3^5;
- sbit user004= P3^6;
- sbit user005= P3^7;
- bit keyflag;
- void inter()
- {
- TMOD|=0X01;
- TH0=(65536-45872)/256;
- TL0=(65536-45872)%256;;
- EA=1;
- ET0=1;
- TR0=1;
- }
- void UART_INIT()
- {
- SM0 = 0;
- SM1 = 1;//串口工作方式1
- REN = 1;//允许串口接收
- EA = 1;//开总中断
- ES = 1;//开串口中断
- TMOD|= 0x20;//8位自动重装模式
- TH1 = 0xfd;
- TL1 = 0xfd;//9600波特率
- TR1 = 1;//启动定时器1
- }
- void delay(uint a)
- {
- uint x,y;
- for(x=0;x++;x<a)
- for(y=0;y++;y<110);
- }
-
- void display()
- {
- LcdShowStr(0,0,"T:"); //温度
- DisplayOneStr(2,0,tmp()%1000/100);
- DisplayOneStr(3,0,tmp()%1000%100/10);
- LcdShowStr(4,0,".");
- DisplayOneStr(5,0,tmp()%10);
- LcdShowStr(6,0,"C");
-
- LcdShowStr(8,0,"H:"); //湿度
- DisplayOneStr(10,0,num1/100);
- DisplayOneStr(11,0,num1%100/10);
- DisplayOneStr(12,0,num1%100%10);
- LcdShowStr(13,0,"%");
-
- tmpchange();
- if(key1==0 && buzz==1)
- {
- TI=1;
- printf("Humidity:");//湿度
- printf("%x",num1/100);
- printf("%x",num1%100/10);
- printf("%x",num1%100%10);
- printf("%%\n");
- printf("\n");
- printf("\n");
- printf("Temperature:");//温度
- printf("%x",tmp()%1000/100);
- printf("%x.",tmp()%1000%100/10);
- printf("%x",tmp()%10);
- printf(".C\n");
- printf("\n");
- printf("\n");
- printf("\n");
-
-
-
-
- while(key1==0);
- }
-
-
-
- }
- /******外部中断1初始化******/
- void intlInit()
- {
- EA=1;//开总中断
- EX1=1;//开外部中断1中断
- EX0=1;//开外部中断0中断
- IT1=1;//中断方式1,下降沿方式
- IT0=1;//中断方式1,下降沿方式
- }
- void main()
- {
-
- InitLcd1602();
- inter();
- UART_INIT();
- intlInit();
- TR0=1;
- buzz=0;
- while(1)
- {
-
-
- EA=0;
- num1=du24c02(0);//湿度
- num1=num1/2.55;
-
-
- EA=1;
- delay(5);
- display();
-
- if(num1>50 || num2>50 || num3>50 || tmp()>400)
- {
- buzz=1;
- }
- else if(num1<50 && num2<50 && num3<50 && tmp()<380)
- {
- buzz=0;
- }
- }
- }
- void Time1()interrupt 1
- {
- TH0=(65536-45872)/256;
- TL0=(65536-45872)%256;
- n1++;
- if(n1==20)
- {
- n1=0;
- s1++;
- if(s1==1)
- {
- s1=0;
- tmpchange();
- }
- }
- }
- void UART_SER() interrupt 4
- {
- if(RI==1)
- {
-
- switch(SBUF)
- {
- case 0x01: user001=~user001; break;
- case 0x02: user002=~user002; break;
- case 0x03: user003=~user003; break;
- case 0x04: user004=~user004; break;
- case 0x05: user005=~user005; break;
- }
- RI = 0;//清除接收标志
-
- }
- }
复制代码
所有资料51hei提供下载:
家电.rar
(324.62 KB, 下载次数: 47)
|