站内搜索
发作品签到
专业版

#第九届立创电赛#温湿度检测仪

工程标签

193
0
0
0

简介

温湿度检测仪以STM32G030K6T6芯片为主控芯片,辅以SN74HC595PMR芯片,主要依靠盛思锐的温湿度传感器传将测量到的温度和湿度信号转换为电信号,处理输出。

简介:温湿度检测仪以STM32G030K6T6芯片为主控芯片,辅以SN74HC595PMR芯片,主要依靠盛思锐的温湿度传感器传将测量到的温度和湿度信号转换为电信号,处理输出。
第九届立创电子设计开源大赛
复刻成本:100

开源协议

GPL 3.0

创建时间:2024-07-14 14:54:16更新时间:2024-08-04 16:04:41

描述

<p style="line-height: 1.8;">注:* 为必填项</p> <p style="line-height: 1.8;"><strong><span style="color: #0093e6;">请在报名阶段填写 &darr;</span></strong></p> <p style="line-height: 1.8;">&nbsp;</p> <h3 style="line-height: 1.8;">* 1、项目功能介绍</h3> <p style="line-height: 1.8;"><span style="color: #95a5a6; font-size: 14px;">温湿度检测仪是传感器将测量到的温度和湿度信号转换为电信号,经过电路处理(如稳压滤波、运算放大、非线性校正等),最终输出与温度和湿度成线性关系的电流信号或电压信号,或者直接通过主控芯片进行数字输出的一种电子仪器,在日常生活中广泛应用,可用于气象判断,环境检测,环保等方面。</span></p> <p style="line-height: 1.8;">&nbsp;</p> <p style="line-height: 1.8;">&nbsp;</p> <p style="line-height: 1.8;">&nbsp;</p> <h3 style="line-height: 1.8;">*2、项目属性</h3> <hr /> <p style="line-height: 1.8;"><span style="color: #95a5a6;">电子设计类项目,未参加过比赛,新手挑战。</span></p> <p style="line-height: 1.8;">&nbsp;</p> <p style="line-height: 1.8;">&nbsp;</p> <p style="line-height: 1.8;">&nbsp;</p> <h3 style="line-height: 1.8;">* 3、开源协议</h3> <hr /> <p style="line-height: 1.8;"><span style="color: #95a5a6; font-size: 14px;">本温湿度检测仪,主要用于环境温度和湿度的感应检测,以STM32G030K6T6芯片为主控芯片,盛思锐温湿度传感器为主要检测模块,SN74HC595PMR芯片为辅组芯片,数码管显示,电池供电,盛思锐传感器负责采集环境的温湿度信息,再通过电路以电信号的形式传给主控芯片,芯片通过烧录的代码而控制各个部分实现自己的功能,芯片对传入的信息进行处理运算,再通过控制595芯片,从而控制数码的IO,完成电信号到数字信息的转换,输出温度和湿度,完成功能。</span></p> <p style="line-height: 1.8;"><span style="color: #95a5a6; font-size: 14px;">本代码和硬件可供分享。</span></p> <p style="line-height: 1.8;"><span style="color: #95a5a6; font-size: 14px;">开源协议:https://opensource.org/licenses/GPL-3.0</span></p> <p style="line-height: 1.8;">&nbsp;</p> <p>&nbsp;</p> <p style="line-height: 1.8;">&nbsp;</p> <p style="line-height: 1.8;"><strong><span style="color: #0093e6;">请在竞赛阶段填写 &darr;</span></strong></p> <p style="line-height: 1.8;">&nbsp;</p> <h3 style="line-height: 1.8;">*4、硬件部分</h3> <hr /> <p style="line-height: 1.8;"><span style="color: #95a5a6; font-size: 14px;">此温湿度检测仪原理并不复杂,采用STM32G030K6T6芯片主控,SN74HC595PMR芯片辅助控制显示屏显示实时的温度和湿度,用盛思锐传感器为温湿度的感应器,将环境温度湿度转化为电信号的方式输入芯片,经过芯片里面已经烧录的代码对电信号进行处理运算,再输出给辅助的芯片,控制显示屏的IO输入高低电平,从而以数字的形式输出温度和湿度。在制作过程中要一步一步地调试代码,确保每一步都没有错,切不可一次将代码全部完成后一起输进去,否则将无法判断问题,同时,焊接不出错是成功的前提,主控芯片虚焊或焊接在一起,将会无法烧录代码,芯片无法被识别到,代码要注意写在BINGEN的后面,防止丢失,注意有些需要宏定义,最后即可完成作品。</span></p> <p style="line-height: 1.8;">&nbsp;</p> <p style="line-height: 1.8;">&nbsp;</p> <p style="line-height: 1.8;">&nbsp;</p> <h3 style="line-height: 1.8;">*5、软件部分</h3> <hr /> <p style="line-height: 1.8;">main.c</p> <p>/* USER CODE BEGIN Header */<br />/**<br />&nbsp; ******************************************************************************<br />&nbsp; * @file &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : main.c<br />&nbsp; * @brief &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: Main program body<br />&nbsp; ******************************************************************************<br />&nbsp; * @attention<br />&nbsp; *<br />&nbsp; * Copyright (c) 2024 STMicroelectronics.<br />&nbsp; * All rights reserved.<br />&nbsp; *<br />&nbsp; * This software is licensed under terms that can be found in the LICENSE file<br />&nbsp; * in the root directory of this software component.<br />&nbsp; * If no LICENSE file comes with this software, it is provided AS-IS.<br />&nbsp; *<br />&nbsp; ******************************************************************************<br />&nbsp; */<br />/* USER CODE END Header */<br />/* Includes ------------------------------------------------------------------*/<br />#include "main.h"<br />#include "adc.h"<br />#include "i2c.h"<br />#include "gpio.h"</p> <p>/* Private includes ----------------------------------------------------------*/<br />/* USER CODE BEGIN Includes */</p> <p>/* USER CODE END Includes */</p> <p>/* Private typedef -----------------------------------------------------------*/<br />/* USER CODE BEGIN PTD */</p> <p>/* USER CODE END PTD */</p> <p>/* Private define ------------------------------------------------------------*/<br />/* USER CODE BEGIN PD */</p> <p>/* USER CODE END PD */</p> <p>/* Private macro -------------------------------------------------------------*/<br />/* USER CODE BEGIN PM */</p> <p>/* USER CODE END PM */</p> <p>/* Private variables ---------------------------------------------------------*/</p> <p>/* USER CODE BEGIN PV */</p> <p>/* USER CODE END PV */</p> <p>/* Private function prototypes -----------------------------------------------*/<br />void SystemClock_Config(void);<br />/* USER CODE BEGIN PFP */</p> <p>/* USER CODE END PFP */</p> <p>/* Private user code ---------------------------------------------------------*/<br />/* USER CODE BEGIN 0 */</p> <p>/* USER CODE END 0 */</p> <p>#define SHT40_Write (0x44&lt;&lt;1) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //写入地址<br />#define SHT40_Read &nbsp;((0x44&lt;&lt;1)+1) &nbsp; &nbsp; &nbsp; //读出地址</p> <p>/**<br />&nbsp; * @brief &nbsp;The application entry point.<br />&nbsp; * @retval int<br />&nbsp; */<br />/**<br />&nbsp; * @brief &nbsp;The application entry point.<br />&nbsp; * @retval int<br />&nbsp; */<br />int main(void)<br />{<br />&nbsp; /* USER CODE BEGIN 1 */<br />&nbsp; &nbsp; uint16_t num = 0;<br />&nbsp; &nbsp; uint8_t writeData[1] = {0xFD};<br />&nbsp; &nbsp; uint8_t readData[6] = {0};<br />&nbsp; &nbsp; uint16_t Temp = 0,Humi = 0;<br />&nbsp; &nbsp; double Temperature = 0;<br />&nbsp; &nbsp; double Humidity = 0;<br />&nbsp; /* USER CODE END 1 */</p> <p>&nbsp; /* MCU Configuration--------------------------------------------------------*/</p> <p>&nbsp; /* Reset of all peripherals, Initializes the Flash interface and the Systick. */<br />&nbsp; HAL_Init();</p> <p>&nbsp; /* USER CODE BEGIN Init */</p> <p>&nbsp; /* USER CODE END Init */</p> <p>&nbsp; /* Configure the system clock */<br />&nbsp; SystemClock_Config();</p> <p>&nbsp; /* USER CODE BEGIN SysInit */<br />&nbsp; &nbsp; HAL_DeInit();<br />&nbsp; /* USER CODE END SysInit */</p> <p>&nbsp; /* Initialize all configured peripherals */<br />&nbsp; MX_GPIO_Init();<br />&nbsp; MX_I2C1_Init();<br />&nbsp; /* USER CODE BEGIN 2 */<br />&nbsp; &nbsp; //使数码管全部熄灭<br />&nbsp; HAL_Delay(100);<br />&nbsp; SN74HC595_Send_Data(SN_DIG,0x00);<br />&nbsp; SN74HC595_Send_Data(SN_LED1,0x00);<br />&nbsp; SN74HC595_Send_Data(SN_LED2,0x00);<br />&nbsp; &nbsp; HAL_Delay(100);<br />&nbsp; &nbsp; HAL_I2C_Master_Transmit(&amp;hi2c1, (uint16_t)SHT40_Write, (uint8_t *)writeData, 1, HAL_MAX_DELAY);<br />&nbsp; &nbsp; HAL_Delay(10);<br />&nbsp; &nbsp; HAL_I2C_Master_Receive(&amp;hi2c1, (uint16_t)SHT40_Read, (uint8_t *)readData, 6, HAL_MAX_DELAY);<br />&nbsp; &nbsp;&nbsp;<br />&nbsp; &nbsp; Temperature = (1.0 * 175 * (readData[0] * 256 + readData[1])) / 65535.0 - 45;<br />&nbsp; &nbsp; Humidity = (1.0 * 125 * (readData[3] * 256 + readData[4])) / 65535.0 - 6.0;<br />&nbsp; &nbsp;&nbsp;<br />&nbsp; &nbsp; Temp = (uint16_t)(Temperature * 10);<br />&nbsp; &nbsp; Humi = (uint16_t)(Humidity * 10);<br />&nbsp; /* USER CODE END 2 */</p> <p>&nbsp; /* Infinite loop */<br />&nbsp; /* USER CODE BEGIN WHILE */<br />&nbsp; while (1)<br />&nbsp; {<br />&nbsp; &nbsp; /* USER CODE END WHILE */<br />&nbsp; &nbsp; /* USER CODE BEGIN 3 */<br />&nbsp; &nbsp; &nbsp; &nbsp; num++;<br />&nbsp; &nbsp; &nbsp; &nbsp; if(num &lt; 100)<br />&nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ShowNum(1,1,Temp/100);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ShowNum(1,2,Temp/ 10 % 10);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ShowNum(1,3,Temp%10);<br />&nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; else if(num &lt; 200)<br />&nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ShowNum(2,1,Humi/100);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ShowNum(2,2,Humi/ 10 % 10);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ShowNum(2,3,Humi%10);<br />&nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; else{<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; num = 0;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ShowNum(1,1,Temp/100);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ShowNum(1,2,Temp/ 10 % 10);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ShowNum(1,3,Temp%10);<br />&nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; }<br />&nbsp; /* USER CODE END 3 */<br />}<br />/**<br />&nbsp; * @brief System Clock Configuration<br />&nbsp; * @retval None<br />&nbsp; */<br />void SystemClock_Config(void)<br />{<br />&nbsp; RCC_OscInitTypeDef RCC_OscInitStruct = {0};<br />&nbsp; RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};</p> <p>&nbsp; /** Configure the main internal regulator output voltage<br />&nbsp; */<br />&nbsp; HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1);</p> <p>&nbsp; /** Initializes the RCC Oscillators according to the specified parameters<br />&nbsp; * in the RCC_OscInitTypeDef structure.<br />&nbsp; */<br />&nbsp; RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;<br />&nbsp; RCC_OscInitStruct.HSIState = RCC_HSI_ON;<br />&nbsp; RCC_OscInitStruct.HSIDiv = RCC_HSI_DIV1;<br />&nbsp; RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;<br />&nbsp; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;<br />&nbsp; RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;<br />&nbsp; RCC_OscInitStruct.PLL.PLLM = RCC_PLLM_DIV1;<br />&nbsp; RCC_OscInitStruct.PLL.PLLN = 8;<br />&nbsp; RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;<br />&nbsp; RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2;<br />&nbsp; if (HAL_RCC_OscConfig(&amp;RCC_OscInitStruct) != HAL_OK)<br />&nbsp; {<br />&nbsp; &nbsp; Error_Handler();<br />&nbsp; }</p> <p>&nbsp; /** Initializes the CPU, AHB and APB buses clocks<br />&nbsp; */<br />&nbsp; RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; |RCC_CLOCKTYPE_PCLK1;<br />&nbsp; RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;<br />&nbsp; RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;<br />&nbsp; RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;</p> <p>&nbsp; if (HAL_RCC_ClockConfig(&amp;RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)<br />&nbsp; {<br />&nbsp; &nbsp; Error_Handler();<br />&nbsp; }<br />}</p> <p>/* USER CODE BEGIN 4 */</p> <p>/* USER CODE END 4 */</p> <p>/**<br />&nbsp; * @brief &nbsp;This function is executed in case of error occurrence.<br />&nbsp; * @retval None<br />&nbsp; */<br />void Error_Handler(void)<br />{<br />&nbsp; /* USER CODE BEGIN Error_Handler_Debug */<br />&nbsp; /* User can add his own implementation to report the HAL error return state */<br />&nbsp; __disable_irq();<br />&nbsp; while (1)<br />&nbsp; {<br />&nbsp; }<br />&nbsp; /* USER CODE END Error_Handler_Debug */<br />}</p> <p>#ifdef &nbsp;USE_FULL_ASSERT<br />/**<br />&nbsp; * @brief &nbsp;Reports the name of the source file and the source line number<br />&nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; where the assert_param error has occurred.<br />&nbsp; * @param &nbsp;file: pointer to the source file name<br />&nbsp; * @param &nbsp;line: assert_param error line source number<br />&nbsp; * @retval None<br />&nbsp; */<br />void assert_failed(uint8_t *file, uint32_t line)<br />{<br />&nbsp; /* USER CODE BEGIN 6 */<br />&nbsp; /* User can add his own implementation to report the file name and line number,<br />&nbsp; &nbsp; &nbsp;ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */<br />&nbsp; /* USER CODE END 6 */<br />}<br />#endif /* USE_FULL_ASSERT */</p> <p>&nbsp;</p> <p>gpio.c</p> <p>/* USER CODE BEGIN Header */<br />/**<br />&nbsp; ******************************************************************************<br />&nbsp; * @file &nbsp; &nbsp;gpio.c<br />&nbsp; * @brief &nbsp; This file provides code for the configuration<br />&nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;of all used GPIO pins.<br />&nbsp; ******************************************************************************<br />&nbsp; * @attention<br />&nbsp; *<br />&nbsp; * Copyright (c) 2024 STMicroelectronics.<br />&nbsp; * All rights reserved.<br />&nbsp; *<br />&nbsp; * This software is licensed under terms that can be found in the LICENSE file<br />&nbsp; * in the root directory of this software component.<br />&nbsp; * If no LICENSE file comes with this software, it is provided AS-IS.<br />&nbsp; *<br />&nbsp; ******************************************************************************<br />&nbsp; */<br />/* USER CODE END Header */</p> <p>/* Includes ------------------------------------------------------------------*/<br />#include "gpio.h"</p> <p>/* USER CODE BEGIN 0 */</p> <p>/* USER CODE END 0 */</p> <p>/*----------------------------------------------------------------------------*/<br />/* Configure GPIO &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; */<br />/*----------------------------------------------------------------------------*/<br />/* USER CODE BEGIN 1 */</p> <p>/* USER CODE END 1 */</p> <p>/** Configure pins as<br />&nbsp; &nbsp; &nbsp; &nbsp; * Analog<br />&nbsp; &nbsp; &nbsp; &nbsp; * Input<br />&nbsp; &nbsp; &nbsp; &nbsp; * Output<br />&nbsp; &nbsp; &nbsp; &nbsp; * EVENT_OUT<br />&nbsp; &nbsp; &nbsp; &nbsp; * EXTI<br />*/<br />void MX_GPIO_Init(void)<br />{</p> <p>&nbsp; GPIO_InitTypeDef GPIO_InitStruct = {0};</p> <p>&nbsp; /* GPIO Ports Clock Enable */<br />&nbsp; __HAL_RCC_GPIOB_CLK_ENABLE();<br />&nbsp; __HAL_RCC_GPIOC_CLK_ENABLE();<br />&nbsp; __HAL_RCC_GPIOA_CLK_ENABLE();</p> <p>&nbsp; /*Configure GPIO pin Output Level */<br />&nbsp; HAL_GPIO_WritePin(GPIOA, LED2_SER_Pin|LED2_RCLK_Pin|LED2_SCLK_Pin|DIG_SER_Pin<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; |DIG_RCLK_Pin|DIG_SCLK_Pin|LED1_RCLK_Pin|LED1_SCLK_Pin, GPIO_PIN_RESET);</p> <p>&nbsp; /*Configure GPIO pin Output Level */<br />&nbsp; HAL_GPIO_WritePin(GPIOB, LED1_SER_Pin|GPIO_PIN_7, GPIO_PIN_RESET);</p> <p>&nbsp; /*Configure GPIO pins : PAPin PAPin PAPin PAPin<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;PAPin PAPin PAPin PAPin */<br />&nbsp; GPIO_InitStruct.Pin = LED2_SER_Pin|LED2_RCLK_Pin|LED2_SCLK_Pin|DIG_SER_Pin<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; |DIG_RCLK_Pin|DIG_SCLK_Pin|LED1_RCLK_Pin|LED1_SCLK_Pin;<br />&nbsp; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;<br />&nbsp; GPIO_InitStruct.Pull = GPIO_NOPULL;<br />&nbsp; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;<br />&nbsp; HAL_GPIO_Init(GPIOA, &amp;GPIO_InitStruct);</p> <p>&nbsp; /*Configure GPIO pin : PtPin */<br />&nbsp; GPIO_InitStruct.Pin = LED1_SER_Pin;<br />&nbsp; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;<br />&nbsp; GPIO_InitStruct.Pull = GPIO_NOPULL;<br />&nbsp; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;<br />&nbsp; HAL_GPIO_Init(LED1_SER_GPIO_Port, &amp;GPIO_InitStruct);</p> <p>&nbsp; /*Configure GPIO pin : PB5 */<br />&nbsp; GPIO_InitStruct.Pin = GPIO_PIN_5;<br />&nbsp; GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;<br />&nbsp; GPIO_InitStruct.Pull = GPIO_PULLUP;<br />&nbsp; HAL_GPIO_Init(GPIOB, &amp;GPIO_InitStruct);</p> <p>&nbsp; /*Configure GPIO pin : PB7 */<br />&nbsp; GPIO_InitStruct.Pin = GPIO_PIN_7;<br />&nbsp; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;<br />&nbsp; GPIO_InitStruct.Pull = GPIO_NOPULL;<br />&nbsp; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;<br />&nbsp; HAL_GPIO_Init(GPIOB, &amp;GPIO_InitStruct);</p> <p>&nbsp; /* EXTI interrupt init*/<br />&nbsp; HAL_NVIC_SetPriority(EXTI4_15_IRQn, 1, 0);<br />&nbsp; HAL_NVIC_EnableIRQ(EXTI4_15_IRQn);</p> <p>}</p> <p>/* USER CODE BEGIN 2 */</p> <p>/*<br />&nbsp; &nbsp; 函数内容:打开LED<br />&nbsp; &nbsp; 函数参数:无<br />&nbsp; &nbsp; 返回值:无<br />*/<br />void Open_Led(void) &nbsp; &nbsp;<br />{<br />&nbsp; &nbsp; //输出低电平<br />&nbsp; &nbsp; HAL_GPIO_WritePin(GPIOB,GPIO_PIN_7,GPIO_PIN_RESET);<br />}<br />/*<br />&nbsp; &nbsp; 函数内容:关闭LED<br />&nbsp; &nbsp; 函数参数:无<br />&nbsp; &nbsp; 返回值:无<br />*/<br />void Close_Led(void)<br />{<br />&nbsp; &nbsp; //输出高电平<br />&nbsp; &nbsp; HAL_GPIO_WritePin(GPIOB,GPIO_PIN_7,GPIO_PIN_SET);<br />}<br />/*<br />&nbsp; &nbsp; 函数内容:翻转LED<br />&nbsp; &nbsp; 函数参数:无<br />&nbsp; &nbsp; 返回值:无<br />*/<br />void Toggle_LED(void)<br />{<br />&nbsp; &nbsp; //翻转电平<br />&nbsp; &nbsp; HAL_GPIO_TogglePin(GPIOB,GPIO_PIN_7);<br />}</p> <p>/*<br />&nbsp; &nbsp; 函数内容:扫描按键<br />&nbsp; &nbsp; 函数参数:无<br />&nbsp; &nbsp; 返回值:无<br />*/</p> <p>void Scanf_GPIO_PIN(void)<br />{<br />&nbsp; &nbsp; if(HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_5) == RESET)<br />&nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; HAL_Delay(20);<br />&nbsp; &nbsp; &nbsp; &nbsp; if(HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_5) == RESET)<br />&nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; while(HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_5) == RESET);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Toggle_LED();<br />&nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; }</p> <p>}</p> <p>/*<br />&nbsp; &nbsp; 函数内容:GPIO下降沿中断回调函数<br />&nbsp; &nbsp; 函数参数:uint16_t GPIO_Pin--位号<br />&nbsp; &nbsp; 返回值:无<br />*/</p> <p>void HAL_GPIO_EXTI_Falling_Callback(uint16_t GPIO_Pin)<br />{<br />&nbsp; if(GPIO_Pin == GPIO_PIN_5)<br />&nbsp; {<br />&nbsp; &nbsp; &nbsp; if(HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_5) == GPIO_PIN_RESET)<br />&nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Toggle_LED();<br />&nbsp; &nbsp; &nbsp; }<br />&nbsp; }<br />}</p> <p>uint16_t sgh_value[11]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,0x80};</p> <p>void SN74HC595_Send_Data(unsigned char sn_num,unsigned int sendValue)<br />{<br />&nbsp; &nbsp; uint8_t i = 0;<br />&nbsp; &nbsp; if(sn_num == SN_LED1) &nbsp; &nbsp;//第一个数码管<br />&nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; for(i = 0;i &lt; 8;i++)<br />&nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(((sendValue &lt;&lt; i)&amp;0x80)!=0) &nbsp; &nbsp;//如果数据第一位是1<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; HAL_GPIO_WritePin(LED1_SER_GPIO_Port,LED1_SER_Pin,GPIO_PIN_SET); &nbsp; &nbsp; &nbsp; &nbsp;//高电平<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; HAL_GPIO_WritePin(LED1_SER_GPIO_Port,LED1_SER_Pin,GPIO_PIN_RESET); &nbsp; &nbsp;//低电平<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; HAL_GPIO_WritePin(LED1_SCLK_GPIO_Port,LED1_SCLK_Pin,GPIO_PIN_RESET); &nbsp; &nbsp;//产生一个SCLK上升沿<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; HAL_GPIO_WritePin(LED1_SCLK_GPIO_Port,LED1_SCLK_Pin,GPIO_PIN_SET);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; HAL_GPIO_WritePin(LED1_RCLK_GPIO_Port,LED1_RCLK_Pin,GPIO_PIN_RESET); &nbsp; &nbsp;//产生一个RCLK上升沿<br />&nbsp; &nbsp; &nbsp; &nbsp; HAL_GPIO_WritePin(LED1_RCLK_GPIO_Port,LED1_RCLK_Pin,GPIO_PIN_SET);<br />&nbsp; &nbsp; }<br />&nbsp; &nbsp; else if(sn_num == SN_LED2)<br />&nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; for(i = 0;i &lt; 8;i++)<br />&nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(((sendValue &lt;&lt; i)&amp;0x80)!=0)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; HAL_GPIO_WritePin(LED2_SER_GPIO_Port,LED2_SER_Pin,GPIO_PIN_SET);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; HAL_GPIO_WritePin(LED2_SER_GPIO_Port,LED2_SER_Pin,GPIO_PIN_RESET);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; HAL_GPIO_WritePin(LED2_SCLK_GPIO_Port,LED2_SCLK_Pin,GPIO_PIN_RESET);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; HAL_GPIO_WritePin(LED2_SCLK_GPIO_Port,LED2_SCLK_Pin,GPIO_PIN_SET);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; HAL_GPIO_WritePin(LED2_RCLK_GPIO_Port,LED2_RCLK_Pin,GPIO_PIN_RESET);<br />&nbsp; &nbsp; &nbsp; &nbsp; HAL_GPIO_WritePin(LED2_RCLK_GPIO_Port,LED2_RCLK_Pin,GPIO_PIN_SET); &nbsp; &nbsp;<br />&nbsp; &nbsp; }<br />&nbsp; &nbsp; else if(sn_num == SN_DIG)<br />&nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; for(i = 0;i &lt; 8;i++)<br />&nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(((sendValue &lt;&lt; i)&amp;0x80)!=0)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; HAL_GPIO_WritePin(DIG_SER_GPIO_Port,DIG_SER_Pin,GPIO_PIN_SET);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; HAL_GPIO_WritePin(DIG_SER_GPIO_Port,DIG_SER_Pin,GPIO_PIN_RESET);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; HAL_GPIO_WritePin(DIG_SCLK_GPIO_Port,DIG_SCLK_Pin,GPIO_PIN_RESET);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; HAL_GPIO_WritePin(DIG_SCLK_GPIO_Port,DIG_SCLK_Pin,GPIO_PIN_SET);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; HAL_GPIO_WritePin(DIG_RCLK_GPIO_Port,DIG_RCLK_Pin,GPIO_PIN_RESET);<br />&nbsp; &nbsp; &nbsp; &nbsp; HAL_GPIO_WritePin(DIG_RCLK_GPIO_Port,DIG_RCLK_Pin,GPIO_PIN_SET); &nbsp; &nbsp;<br />&nbsp; &nbsp; }<br />}</p> <p>void ShowNum(uint8_t row, uint8_t column, uint8_t value)<br />{<br />&nbsp; &nbsp; if(row == 1)<br />&nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; switch(column)<br />&nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case 1: &nbsp; &nbsp;//如果是第一排第一个<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SN74HC595_Send_Data(SN_DIG,0xFE);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SN74HC595_Send_Data(SN_LED1,sgh_value[value]);//显示值对应16进制数<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case 2:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SN74HC595_Send_Data(SN_DIG,0xFD);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SN74HC595_Send_Data(SN_LED1,(sgh_value[value]|0x80));<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case 3:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SN74HC595_Send_Data(SN_DIG,0xFB);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SN74HC595_Send_Data(SN_LED1,sgh_value[value]);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; default:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;<br />&nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; SN74HC595_Send_Data(SN_LED1,0x00); &nbsp; &nbsp;//消影,防止错位<br />&nbsp; &nbsp; }<br />&nbsp; &nbsp; else<br />&nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; switch(column)<br />&nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case 1:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SN74HC595_Send_Data(SN_DIG,0xF7);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SN74HC595_Send_Data(SN_LED2,sgh_value[value]);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case 2:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SN74HC595_Send_Data(SN_DIG,0xEF);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SN74HC595_Send_Data(SN_LED2,(sgh_value[value]|0x80));<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case 3:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SN74HC595_Send_Data(SN_DIG,0xDF);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SN74HC595_Send_Data(SN_LED2,sgh_value[value]);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; default:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;<br />&nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; SN74HC595_Send_Data(SN_LED2,0x00);<br />&nbsp; &nbsp; }<br />}</p> <p>/* USER CODE END 2 */</p> <p>&nbsp;</p> <p>gpio.h</p> <p>/* USER CODE BEGIN Header */<br />/**<br />&nbsp; ******************************************************************************<br />&nbsp; * @file &nbsp; &nbsp;gpio.h<br />&nbsp; * @brief &nbsp; This file contains all the function prototypes for<br />&nbsp; * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;the gpio.c file<br />&nbsp; ******************************************************************************<br />&nbsp; * @attention<br />&nbsp; *<br />&nbsp; * Copyright (c) 2024 STMicroelectronics.<br />&nbsp; * All rights reserved.<br />&nbsp; *<br />&nbsp; * This software is licensed under terms that can be found in the LICENSE file<br />&nbsp; * in the root directory of this software component.<br />&nbsp; * If no LICENSE file comes with this software, it is provided AS-IS.<br />&nbsp; *<br />&nbsp; ******************************************************************************<br />&nbsp; */<br />/* USER CODE END Header */<br />/* Define to prevent recursive inclusion -------------------------------------*/<br />#ifndef __GPIO_H__<br />#define __GPIO_H__</p> <p>#ifdef __cplusplus<br />extern "C" {<br />#endif</p> <p>/* Includes ------------------------------------------------------------------*/<br />#include "main.h"</p> <p>/* USER CODE BEGIN Includes */</p> <p>/* USER CODE END Includes */</p> <p>/* USER CODE BEGIN Private defines */</p> <p>#define SN_LED1 0x01<br />#define SN_LED2 0x02<br />#define SN_DIG 0x03</p> <p>/* USER CODE END Private defines */</p> <p>void MX_GPIO_Init(void);</p> <p>/* USER CODE BEGIN Prototypes */</p> <p>void Open_Led(void);<br />void Close_Led(void);<br />void Toggle_LED(void);<br />void Scanf_GPIO_PIN(void);<br />void SN74HC595_Send_Data(unsigned char sn_num,unsigned int sendValue);<br />void ShowNum(uint8_t row, uint8_t column, uint8_t value);<br />void Get_TemperatureHumidity(float *Temperature,float *Humidity);<br />/* USER CODE END Prototypes */</p> <p>#ifdef __cplusplus<br />}<br />#endif<br />#endif /*__ GPIO_H__ */</p> <p>&nbsp;</p> <p>ic2.c</p> <p><br />/* USER CODE BEGIN 1 */</p> <p>void Get_TemperatureHumidity(float *Temperature,float *Humidity)<br />{<br />&nbsp; &nbsp; uint8_t writeData[1] = {0xFD};<br />&nbsp; &nbsp; uint8_t readData[6] = {0};<br />&nbsp; &nbsp; HAL_Delay(100);<br />&nbsp; &nbsp; HAL_I2C_Master_Transmit(&amp;hi2c1, (uint16_t)SHT40_Write, (uint8_t *)writeData, 1, HAL_MAX_DELAY);<br />&nbsp; &nbsp; HAL_Delay(10);<br />&nbsp; &nbsp; HAL_I2C_Master_Receive(&amp;hi2c1, (uint16_t)SHT40_Read, (uint8_t *)readData, 6, HAL_MAX_DELAY);<br />&nbsp; &nbsp; *Temperature = (1.0 * 175 * (readData[0] * 256 + readData[1])) / 65535.0 - 45;<br />&nbsp; &nbsp; *Humidity = (1.0 * 125 * (readData[3] * 256 + readData[4])) / 65535.0 - 6.0;<br />}</p> <p>/* USER CODE END 1 */</p> <p style="line-height: 1.8;"><span style="color: #95a5a6; font-size: 14px;">注:若您的项目涉及软件开发,请在附件上传对应的工程源码。这里可以详细说明您的软件流程图、功能模块框图、相关算法的解释或科普、源码结构、编译环境的搭建和配置、源码编译方法、程序烧录方法等。推荐图文并茂的形式向别人介绍您的想法。</span></p> <p style="line-height: 1.8;">&nbsp;</p> <h3 style="line-height: 1.8;">*6、BOM清单</h3> <hr /> <p style="line-height: 1.8;"><span style="color: #95a5a6; font-size: 14px;">请输入内容&hellip;</span></p> <p style="line-height: 1.8;">&nbsp;</p> <p style="line-height: 1.8;">&nbsp;</p> <p style="line-height: 1.8;">&nbsp;</p> <h3 style="line-height: 1.8;">*7、大赛LOGO验证</h3> <hr /> <p style="line-height: 1.8;"><img src="//image.lceda.cn/oshwhub/c9d23a32cae044a18c82ac0395d94f92.jpg" /></p> <p style="line-height: 1.8;">&nbsp;</p> <p>&nbsp;</p> <p style="line-height: 1.8;">&nbsp;</p> <h3 style="line-height: 1.8;">* 8、演示您的项目并录制成视频上传</h3> <hr /> <p style="line-height: 1.8;">&nbsp;</p> <p style="line-height: 1.8;">&nbsp;</p> <p style="line-height: 1.8;">&nbsp;</p> <p style="line-height: 1.8;">&nbsp;</p> <p style="line-height: 1.8;">&nbsp;</p>

设计图

未生成预览图,请在编辑器重新保存一次

BOM

暂无BOM

3D模型

序号文件名称下载次数
暂无数据

附件

序号文件名称下载次数
1
温湿度检测仪3DShell_PCB1_1.zip
0
2
7月28日22.mp4
0
克隆工程
添加到专辑
0
0
分享
侵权投诉

工程成员

知识产权声明&复刻说明

本项目为开源硬件项目,其相关的知识产权归创作者所有。创作者在本平台上传该硬件项目仅供平台用户用于学习交流及研究,不包括任何商业性使用,请勿用于商业售卖或其他盈利性的用途;如您认为本项目涉嫌侵犯了您的相关权益,请点击上方“侵权投诉”按钮,我们将按照嘉立创《侵权投诉与申诉规则》进行处理。

请在进行项目复刻时自行验证电路的可行性,并自行辨别该项目是否对您适用。您对复刻项目的任何后果负责,无论何种情况,本平台将不对您在复刻项目时,遇到的任何因开源项目电路设计问题所导致的直接、间接等损害负责。

评论

全部评论(1
按时间排序|按热度排序
粉丝0|获赞0
相关工程
暂无相关工程

底部导航