Design of intelligent air conditioning control system based on 51 single-chip microcomputer (simulation + code + schematic diagram + report + video explanation)

Intelligent air-conditioning control system based on 51 single-chip microcomputer

1 Development environment

Simulation diagram: proteus8.9 or above

Program code: KEIL4/KEIL5

Schematic/PCB:AD

Design number: A0003

Explain the demonstration video

video

Video explanation of intelligent air conditioning control system based on 51 single chip microcomputer

2 Function Description Introduction

Air-conditioning temperature control system based on 51 single-chip microcomputer

Consists of STC89C51 microcontroller + LCD1602 liquid crystal display + L298N control module + DC motor + DS18B20 temperature sensor

Specific functions:

(1) Realize the control of the motor by L298N, and use LCD1602 to display the temperature directly and clearly;

(2) Realize the control of the motor speed based on the measured temperature (using the motor to simulate the frequency conversion system of the air conditioner);

(3) In automatic mode, the higher the temperature, the higher the duty and the faster the revolution. In manual mode, the motor speed can be controlled by pressing the buttons.

3 Simulation diagram

img

4 programs

4.1 Project documents

img

4.2 code

img

main function

#include<REG52.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
uchar num=0;
bit flang;
sbit IN1=P3^5;
sbit IN2=P3^6;
sbit PWM1 =P3^7;//风扇控制引脚

uchar xianshi1[] ="TEMP       00.0C";// 内容
uchar xianshi2[] ="000%            ";// 内容
uint    wendu=0;
uchar count;
uchar jd=5;
bit work;	//开关标志

sbit k1=P1^0; //
sbit k2=P1^1; //
sbit k3=P1^2; //
sbit DQ=P2^0; //定义DS18B20总线I/O

//Port Definitions**********************************************************
sbit LcdRs		= P2^5;
sbit LcdRw		= P2^6;
sbit LcdEn  	= P2^7;
sfr  DBPort 	= 0x80;		//P0=0x80,P1=0x90,P2=0xA0,P3=0xB0.数据端口
	void delay(uint z)
{
    
    
   uint a,b;
   for(a=z;a>0;a--)
     for(b=120;b>0;b--);
}
//向LCD写入命令或数据************************************************************
#define LCD_COMMAND			0      // Command
#define LCD_DATA			1      // Data
#define LCD_CLEAR_SCREEN	0x01      // 清屏
#define LCD_HOMING  		0x02      // 光标返回原点
void LCD_Write(bit style, unsigned char input)
{
    
    
	LcdEn=0;
	LcdRs=style;
	LcdRw=0;		_nop_();
	DBPort=input;	_nop_();//注意顺序
	LcdEn=1;		_nop_();//注意顺序
	LcdEn=0;		_nop_();
 delay(1);
}

//设置显示模式************************************************************
#define LCD_SHOW			0x04    //显示开
#define LCD_HIDE			0x00    //显示关	  

#define LCD_CURSOR			0x02 	//显示光标
#define LCD_NO_CURSOR		0x00    //无光标		     

#define LCD_FLASH			0x01    //光标闪动
#define LCD_NO_FLASH		0x00    //光标不闪动

void LCD_SetDisplay(unsigned char DisplayMode)
{
    
    
	LCD_Write(LCD_COMMAND, 0x08|DisplayMode);	
}
//设置输入模式************************************************************
#define LCD_AC_UP			0x02
#define LCD_AC_DOWN			0x00      // default

#define LCD_MOVE			0x01      // 画面可平移
#define LCD_NO_MOVE			0x00      //default

void LCD_SetInput(unsigned char InputMode)
{
    
    
	LCD_Write(LCD_COMMAND, 0x04|InputMode);
}
//初始化LCD************************************************************
void LCD_Initial()
{
    
    
	LcdEn=0;
	LCD_Write(LCD_COMMAND,0x38);           //8位数据端口,2行显示,5*7点阵
	delay(5);
	LCD_Write(LCD_COMMAND,0x38);
	delay(5);
	LCD_SetDisplay(LCD_SHOW|LCD_NO_CURSOR);    //开启显示, 无光标
	delay(5);
	LCD_Write(LCD_COMMAND,LCD_CLEAR_SCREEN);   //清屏
	delay(5);
	LCD_SetInput(LCD_AC_UP|LCD_NO_MOVE);       //AC递增, 画面不动
	delay(5);
}
//液晶字符输入的位置************************
void GotoXY(unsigned char x, unsigned char y)
{
    
    
	if(y==0)
		LCD_Write(LCD_COMMAND,0x80|x);
	if(y==1)
		LCD_Write(LCD_COMMAND,0x80|(x-0x40));
}
//将字符输出到液晶显示
void Print(unsigned char *str)
{
    
    
	while(*str!='\0')
	{
    
    
		LCD_Write(LCD_DATA,*str);
		str++;
		delay(1);
	}
}
void init()// 定时器初始化
{
    
    
	TMOD=0x01;
  TH0=TL0=(256-200); 
  ET0=1;//开定时器0中断
	TR0=1;
	EA=1;//开总中断
}

void Delay_DS18B20(int num);

/*****初始化DS18B20*****/  //探头1
void Init_DS18B20()
{
    
    
  unsigned char x;
  DQ=1;                //DQ复位
  Delay_DS18B20(8);    //稍做延时
  DQ = 0;         //单片机将DQ拉低
  Delay_DS18B20(80);   //精确延时,大于480us
  DQ = 1;         //拉高总线
  Delay_DS18B20(14);
  x = DQ;           //稍做延时后,如果x=0则初始化成功,x=1则初始化失败
  Delay_DS18B20(20);
}


/*****延时子程序*****/
void Delay_DS18B20(int num)
{
    
    
  while(num--) ;
}


/*****写一个字节*****/
void WriteOneChar(unsigned char dat)
{
    
    
  unsigned char i=0;
  for (i=8; i>0; i--)
  {
    
    
    DQ = 0;
    DQ = dat&0x01;
    Delay_DS18B20(5);
    DQ = 1;
    dat>>=1;
  }
}

/*****读一个字节*****/
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);
}



/*****读取温度*****/
unsigned int ReadTemperature(void)	 //读取温度并转换
{
    
    
  unsigned char a=0;
  unsigned char b=0;
  unsigned int t=0;
	 unsigned int tempb20;
  float f_temp=0;
	
  Init_DS18B20();
  WriteOneChar(0xCC);  //跳过读序号列号的操作
  WriteOneChar(0x44);  //启动温度转换
  Init_DS18B20();
  WriteOneChar(0xCC);  //跳过读序号列号的操作
  WriteOneChar(0xBE);  //读取温度寄存器
  a=ReadOneChar();     //读低8位
  b=ReadOneChar();    //读高8位
  
 tempb20=b;
	tempb20<<=8;
	tempb20=tempb20|a;
  
	if((b&0xfc)==0xfc)//负温度
   {
    
    
	    flang=1;
	   	tempb20=((~tempb20)+1);
			  f_temp=tempb20*0.0625;
		 		tempb20=f_temp*10+0.5;

  }
  else//正温度
  {
    
    
		flang=0;
		f_temp=tempb20*0.0625;
		tempb20=f_temp*10+0.5;

 }
	 return tempb20;
}

main()
{
    
    	

	uchar k;
	LCD_Initial();
	
	PWM1=0;
	IN1=0;
	IN2=1;
	init();

while(1)
{
    
    			
	  if(k==0)
			{
    
    
				EA=0;
        wendu=ReadTemperature();//读取温度数据
				EA=1;
	 	  } 
		if(k++>25) k=0;

	if(k1)
	{
    
    		
		if(wendu>=270)
		{
    
    
		 jd=(wendu/10)-27;
		}
		else jd=0;
	}
	else
	{
    
    
	

		 if(k2==0)//PWM+
	    {
    
    
		   delay(10);	
	 	    jd++;
				if(jd>=10)jd=10;
			 while(k2==0);
			}
			
			if(k3==0)//PWM-
	    {
    
    
		    delay(10);
			  if(jd>0) jd--;
			  while(k3==0);
			}		
	}

		if(flang==1)
		xianshi1[10]='-';
		else
		xianshi1[10]=' ';	

    xianshi1[11]=wendu/100+0x30;
	  xianshi1[12]=wendu/10%10+0x30;
	  xianshi1[14]=wendu%10+0x30;
		
		
	  xianshi2[0]=jd/10+0x30;
	  xianshi2[1]=jd%10+0x30;
	 

		GotoXY(0,0);
		Print(xianshi1);
		GotoXY(0,1);
		Print(xianshi2);	
		
 }
}

5 Schematic

The schematic diagram is drawn by AD, and there are differences between the schematic diagram and the simulation diagram. The schematic diagram requires a power supply and a power switch module. The design information is detailed, and the hardware manual information and pictures are detailed. I am not responsible for hardware debugging, and some basic skills are required to make the real thing.

img

6 Components list

  1. Universal board 9*15

  2. DC power socket

  3. Self-locking switch

  4. 2.2K resistor*1

  5. STC89C51 microcontroller

  6. 40-pin IC seat

  7. DC power cord

  8. L298N driver chip

  9. LCD1602 liquid crystal display

  10. 10K exclusion (103)

  11. 10K resistor*2

  12. 10uF capacitor

  13. button*2

  14. Single Pole Double Throw Switch

  15. 12M crystal oscillator

  16. 30Pf ceramic capacitor*2

  17. 3.3V DC motor

  18. wire

  19. Solder

  20. DS18B20 temperature sensor

  21. One piece of universal board

7 video explanation

Code explanation + simulation explanation + simulation demonstration + schematic diagram explanation

img

8 Information list

imgDownload address: Watch the video at the top of the article.

Guess you like

Origin blog.csdn.net/Jack_0220/article/details/128183940