博客
关于我
51单片机 蓝牙/WiFi无线遥控智能家居系统设计 仿真 实物 串口 音乐 蓝牙 继电器 PWM 温度
阅读量:364 次
发布时间:2019-03-04

本文共 2754 字,大约阅读时间需要 9 分钟。

51单片机蓝牙/WiFi无线遥控智能家居系统设计

本系统基于51单片机,通过蓝牙/WiFi无线技术实现对智能家居设备的远程控制。系统主要功能包括PWM控制小灯亮度、播放天空之城音乐以及显示DS18B20温度等。

PWM控制小灯亮度

系统支持通过PWM调节LED灯的占空比。占空比越高,小灯亮度越高;占空比越低,小灯亮度越低。通过调节PWM占空比,可以实现对灯亮度的精确控制。

音乐播放功能

系统集成无源蜂鸣器,支持播放天空之城音乐。音乐播放通过定时器和中断控制实现,确保音乐的流畅播放和及时停止。

温度显示功能

系统集成DS18B20温度传感器,能够实时显示环境温度。通过简易的数据采集和显示逻辑,用户可以轻松查看当前温度数据。

代码逻辑说明

void main() {    LCD_init();    SerInit();    Print_Str("test");    DULA=1;    P0=0X00;    DULA=0;    WELA=1;    P0=0X00;    WELA=0;    while (1) {        if (mode == 1) {            u = 0;            while (music0[u] != 0xff) {                C = 460830 / music0[u];                TH0 = (8192 - C) / 32;                TL0 = (8192 - C) % 32;                TR0 = 1;                for (t = 0; t < music0_JP[u]; t++)                    delay1();                TR0 = 0;                u++;            }            TR0 = 0;            sound = 1;        } else if (mode == 2) {            temp = getTmpValue();            DisplayTEMP(temp);            sound = 1;            delayMs(10);        }    }}void Uart_isr() interrupt 4 {    if (RI) {        Txd_data = SBUF;        RI = 0;        SBUF = Txd_data;        while (!TI);        TI = 0;        if (Txd_data == '1') {            WELA=1;            P0=0X00;            WELA=0;            mode = 0;            init_timer0_pwm();        } else if (Txd_data == '2') {            if (ZHANKONGBI < 9) {                ZHANKONGBI++;                SBUF = '0' + ZHANKONGBI;                while (!TI);                TI = 0;            } else if (Txd_data == '3') {                if (ZHANKONGBI > 0) {                    ZHANKONGBI--;                    SBUF = '0' + ZHANKONGBI;                    while (!TI);                    TI = 0;                }            } else if (Txd_data == '4') {                init_timer0_yinyue();                mode = 1;                WELA=1;                P0=0X00;                WELA=0;            } else if (Txd_data == '5') {                mode = 5;                WELA=1;                D6RL=1;                WELA=0;            } else if (Txd_data == '6') {                mode = 5;                WELA=1;                D6RL=0;                WELA=0;            } else if (Txd_data == '7') {                mode = 2;                WELA=1;                P0=0X00;                WELA=0;            }        }}sbit LED = P1 ^ 0;void timer0_server() interrupt 1 {    if (mode == 0) {        TH0 = (65536 - 1000) / 256;        TL0 = (65536 - 1000) % 256;        pwm_count++;        if (pwm_count == 10) {            pwm_count = 0;            LED = 0;        }        if (ZHANKONGBI == pwm_count) {            LED = 1;        }    } else if (mode == 1) {        sound = !sound;        TH0 = (8192 - C) / 32;        TL0 = (8192 - C) % 32;    }}

转载地址:http://nuce.baihongyu.com/

你可能感兴趣的文章
npm安装教程
查看>>
npm报错Cannot find module ‘webpack‘ Require stack
查看>>
npm报错Failed at the node-sass@4.14.1 postinstall script
查看>>
npm报错fatal: Could not read from remote repository
查看>>
npm报错File to import not found or unreadable: @/assets/styles/global.scss.
查看>>
npm报错TypeError: this.getOptions is not a function
查看>>
npm报错unable to access ‘https://github.com/sohee-lee7/Squire.git/‘
查看>>
npm淘宝镜像过期npm ERR! request to https://registry.npm.taobao.org/vuex failed, reason: certificate has ex
查看>>
npm版本过高问题
查看>>
npm的“--force“和“--legacy-peer-deps“参数
查看>>
npm的安装和更新---npm工作笔记002
查看>>
npm的常用操作---npm工作笔记003
查看>>
npm的常用配置项---npm工作笔记004
查看>>
npm的问题:config global `--global`, `--local` are deprecated. Use `--location=global` instead 的解决办法
查看>>
npm编译报错You may need an additional loader to handle the result of these loaders
查看>>
npm设置淘宝镜像、升级等
查看>>
npm设置源地址,npm官方地址
查看>>
npm设置镜像如淘宝:http://npm.taobao.org/
查看>>
npm配置安装最新淘宝镜像,旧镜像会errror
查看>>
NPM酷库052:sax,按流解析XML
查看>>