• 基于51单片机的智能红外遥控防雨晾衣架 雨滴光强检测系统proteus仿真原理图PCB


    功能:
    0.本系统采用STC89C52作为单片机
    1.LCD1602液晶实时显示当前雨滴/光强/温湿度/晾衣架状态
    2.支持手动/自动两种模式
    3.自动模式下,当雨滴<5/光强<80同时满足时,晾衣架将自动晾晒
    4.采用DC002作为电源接口可直接输入5V给整个系统供电

    原理图:
    在这里插入图片描述

    PCB :
    在这里插入图片描述

    主程序:

    #include  //头文件
    #include "stdio.h"
    #include "delay.h"
    #include "lcd1602.h"
    #include "28BYJ48.h"
    #include "tlc0832.h"
    #include "dht11.h"
    
    #define uchar unsigned char //宏定义
    #define uint unsigned int
    
    /*******************引脚定义*********************/
    sbit KEY_MODE    = P3^6;   //设置键
    sbit KEY_OUT     = P3^5;   //晾晒键
    sbit KEY_IN     = P3^4;   //回收键
    
    /*******************变量定义*********************/
    bit modeFlag = 0; //模式标记。=0手动,=1自动
    uint light;    //光强
    uint water; //雨滴
    uint humidity; //湿度
    uint temp;    //温度
    
    uint motorCnt = 0;     //记录晾衣架位置
    uchar motorFlag = 2;        //标记当前控制状态,=0已经晾晒,=1过程中,=2已经回收
    bit motorDir = 0;        //方向
    
    bit dispFlag = 1;
    
    uchar dis0[16];
    
    /************************* 宏定义 *************************/
    #define AUTO 0
    #define MANUAL 1
    
    /************************* 函数声明 *************************/
    void Timer0_Init(void); //初始化定时器0
    
    /********************************************************
    函数名称:void mian()
    函数作用:主函数
    参数说明:
    ********************************************************/
    void main()
    {
        modeFlag = MANUAL;
    
        Timer0_Init(); //初始化定时器0
    
        LCD_Init();   //初始化液晶
        DelayMs(200); //延时有助于稳定
        LCD_Clear();  //清屏
    
        while (1) //死循环
        {
            if (dispFlag == 1)
            {
                dispFlag = 0;
                
                DHT11_ReadData(); //读取温湿度值
    
                humidity = U8RH_data_H;
                temp = U8T_data_H;
    
                light = 100 - 100 * ReadADC(AIN1_GND) / 255; //读取光强
                water = 100 - 100 * ReadADC(AIN0_GND) / 255; //读取雨滴
    
                sprintf(dis0, "L:%3d%% H:%3d%%", light, humidity);
                LCD_DispStr(0, 0, dis0);
    
                sprintf(dis0, "W:%3d%% T:%3d", water, temp);
                LCD_DispStr(0, 1, dis0);
                LCD_DispOneChar(12, 1, 0xdf);
                LCD_DispOneChar(13, 1, 'C');
            }
    
            if (KEY_MODE == 0)
            {
                DelayMs(50);
                if (KEY_MODE == 0)
                {
                    modeFlag = ~modeFlag;
                }
                while (KEY_MODE == 0)
                    ;
            }
    
            if (modeFlag == AUTO)
            {
                LCD_DispOneChar(15, 0, 'A');
                if (motorFlag == 2) //已经回收状态
                {
                    LCD_DispOneChar(15, 1, 'C');
                    if (light < 80 && water < 5) //当光强满足条件且没下雨时,晾晒衣服
                    {
                        motorFlag = 1;
                        motorDir = 1;
                        motorCnt = 0;
                    }
                }
                else if (motorFlag == 0) //已经晾晒状态
                {
                    LCD_DispOneChar(15, 1, 'O');
                    if (light < 80 && water < 5) //当光强满足条件且没下雨时,晾晒衣服
                    {
                        ;
                    }
                    else //否则回收
                    {
                        motorFlag = 1;
                        motorDir = 0;
                        motorCnt = 128;
                    }
                }
            }
            else
            {
                LCD_DispOneChar(15, 0, 'M');
                if (motorFlag == 2) //已经回收状态
                {
                    LCD_DispOneChar(15, 1, 'C');
                    if (KEY_OUT == 0) //晾晒
                    {
                        DelayMs(50);
                        if (KEY_OUT == 0)
                        {
                            motorFlag = 1;
                            motorDir = 1;
                            motorCnt = 0;
                        }
                        while (KEY_OUT == 0)
                            ;
                    }
                }
                else if (motorFlag == 0) //回收
                {
                    LCD_DispOneChar(15, 1, 'O');
                    if (KEY_IN == 0)
                    {
                        DelayMs(50);
                        if (KEY_IN == 0)
                        {
                            motorFlag = 1;
                            motorDir = 0;
                            motorCnt = 128;
                        }
                        while (KEY_IN == 0)
                            ;
                    }
                }
            }
    
            if (motorFlag == 1)
            {
                LCD_DispOneChar(15, 1, '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; //重新赋值 20ms
        TL0 = (65536 - 18432) % 256;
        EA = 1;  //总中断打开
        ET0 = 1; //定时器中断打开
        TR0 = 1; //定时器开关打开
    }
    /*------------------------------------------------
                    定时器中断子程序
    ------------------------------------------------*/
    void Timer0_Interrupt(void) interrupt 1
    {
        static unsigned char time20ms  = 0;
        TH0 = (65536 - 18432) / 256; //重新赋值 20ms
        TL0 = (65536 - 18432) % 256;
        time20ms++;
    
        if (time20ms > 50)
        {
            time20ms = 0;
            dispFlag = 1; //读标志位置1
        }
    
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159
    • 160
    • 161
    • 162
    • 163
    • 164
    • 165
    • 166
    • 167
    • 168
    • 169
    • 170
    • 171
    • 172
    • 173
    • 174
    • 175
    • 176
    • 177
    • 178
    • 179
    • 180
    • 181
    • 182
    • 183
    • 184
    • 185
    • 186
    • 187
    • 188
    • 189
    • 190
    • 191
    • 192
    • 193
    • 194
    • 195
    • 196
    • 197
    • 198
    • 199
    • 200
    • 201
    • 202
    • 203
    • 204
    • 205
    • 206
    • 207

    仿真演示视频:
    https://www.bilibili.com/video/BV1d3411L7sM/

    实物演示视频:
    https://www.bilibili.com/video/BV1X8411W7JR/

  • 相关阅读:
    如何从戴尔笔记本电脑恢复数据?
    2310C++子类已调用基类构造器
    SpringBoot+Mybatis+Thymeleaf实现垃圾分类系统
    js实现拖拽移动
    AVS感知无损压缩标准概述——视觉无损质量等级视频浅压缩
    【现代控制理论期末考点】
    关于射频同轴连接器的功率容量探讨
    赴日IT必备!日本技术人文签证怎么拿?
    tp6 + swagger 配置文档接口
    类和函数成员
  • 原文地址:https://blog.csdn.net/jimo167913/article/details/127846326