将按键、数码管、蜂鸣器、DS18B20结合到一起可以做成一个温度报警器很简单的逻辑,使用按键配合数码管设定报警温度值(超过设定值报警),报警时蜂鸣器持续鸣叫简单写个汇总的程序
void dis_pro(void) { static uint32_t timer_dis; if (work.timer_ms - timer_dis < 9) // 10ms进入一次 return; timer_dis = work.timer_ms; if (work.set_flag == 0) // 非设置模式 { smg_pro(work.tem, 0); if (work.tem > work.set_tem) // 报警 { BEEP_Start(10, 10, 0); } else { BEEP_Stop(); } if (work.key == 0x31) { work.set_flag = 1; // 进入设置模式 } } else { smg_pro(work.set_tem, 1); if (work.key == 0x11) { work.set_tem++; if (work.set_tem > 999) work.set_tem = 0; } else if (work.key == 0x21) { work.set_tem--; if (work.set_tem == 0XFFFF) work.set_tem = 999; } else if (work.key == 0x31) { work.set_flag = 0; // 退出设置模式 } } work.key = 0; }
下边就是汇总的视频链接
https://www.bilibili.com/video/BV1dM4m1C7PS/?vd_source=ed86e3379cd61e3a01b5fb82fc649e60