描述
<h2>题目要求</h2>
<p><span style="color:#999AAA">温湿度传感器</span></p>
<h2>题目分析</h2>
<p><span style="color:#999AAA">通过i2c协议读取SHT40温湿度传感器模块的数据并且显示在数码管上</span></p>
<h2>原理图设计说明</h2>
<p><span style="color:#999AAA"></span></p>
<p><img src="//image.lceda.cn/oshwhub/81ec2286d86a4f4f9543d014c042ce75.png" alt="屏幕截图 2024-07-28 232011.png"></p>
<p><span style="color:#999AAA"></span></p>
<h2>软件说明</h2>
<p><span style="color:#999AAA">提示:软件可以使用代码块来进行嵌套放置,无需全部软件部分说明,只需说明重要部分即可
<strong>代码块:</strong></span></p>
<pre><code>#include
void main()
{
int main(void)
{
/* USER CODE BEGIN 1 */
float temperature = 0;
float humidity = 0;
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
HAL_DeInit();
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_ADC1_Init();
MX_I2C1_Init();
MX_TIM14_Init();
/* USER CODE BEGIN 2 */
HAL_Delay(100);
SN74HC595_Send_Data(SN_DIG,0xFF); //关闭数码管显示
SN74HC595_Send_Data(SN_LED1,0x00);
SN74HC595_Send_Data(SN_LED2,0x00);
/* USER CODE END 2 */
HAL_SuspendTick(); //暂停滴答定时器,防止通过滴答定时器中断唤醒
HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI); /* 执行WFI指令, 进入睡眠模式 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
if(device_paramter.KeyStatus == KEY_SHAKE_STATE)
{
HAL_Delay(10);
if(HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_5) == GPIO_PIN_RESET)
{
while(HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_5) == GPIO_PIN_RESET);
SHT40_Read_RHData(&temperature,&humidity); //读取温湿度
device_paramter.Temp = temperature * 10; //放大温湿度
device_paramter.Humi = humidity * 10;
HAL_TIM_Base_Start_IT(&htim14); //开始定时器,显示两次数据
device_paramter.sleepStatus = 0; //清除休眠标志
device_paramter.KeyStatus = KEY_NO_PRESS; //清除按下标志
}
}
else if(device_paramter.sleepStatus == 1) //显示结束,进入休眠
{
HAL_SuspendTick(); //暂停滴答定时器,防止通过滴答定时器中断唤醒
HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI); /* 执行WFI指令, 进入睡眠模式 */
}
}
/* USER CODE END 3 */
}
}
</code></pre>
<h2>实物展示说明</h2>
<p></p>
评论(0)