摘 要
本设计以ESP32单片机为控制核心,致力于打造一个功能全面的远程监控系统。该系统主要用于实时监控高塔液位的变化,确保监控过程的智能化与实时性。通过LCD显示器,系统能够实时展示当前的液位值,使用户能够直观了解液位状态。当液位超过预设的上限或下限时,系统会立即触发报警机制,包括蜂鸣器发出警报声和LED灯闪烁,以提醒操作人员及时采取措施。
在设计过程中,我们根据远程监控系统的主要功能需求,提出了详细的设计方案,并进行了充分的论证。设计方案涵盖了硬件和软件两大部分。硬件部分主要包括单片机最小系统、矩阵键盘模块、无线收发模块、显示模块以及报警模块。其中,单片机选用了宏晶科技公司的ESP32,以其强大的性能和稳定性确保系统的稳定运行。矩阵键盘模块用于输入模拟液位数据值,这些数据将通过无线模块进行传输和处理。1602液晶显示器则用于显示高塔液位信息,并与输入值进行比较,以便操作人员作出判断。报警模块则包括发光二极管和蜂鸣器,用于在异常情况发生时提供及时的报警提示。
软件部分采用了模块化的设计方法,主要包括主程序、无线发射模块子程序、无线接收子程序、按键检测子程序、液晶显示子程序以及报警模块子程序。这种模块化的设计使得系统更加易于调试和维护,同时也提高了系统的可扩展性和灵活性。
在完成软硬件设计后,我们对系统进行了联调测试。测试结果表明,系统能够准确地将模拟液位数据通过nrf24l01无线模块进行传输,并在另一个nrf24l01无线模块上接收并解码显示。当接收到的数值超过1000或小于10时,系统会立即触发蜂鸣器和发光二极管的报警机制,确保操作人员能够及时收到报警信息。
关键词:nrf24l01;单片机;远程传输;显示器
Abstract
This design takes ESP32 MCU as the control core, and is committed to build a fully functional remote monitoring system. The system is mainly used to monitor the change of the high tower liquid level in real time to ensure the intelligence and real-time performance of the monitoring process. Through the LCD display, the system can display the current level value in real time, enabling the user to intuitively understand the level status. When the liquid level exceeds the preset upper or lower limit, the system immediately triggers the alarm mechanism, including the buzzer and flashing LED light to remind the operator to take timely action.
In the design process, we propose the detailed design scheme according to the main functional requirements of the remote monitoring system, and fully demonstrated it fully. The design scheme covers both the hardware and the software parts. The hardware part mainly includes the microcontroller minimum system, matrix keyboard module, wireless transceiver module, display module and alarm module. Among them, the single-chip microcomputer selects the ESP32 of Hongjing Technology Company, to ensure the stable operation of the system with its strong performance and stability. The matrix Keyboard module is used to input analog level data values, which will be transmitted and processed through the wireless module. The 1602 LCD display is used to display the high tower liquid level information and compare it with the input value for the operator to make a judgment. The alarm module includes a light-emitting diode and a buzzer to provide prompt alarm prompts when abnormal situations occur.
The software part adopts a modular design method, mainly including master, wireless transmitter module, wireless reception program, key detection, LCD display and alarm module. This modular design makes the system easier to debug and maintain, while also improving its scalability and flexibility.
After completing the hardware and software design, we conducted a joint adjustment test on the system. The test results show that the system can accurately transmit the simulated liquid level data through the nrf24l01 wireless module, and receive and decode it on another nrf24l01 wireless module. When the received value exceeds 1000 or less than 10, the system will immediately trigger the alarm mechanism of the buzzer and light emitting diode, ensuring that the operator can receive the alarm information in time.
Key words: nrf24l01; single-chip microcomputer; remote transmission; monitor
目 录
1概述 1
1.1 课题研究背景与意义 1
1.2 课题设计内容 1
2方案设计选择 2
2.1单片机选择 2
2.1无线装置选择 3
2.2显示模块选择 4
2.4总体方案 4
3硬件电路设计 5
3.1最小系统模块 5
3.2矩阵键盘电路设计 6
3.3无线收发电路设计 7
3.3.1 nrf24l01概述 8
3.3.2引脚功能及描述 8
3.3.3工作模式 9
3.3.4工作原理 10
3.3.5配置字 10
3.4 LCD显示模块 11
4软件系统设计 13
4.1总流程图设计 13
4.2矩阵键盘电路软件设计 14
4.3无线发射模块软件设计 15
4.4无线接收模块软件设计 16
4.5 LCD1602显示器软件设计 17
4.6蜂鸣器报警电路 18
5系统的调试及实验结果 20
5.1 调试步骤 20
5.2实验结果 20
结 论 22
参考文献 23
致 谢 24
附 录 25
附录1:发送电路部分程序 25
附录2: 35
发送电路电路图: 35
接收部分电路图: 36
附录3:元器件清单 37
无线数据传输技术优点多,不仅简单易用,成本低,效率高,收益长远,抗干扰能力强,再结合微机和互联网进行使用便可以胜过传统有线传输。
1.2 课题设计内容
本课题以ESP32单片机作为控制核心,并结合相关的外围电路,设计并实现了一个远程监控系统。该系统具备多项关键功能,包括数据采集、无线数据发送、实时数据显示以及异常报警。以下是对这些功能的详细阐述:
a)利用矩阵键盘进行数据采集:通过矩阵键盘输入或选择需要监控的参数,如液位设定值等,这些数据将被系统采集并用于后续的监控和判断。
b)无线模块实现数据收发:系统采用无线模块(如Wi-Fi或蓝牙等,具体根据任务书未详细提及的实际情况确定)来发送和接收数据。这样,监控设备可以远程传输实时数据到指定的接收端,实现远程监控的目的。
c)LCD显示屏实时显示数据:系统配备有LCD显示屏,用于实时显示当前液位值以及其他相关参数。这样,用户可以直观地了解当前监控状态,便于及时发现问题并采取措施。
d)数据异常时触发蜂鸣器报警:当系统检测到液位值超过预设的上限或下限时,将自动触发蜂鸣器进行报警。同时,LED灯也会闪烁以提供视觉上的报警提示。这种双重报警机制可以确保用户及时注意到异常情况,并采取相应的应急措施。
2方案设计选择
由于目前远程控制技术的控制方式是多种多样的,我们通常把他们分为无线遥控、声控和红外遥控。现在讨论一下这几种无线控制方式的优点和缺点。
2.1单片机选择
单片机作为信息时代的产物,收到许许多多的企业和个人青睐,从目前的发展状况和应用的角度上来看,可以将单片机粗略的分为总线型单片机。非总线型单片机、通用型单片机、专用型单片机、商业应用型单片机、企业生产型单片机、家庭应用型单片机等。
总线型单片机提供并行总线。在其内部设置诸多总线。例如:控制总线可以用来控制外部引脚、数据总线用于与外部进行数据传输、地址总线用来寻址等。
控制型单片机主要应用于大型机械生产加工上以及各类家电的控制上。一般来说,工控型单片机具有运算能力强、寻址范围大等优点:家用型单片机一般是专用型的,比如我们生活中的空调、电视机、电饭锅、电磁炉等都需要用到这种封装小、价格低、易操作、集成度高、抗干扰较强的单片机。此单片机针对性较强,但比较局性。
通用型单片机的适用范围较广,既能适用于工业控制,又能适用于家庭生活等。缺点是没有针对性。这种单片机的应用较多,资料齐全,易上手。对于初学者是一个不错的选择。
ESP32单片机是宏晶科技有限公司生产的一种适用性强、实用性高、能耗低、具有比较大的可编程空间、被市场广泛认可的单片机。ESP32单片机选用经典的MCS-51作为内核使用,以此为基础做了许多的改良使得芯片的功能比传统的51单片机更加的强大。因为单片机提供了8K的可编程flash存储,所以使得单片机可以在很多的可嵌入式系统中得以使用,并发挥出良好的性能。
#ifndef __SYS_H
#define __SYS_H
#include "stm32f4xx.h"
#define BITBAND(addr, bitnum) ((addr & 0xF0000000)+0x2000000+((addr &0xFFFFF)<<5)+(bitnum<<2))
#define MEM_ADDR(addr) *((volatile unsigned long *)(addr))
#define BIT_ADDR(addr, bitnum) MEM_ADDR(BITBAND(addr, bitnum))
//IO口地址映射
#define GPIOA_ODR_Addr (GPIOA_BASE+20) //0x40020014
#define GPIOB_ODR_Addr (GPIOB_BASE+20) //0x40020414
#define GPIOC_ODR_Addr (GPIOC_BASE+20) //0x40020814
#define GPIOD_ODR_Addr (GPIOD_BASE+20) //0x40020C14
#define GPIOE_ODR_Addr (GPIOE_BASE+20) //0x40021014
#define GPIOF_ODR_Addr (GPIOF_BASE+20) //0x40021414
#define GPIOG_ODR_Addr (GPIOG_BASE+20) //0x40021814
#define GPIOH_ODR_Addr (GPIOH_BASE+20) //0x40021C14
#define GPIOI_ODR_Addr (GPIOI_BASE+20) //0x40022014
#define GPIOA_IDR_Addr (GPIOA_BASE+16) //0x40020010
#define GPIOB_IDR_Addr (GPIOB_BASE+16) //0x40020410
#define GPIOC_IDR_Addr (GPIOC_BASE+16) //0x40020810
#define GPIOD_IDR_Addr (GPIOD_BASE+16) //0x40020C10
#define GPIOE_IDR_Addr (GPIOE_BASE+16) //0x40021010
#define GPIOF_IDR_Addr (GPIOF_BASE+16) //0x40021410
#define GPIOG_IDR_Addr (GPIOG_BASE+16) //0x40021810
#define GPIOH_IDR_Addr (GPIOH_BASE+16) //0x40021C10
#define GPIOI_IDR_Addr (GPIOI_BASE+16) //0x40022010
//IO口操作,只对单一的IO口!
//确保n的值小于16!
#define PAout(n) BIT_ADDR(GPIOA_ODR_Addr,n) //输出
#define PAin(n) BIT_ADDR(GPIOA_IDR_Addr,n) //输入
#define PBout(n) BIT_ADDR(GPIOB_ODR_Addr,n) //输出
#define PBin(n) BIT_ADDR(GPIOB_IDR_Addr,n) //输入
#define PCout(n) BIT_ADDR(GPIOC_ODR_Addr,n) //输出
#define PCin(n) BIT_ADDR(GPIOC_IDR_Addr,n) //输入
#define PDout(n) BIT_ADDR(GPIOD_ODR_Addr,n) //输出
#define PDin(n) BIT_ADDR(GPIOD_IDR_Addr,n) //输入
#define PEout(n) BIT_ADDR(GPIOE_ODR_Addr,n) //输出
#define PEin(n) BIT_ADDR(GPIOE_IDR_Addr,n) //输入
#define PFout(n) BIT_ADDR(GPIOF_ODR_Addr,n) //输出
#define PFin(n) BIT_ADDR(GPIOF_IDR_Addr,n) //输入
#define PGout(n) BIT_ADDR(GPIOG_ODR_Addr,n) //输出
#define PGin(n) BIT_ADDR(GPIOG_IDR_Addr,n) //输入
#define PHout(n) BIT_ADDR(GPIOH_ODR_Addr,n) //输出
#define PHin(n) BIT_ADDR(GPIOH_IDR_Addr,n) //输入
#define PIout(n) BIT_ADDR(GPIOI_ODR_Addr,n) //输出
#define PIin(n) BIT_ADDR(GPIOI_IDR_Addr,n) //输入
//#define LED0 PFout(10)
#endif