【TB作品】MSP430G2553单片机,读取dht11,读取ds18b20,温度报警器

功能

读取dht11温湿度显示到oled

读取ds18b20温度显示到oled

按键修改温度上限

温度超出温度上限就蜂鸣器报警

硬件接法

oled接法 0.96 寸 7针 oled

// GND 电源地

// VCC 3.3v电源

// D0 P23(时钟)

// D1 P24(数据)

// RES 接P21

// DC 接P22

// CS 接P20

ds18b20

// GND 电源地

// VCC 3.3v电源

// DATA P1.5

DHT11

// GND 电源地

// VCC 3.3v电源

// DATA P1.4

按键1 P1.6

按键2 P1.7

有源蜂鸣器低电平触发 接P1.3

部分代码

cpp 复制代码
int main(void) {
	uchar o;
	uchar count = 0;
	uint warn_temp = 270;      //报警温度

	WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT

	if (CALBC1_8MHZ == 0xFF)				// If calibration constant erased
			{
		while (1)
			;                               // do not load, trap CPU!!
	}
	DCOCTL = 0;                          // Select lowest DCOx and MODx settings
	BCSCTL1 = CALBC1_8MHZ;                    // Set range
	DCOCTL = CALDCO_8MHZ;                     // Set DCO step + modulation */

	P1DIR |= BIT3;                     //BEEP
	P1OUT |= BIT3;                     //CLOSE

	P1DIR &= ~(BIT6 + BIT7); //KEY1 KEY2
	P1REN |= BIT6 + BIT7;
	P1OUT |= BIT6 + BIT7;

	OLED_Init();        //初始化OLED
	OLED_Clear();
	OLED_ShowString(40, 0, "SYSTEM");

	DS18b20_Init();

	//初始化显示报警温度
	memset(dis_str, 0, 15);
	count = 0;
	dis_str[count++] = warn_temp % 1000 / 100 + '0';
	dis_str[count++] = warn_temp % 100 / 10 + '0';
	dis_str[count++] = '.';
	dis_str[count++] = warn_temp % 10 + '0';
	dis_str[count++] = 'C';
	dis_str[count++] = 0;
	OLED_ShowString(0, 4, dis_str);

	while (1) {
		temp_value = get_one_temperature();

		o = start_DHT11();

		if (o) {
			memset(dis_str, 0, 15);
			count = 0;
			dis_str[count++] = temp_value % 1000 / 100 + '0';
			dis_str[count++] = temp_value % 100 / 10 + '0';
			dis_str[count++] = '.';
			dis_str[count++] = temp_value % 10 + '0';
			dis_str[count++] = 'C';
			dis_str[count++] = ' ';
			dis_str[count++] = ' ';
			dis_str[count++] = DHT11RH_Data_H % 100 / 10 + '0';
			dis_str[count++] = DHT11RH_Data_H % 10 + '0';
			dis_str[count++] = '%';
			dis_str[count++] = 'R';
			dis_str[count++] = 'H';
			dis_str[count++] = 0;
			OLED_ShowString(0, 2, dis_str);
		}

		if ((P1IN & BIT6) == 0) {
			delay_ms(3);
			if ((P1IN & BIT6) == 0) {
//				while ((P1IN & BIT6) == 0)
//					;
				warn_temp++;
				//初始化显示报警温度
				memset(dis_str, 0, 15);
				count = 0;
				dis_str[count++] = warn_temp % 1000 / 100 + '0';
				dis_str[count++] = warn_temp % 100 / 10 + '0';
				dis_str[count++] = '.';
				dis_str[count++] = warn_temp % 10 + '0';
				dis_str[count++] = 'C';
				dis_str[count++] = 0;
				OLED_ShowString(0, 4, dis_str);

			}
		}
		if ((P1IN & BIT7) == 0) {
			delay_ms(3);
			if ((P1IN & BIT7) == 0) {
//				while ((P1IN & BIT7) == 0)
//					;
				warn_temp--;
				//初始化显示报警温度
				memset(dis_str, 0, 15);
				count = 0;
				dis_str[count++] = warn_temp % 1000 / 100 + '0';
				dis_str[count++] = warn_temp % 100 / 10 + '0';
				dis_str[count++] = '.';
				dis_str[count++] = warn_temp % 10 + '0';
				dis_str[count++] = 'C';
				dis_str[count++] = 0;
				OLED_ShowString(0, 4, dis_str);

			}
		}

		if (temp_value > warn_temp) {
			P1OUT &= ~BIT3;
		} else {
			P1OUT |= BIT3;                     //CLOSE

		}

		delay_ms(10);

	}

}

全部代码

cpp 复制代码
https://docs.qq.com/sheet/DUEdqZ2lmbmR6UVdU?tab=BB08J2
相关推荐
etcix2 小时前
implement copy file content to clipboard on Windows
windows·stm32·单片机
谱写秋天2 小时前
在STM32F103上进行FreeRTOS移植和配置(STM32CubeIDE)
c语言·stm32·单片机·freertos
globbo6 小时前
【嵌入式STM32】I2C总结
单片机·嵌入式硬件
玖別ԅ(¯﹃¯ԅ)6 小时前
SysTick寄存器(嘀嗒定时器实现延时)
stm32·单片机·嵌入式硬件
Blossom.1187 小时前
把 AI 推理塞进「 8 位 MCU 」——0.5 KB RAM 跑通关键词唤醒的魔幻之旅
人工智能·笔记·单片机·嵌入式硬件·深度学习·机器学习·搜索引擎
桃源学社(接毕设)9 小时前
基于人工智能和物联网融合跌倒监控系统(LW+源码+讲解+部署)
人工智能·python·单片机·yolov8
玖別ԅ(¯﹃¯ԅ)9 小时前
PID学习笔记6-倒立摆的实现
笔记·stm32·单片机
清风66666614 小时前
基于51单片机的手机蓝牙控制8位LED灯亮灭设计
单片机·嵌入式硬件·智能手机·毕业设计·51单片机·课程设计
anghost1501 天前
基于单片机的超市储物柜设计
单片机·嵌入式硬件·超市储物柜设计
尘似鹤1 天前
旋钮键盘项目---foc讲解(开环)
单片机·嵌入式硬件