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


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

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

    PCB :
    在这里插入图片描述

    主程序:

    /*************************************************************
                            智能晾衣架
    
    补充说明:
    ***************************************************************/
    #include  //头文件
    #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; //红外接收标志,收到一帧正确数据后置1
    unsigned 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(); //初始化定时器0
        IR_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; //重新赋值 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
    void 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 值为0
                    byt >>= 1;                    //因低位在先,所以数据右移,高位为0
                }
                else if ((time > 1345) && (time < 1751)) //时间判定范围为1460~1900us,
                {                                        //在此范围内说明该bit 值为1
                    byt >>= 1;                           //因低位在先,所以数据右移,
                    byt |= 0x80;                         //高位置1
                }
                else //不在上述范围内则说明为误码,直接退出
                {
                    IE1 = 0;
                    return;
                }
            }
            g_irCode[i] = byt; //接收完一个字节后保存到缓冲区
        }
        g_irFlag = 1; //接收完毕后设置标志
        IE1 = 0;    //退出前清零INT1 中断标志
    }
    /**************************************************************************************************
    ***************************************************************************************************
    **************************************************************************************************/
    
    
    • 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
    • 208
    • 209
    • 210
    • 211
    • 212
    • 213
    • 214
    • 215
    • 216
    • 217
    • 218
    • 219
    • 220
    • 221
    • 222
    • 223
    • 224
    • 225
    • 226
    • 227
    • 228
    • 229
    • 230
    • 231
    • 232
    • 233
    • 234
    • 235
    • 236
    • 237
    • 238
    • 239
    • 240
    • 241
    • 242
    • 243
    • 244
    • 245
    • 246
    • 247
    • 248
    • 249
    • 250
    • 251
    • 252
    • 253
    • 254
    • 255
    • 256
    • 257
    • 258
    • 259
    • 260
    • 261
    • 262
    • 263
    • 264
    • 265
    • 266
    • 267
    • 268
    • 269
    • 270
    • 271
    • 272
    • 273
    • 274
    • 275
    • 276
    • 277
    • 278
    • 279
    • 280
    • 281
    • 282
    • 283
    • 284
    • 285
    • 286
    • 287
    • 288
    • 289
    • 290
    • 291
    • 292
    • 293
    • 294
    • 295
    • 296
    • 297
    • 298
    • 299
    • 300
    • 301
    • 302
    • 303
    • 304
    • 305
    • 306

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

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

  • 相关阅读:
    R-install_miniconda()卸载 | conda命令行报错及解决方法
    【MySQL面试复习】谈一谈你对SQL的优化经验
    阿里面试官问的 Redis 太刁钻,索性整理出所有大厂的 Redis 面试题,拿下麻烦的面试官
    笔记--autosar是什么
    flex布局 H5携程移动端头部个人中心和图标 (三)
    H指数----题解报告
    pwnable-1-fd
    elasticsearch基本操作
    剑指Offer || 044.在每个树行中找最大值
    作为外贸业务员,为什么我经常随机轻松 就“捡“到精准潜在客户
  • 原文地址:https://blog.csdn.net/jimo167913/article/details/128076876