|
5黑币
本帖最后由 9丫鬟 于 2021-5-9 21:00 编辑
程序仿真后,k1摆臂开关好用,k2--k6液晶不显示,而且相关联的继电器电路和加热制冷也不行
单片机源程序如下:
- #include <reg52.h>
- #include <intrins.h>
- #include <math.h>
- #define uchar unsigned char
- #define uint unsigned int
- #define ulong unsigned long
- #include "1602.h"
- #include "ad.h"
- #include<DS18B20.h>
- uchar code zifu0[]=" Star "; //开机显示Intelligent beverage machine
- uchar code zifu1[]=" TT00 TM00 TB00 "; //显示各个温度
- unsigned char s,i,j,keynum;
- int ans1,ans2,ans3,ans; //读取的温度寄存器
- uchar heatflag=1;
- //负载
- sbit out=P0^3;
- //蜂鸣器
- sbit beer=P3^7;
- //键盘
- sbit k1=P2^5;
- sbit k2=P2^6;
- sbit k3=P2^7;
- sbit k4=P3^6;
- sbit k5=P3^5;
- sbit k6=P0^7;
- sbit heat=P2^3;
- sbit cry=P2^4;
- sbit hout=P0^2;
- sbit cout=P0^0;
- sbit nout=P0^1;
- void delay_ms1(int x)//延时1ms
- {
- unsigned char i,j;
- for(i=x;i>0;i--)
- for(j=110;j>0;j--);
- }
- void delay(void)//延时5ms
- {
- unsigned char i,j;
- for(i=10;i>0;i--)
- for(j=248;j>0;j--);
- }
- void delay1(void)//延时10ms
- {
- unsigned char i,j,k;
- for(k=10;k>0;k--)
- for(i=20;i>0;i--)
- for(j=248;j>0;j--);
- }
- uchar key_num()
- {
- if(k2 == 0)
- {
- delay_ms1(1);
- if(k2 == 0)
- {
- keynum=2;
- }
- while(!k2);
- }
- if(k3 == 0)
- {
- delay_ms1(1);
- if(k3 == 0)
- {
- keynum=3;
- }
- while(!k3);
- }
- if(k4 == 0)
- {
- delay_ms1(1);
- if(k4 == 0)
- {
- keynum=4;
- }
- while(!k4);
- }
- if(k5 == 0)
- {
- delay_ms1(1);
- if(k5 = 0)
- {
- keynum=5;
- }
- while(!k5);
- }
- if(k6 == 0)
- {
- delay_ms1(1);
- if(k6 == 0)
- {
- keynum=6;
- }
- while(!k6);
- } return keynum;
- }
- //显示参数------------------------------`
- void display()
- {
-
-
- DS18B20_start_change1(); //开始读温度
- ans1=DS18B20_read_date1();
- delay1();
- DS18B20_start_change2(); //开始读温度
- ans2=DS18B20_read_date2();
- delay1();
- DS18B20_start_change3(); //开始读温度
- ans3=DS18B20_read_date3();
- delay1();
- //ans=(ans1+ans2+ans3)/3;
-
- lcd1602_adr(0x43);
- lcd1602_writenumber(0x30+ans1%100/10);
- lcd1602_writenumber(0x30+ans1%10/1);
-
- lcd1602_adr(0x48);
- lcd1602_writenumber(0x30+ans2%100/10);
- lcd1602_writenumber(0x30+ans2%10/1);
- lcd1602_adr(0x4d);
- lcd1602_writenumber(0x30+ans3%100/10);
- lcd1602_writenumber(0x30+ans3%10/1);
- }
- void displayfun(int s)
- {
- switch(s)
- {
- case(1):
- LCD1602_string(1,1," Onekey heating ");//温度低于75可以一键加热
- if(ans1<75){
- heat=0;
- }else{
- heat=1;
- LCD1602_string(1,1," Heating over ");
- }
- break;
- case(2):
- LCD1602_string(1,1," Onekey cooling ");
- if(ans2>5){
- cry=0;
- }else{
- cry=1;
- LCD1602_string(1,1," Cooling over ");
- }
- break;
-
- case(3):
- LCD1602_string(1,1," HOT water out ");// 出水
- break;
- case(4):
- LCD1602_string(1,1," COLD water out ");// 出水
- break;
- case(5):
- LCD1602_string(1,1," NORMAL water out ");// 出水
- break;
- default:break;
- }
- }
- //主函数
- void main()
- {
- unsigned char NUM;
- lcd1602_init(); //初始化显示屏
- LCD1602_string(1,1,zifu0);
- LCD1602_string(2,1,zifu1); //初始化界面
- while(1)
- {
- display();
- if(ans1>110)
- {
- beer=0;
- LCD1602_string(1,1," Temp is high ");
- }
-
- if(k1 == 0)
- {
- delay_ms1(1);
- if(k1 == 0)
- {
- /* if(ans1<70)
- {
- beer=0;
- LCD1602_string(1,1," Temp is cool "); //温度过低<70,不进行工作
- }else{ */
- LCD1602_string(1,1," Working ");
- //MotorRight();
- }
- }
-
- }
- NUM=key_num(); //读按键的位置码
- switch(NUM) //判断按键值
- {
- case (2):cry=1;displayfun(1); break; //K1是开机键
- case (3):heat=1;displayfun(2); break;
- case (4):hout=1;displayfun(3); break;
- case (5):displayfun(4); break;
- case (6):cout=1;displayfun(5); break;
- case (7):nout=1;displayfun(6); break;
- default: break;
- }
- }
复制代码
|
|