600字范文,内容丰富有趣,生活中的好帮手!
600字范文 > 基于51单片机的智能遥控晾衣架温度湿度光强检测proteus仿真原理图PCB

基于51单片机的智能遥控晾衣架温度湿度光强检测proteus仿真原理图PCB

时间:2022-05-25 09:29:59

相关推荐

基于51单片机的智能遥控晾衣架温度湿度光强检测proteus仿真原理图PCB

功能:

0.本系统采用STC89C52作为单片机

1.LCD1602液晶实时显示当前温度/湿度/光强/晾衣架状态

2.支持手动/自动两种模式

3.自动模式下,当温度>10/湿度<90/光强>80同时满足时,晾衣架将自动晾晒

4.采用DC002作为电源接口可直接输入5V给整个系统供电

原理图:

PCB :

主程序:

/*************************************************************智能晾衣架补充说明:***************************************************************/#include <reg52.h> //头文件#include "stdio.h"#include "delay.h"#include "lcd1602.h"#include "28BYJ48.h"#include "tlc0832.h"#include "dht11.h"#include "infrared.h"#define uchar unsigned char //宏定义#define uint unsigned int/*******************引脚定义*********************/sbit KEY_MODE = P2^0; //自动/手动sbit KEY_OUT= P2^1; //晾晒sbit KEY_IN= P2^2; //回收/*******************变量定义*********************/bit modeFlag = 0; //模式标记。=0手动,=1自动uint light; //光强uint humidity; //湿度uint temp; //温度uint motorCnt = 0;//记录晾衣架位置uchar motorFlag = 2; //标记当前控制状态,=0已经晾晒,=1过程中,=2已经回收bit motorDir = 0; //方向bit dispFlag = 0;bit g_irFlag = 0; //红外接收标志,收到一帧正确数据后置1unsigned char g_irCode[4];uchar dis0[5];/************************* 宏定义 *************************/#define AUTO 0#define MANUAL 1/************************* 函数声明 *************************/void Timer0_Init(void); //初始化定时器0/********************************************************函数名称:void mian()函数作用:主函数参数说明:********************************************************/void main(){IR_INPUT = 1;modeFlag = MANUAL;Timer0_Init(); //初始化定时器0IR_Init();LCD_Init(); //初始化液晶DelayMs(200); //延时有助于稳定LCD_Clear(); //清屏LCD_DispStr(0, 0, "Temp: 0.0 C"); //显示温度LCD_DispOneChar(10, 0, 0xdf); //温度的点LCD_DispStr(0, 1, "HM: 0% LG: 0%");while (1) //死循环{if (dispFlag == 1){dispFlag = 0;DHT11_ReadData(); //读取温湿度值humidity = U8RH_data_H;temp = U8T_data_H;light = 100 - 100 * ReadADC(AIN0_GND) / 255; //读取光强sprintf(dis0, "%3d", temp);LCD_DispStr(5, 0, dis0);sprintf(dis0, "%3d", humidity);LCD_DispStr(3, 1, dis0);sprintf(dis0, "%3d", light);LCD_DispStr(12, 1, dis0);}if (KEY_MODE == 0){DelayMs(50);if (KEY_MODE == 0){modeFlag = ~modeFlag;}while (KEY_MODE == 0);}else if (g_irFlag == 1 && g_irCode[2] == IRCodeMap[8][0]){modeFlag = ~modeFlag;g_irFlag = 0;}if (modeFlag == AUTO){LCD_DispOneChar(13, 0, 'A');if (motorFlag == 2) //已经回收状态{LCD_DispOneChar(15, 0, 'C');if (temp > 10 && humidity < 90 && light > 80) //当温度湿度和光强满足条件时,晾晒衣服{motorFlag = 1;motorDir = 1;motorCnt = 0;}}else if (motorFlag == 0) //已经晾晒状态{LCD_DispOneChar(15, 0, 'O');if (temp > 10 && humidity < 90 && light > 80) //当温度湿度和光强满足条件时,晾晒衣服{;}else{motorFlag = 1;motorDir = 0;motorCnt = 128;}}}else{LCD_DispOneChar(13, 0, 'M');if (motorFlag == 2) //已经回收状态{LCD_DispOneChar(15, 0, 'C');if (KEY_OUT == 0) //当温度湿度和光强满足条件时,晾晒衣服{DelayMs(50);if (KEY_OUT == 0){motorFlag = 1;motorDir = 1;motorCnt = 0;}while (KEY_OUT == 0);}else if (g_irFlag == 1 && g_irCode[2] == IRCodeMap[7][0]){motorFlag = 1;motorDir = 1;motorCnt = 0;g_irFlag = 0;}}else if (motorFlag == 0) //已经晾晒状态{LCD_DispOneChar(15, 0, 'O');if (KEY_IN == 0) //当温度湿度和光强满足条件时,晾晒衣服{DelayMs(50);if (KEY_IN == 0){motorFlag = 1;motorDir = 0;motorCnt = 128;}while (KEY_IN == 0);}else if (g_irFlag == 1 && g_irCode[2] == IRCodeMap[6][0]){motorFlag = 1;motorDir = 0;motorCnt = 128;g_irFlag = 0;}}}if (motorFlag == 1){LCD_DispOneChar(15, 0, 'D');if (motorDir == 1){motorCnt++;motor_z();if (motorCnt == 128){motorFlag = 0;}}else{motorCnt--;motor_f();if (motorCnt == 0){motorFlag = 2;}}}}}/*------------------------------------------------定时器初始化子程序------------------------------------------------*/void Timer0_Init(void){TMOD |= 0x01; //使用模式1,16位定时器,使用"|"符号可以在使用多个定时器时不受影响TH0 = (65536 - 18432) / 256; //重新赋值 20msTL0 = (65536 - 18432) % 256;EA = 1; //总中断打开ET0 = 1; //定时器中断打开TR0 = 1; //定时器开关打开}/*------------------------------------------------定时器中断子程序------------------------------------------------*/void Timer0_Interrupt(void) interrupt 1{static unsigned char time20ms = 0;TH0 = (65536 - 18432) / 256; //重新赋值 20msTL0 = (65536 - 18432) % 256;time20ms++;if (time20ms > 50){time20ms = 0;dispFlag = 1; //显示标志位置1}}/***************************************************************************************************************************************红外解码定时器程序**********************************************************************************************************************************************///外部中断解码程序_外部中断1void Ext1_Interrupt(void) interrupt 2{unsigned char i, j;unsigned char byt;unsigned int time;time = IR_GetLowTime();if ((time < 7833) || (time > 8755)){IE1 = 0;return;} //找到启始码time = IR_GetHighTime();if ((time < 3686) || (time > 4608)) //时间判定范围为4.0~5.0ms,{//超过此范围则说明为误码,直接退出IE1 = 0;return;}//接收并判定后续的4 字节数据for (i = 0; i < 4; i++) //循环接收4 个字节{for (j = 0; j < 8; j++) //循环接收判定每字节的8 个bit{//接收判定每bit 的560us 低电平time = IR_GetLowTime();if ((time < 313) || (time > 718)) //时间判定范围为340~780us,{//超过此范围则说明为误码,直接退出IE1 = 0;return;}//接收每bit 高电平时间,判定该bit 的值time = IR_GetHighTime();if ((time > 313) && (time < 718)) //时间判定范围为340~780us,{//在此范围内说明该bit 值为0byt >>= 1;//因低位在先,所以数据右移,高位为0}else if ((time > 1345) && (time < 1751)) //时间判定范围为1460~1900us,{//在此范围内说明该bit 值为1byt >>= 1; //因低位在先,所以数据右移,byt |= 0x80;//高位置1}else //不在上述范围内则说明为误码,直接退出{IE1 = 0;return;}}g_irCode[i] = byt; //接收完一个字节后保存到缓冲区}g_irFlag = 1; //接收完毕后设置标志IE1 = 0; //退出前清零INT1 中断标志}/*******************************************************************************************************************************************************************************************************************************************************************************************************/

仿真演示视频:

/video/BV14b4y1x7rr/

实物演示视频:

/video/BV1vT4y1S7vz/

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。