博客
关于我
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/

你可能感兴趣的文章
pandas :将时间戳转换为 datetime.date
查看>>
pandas :将行取消堆叠到新列中
查看>>
pandas :设置编号.最大行数
查看>>
pandas DataFrame 中的自定义浮点格式
查看>>
Pandas DataFrame 的 describe()方法详解-ChatGPT4o作答
查看>>
Pandas DataFrame中删除列级的方法链接解决方案
查看>>
Pandas DataFrame中的列从浮点数输出到货币(负值)
查看>>
Pandas DataFrame中的列从浮点数输出到货币(负值)
查看>>
Pandas DataFrame多索引透视表-删除空头和轴行
查看>>
pandas DataFrame的一些操作
查看>>
Pandas Dataframe的日志文件
查看>>
Pandas df.iterrows() 并行化
查看>>
Pandas drop_duplicates 方法不适用于包含列表的数据框
查看>>
pandas groupby 和过滤器
查看>>
pandas GROUPBY+变换和多列
查看>>
pandas Groupby:创建两列的Groupby时,如何按正确的顺序对工作日进行排序?
查看>>
Pandas matplotlib 无法显示中文
查看>>
pandas PIVOT_TABLE保持索引
查看>>
Pandas Plots:周末的单独颜色,x 轴上漂亮的打印时间
查看>>
pandas to_latex() 转义数学模式
查看>>