首页 > 其他分享 >嘉立创暑期训练营——温湿度检测仪

嘉立创暑期训练营——温湿度检测仪

时间:2024-07-18 08:58:50浏览次数:13  
标签:TIM3 CODE HAL 检测仪 温湿度 TIM 嘉立 USER GPIO

1.引言

        本次暑假参加了立创EDA的训练营,在备战电赛的同时完成了训练营的基本内容,在于锻炼自己的能力。

 2.原理图和PCB       

        闲话少续,直接上正片。

原理图 

PCB

 原理图和PCB都可以按照立创EDA的教程。

连接我就放在这了:https://www.bilibili.com/video/BV1k4421U7uh/?spm_id_from=333.999.0.0&vd_source=d3f507653efa4093bc0bacb0ea320b7a

3.焊接和试验 

         焊接没什么好说的,保持从小到大,从下到小的顺序焊接。

4.软件部分

         使用的HAL库,STM32cube进行配置。

1.IIC时序代码

        IIC.c

//SCL为高电平期间,SDA从高电平往低电平进行跳变
//延时时间根据期间不同需要进行对应的改变
void iic_start(void)
{
    IIC_SDA(1);
    IIC_SCL(1);
    iic_delay();
    IIC_SDA(0);
    iic_delay();
}
//SCL为高电平期间,SDA从低电平往高电平跳变
void iic_stop(void)
{
    IIC_SDA(0);
    IIC_SCL(1);
    iic_delay();
    IIC_SDA(1);
    iic_delay();
}
//有应答返回0,没有应答返回1
uint8_t iic_wait_ack(void)
{
    IIC_SDA(1);		//主机释放SDA总线
    iic_delay();
    IIC_SCL(1);		//拉高时钟线,等待从机返回ACK
    iic_delay();
    if(IIC_READ_SDA() == 1)	//如果数据线没有变化
    {
        iic_stop();
        return 1;
    }
    IIC_SCL(0);		//SCL低电平表示结束ACK检查
    iic_delay();
    return 0;
}
void iic_ack(void)
{
    IIC_SCL(0);		//先拉低时钟线
    iic_delay();
    IIC_SDA(0);		//数据线为低电平,表示应答
    iic_delay();
    IIC_SCL(1);		
    iic_delay();
}
void iic_nack(void)
{
    IIC_SCL(0);		//先拉低时钟线
    iic_delay();
    IIC_SDA(1);		//数据线为高电平,表示非应答
    iic_delay();
    IIC_SCL(1);		
    iic_delay();
}
void iic_send_byte(uint8_t data)
{
    uint8_t i = 0;
    for(i =0;i<8;i++)
    {
        IIC_SDA((data&0x80)>>7);
        iic_delay();
        IIC_SCL(1);
        iic_delay();
        IIC_SCL(0);
        data=data<<1;
    }
    IIC_SDA(1);
}
uint8_t iic_read_byte(uint8_t ack)
{
    uint8_t receive = 0;
    uint8_t i = 0;
    for(i=0;i<8;i++)
    {
        receive = receive<<1;
        IIC_SCL(1);
        iic_delay();
        if(IIC_READ_SDA()==1)
        {
            receive++;
        }
        IIC_SCL(0);
        iic_delay();
    }
    if(ack){
        iic_ack();
    }
    else{
        iic_nack();
    }
    return receive;
}

         IIC.h

#ifndef __I2C_H__
#define __I2C_H__

#ifdef __cplusplus
extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/
#include "main.h"

/* USER CODE BEGIN Includes */

/* USER CODE END Includes */

extern I2C_HandleTypeDef hi2c1;

/* USER CODE BEGIN Private defines */

/* USER CODE END Private defines */

void MX_I2C1_Init(void);

/* USER CODE BEGIN Prototypes */

/* USER CODE END Prototypes */

#ifdef __cplusplus
}
#endif

#endif /* __I2C_H__ */

        这个句柄在i2c.h头文件中进行了声明,后续我们直接使用即可。

I2C_HandleTypeDef hi2c1;

2.gpio配置 

        gpio.c

/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * @file    gpio.c
  * @brief   This file provides code for the configuration
  *          of all used GPIO pins.
  ******************************************************************************
  * @attention
  *
  * Copyright (c) 2024 STMicroelectronics.
  * All rights reserved.
  *
  * This software is licensed under terms that can be found in the LICENSE file
  * in the root directory of this software component.
  * If no LICENSE file comes with this software, it is provided AS-IS.
  *
  ******************************************************************************
  */
/* USER CODE END Header */

/* Includes ------------------------------------------------------------------*/
#include "gpio.h"

/* USER CODE BEGIN 0 */

/* USER CODE END 0 */

/*----------------------------------------------------------------------------*/
/* Configure GPIO                                                             */
/*----------------------------------------------------------------------------*/
/* USER CODE BEGIN 1 */
//0~9,外加一个小数点
uint16_t sgh_value[11]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,0x80};

/* USER CODE END 1 */

/** Configure pins as
        * Analog
        * Input
        * Output
        * EVENT_OUT
        * EXTI
*/
void MX_GPIO_Init(void)
{

  GPIO_InitTypeDef GPIO_InitStruct = {0};

  /* GPIO Ports Clock Enable */
  __HAL_RCC_GPIOB_CLK_ENABLE();
  __HAL_RCC_GPIOC_CLK_ENABLE();
  __HAL_RCC_GPIOA_CLK_ENABLE();

  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(GPIOA, LED2_SER_Pin|LED2_RCLK_Pin|LED2_SCLK_Pin|DIG_SER_Pin
                          |DIG_RCLK_Pin|DIG_SCLK_Pin|LED1_RCLK_Pin|LED1_SCLK_Pin, GPIO_PIN_RESET);

  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(LED1_SER_GPIO_Port, LED1_SER_Pin, GPIO_PIN_RESET);

  /*Configure GPIO pins : PAPin PAPin PAPin PAPin
                           PAPin PAPin PAPin PAPin */
  GPIO_InitStruct.Pin = LED2_SER_Pin|LED2_RCLK_Pin|LED2_SCLK_Pin|DIG_SER_Pin
                          |DIG_RCLK_Pin|DIG_SCLK_Pin|LED1_RCLK_Pin|LED1_SCLK_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

  /*Configure GPIO pin : PtPin */
  GPIO_InitStruct.Pin = LED1_SER_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  HAL_GPIO_Init(LED1_SER_GPIO_Port, &GPIO_InitStruct);

}

/* USER CODE BEGIN 2 */

void SN74HC595_Send_Data(unsigned char sn_num,unsigned int sendValue)
{
	uint8_t i = 0;
	if(sn_num == SN_LED1)	//第一个数码管
	{
		for(i = 0;i < 8;i++)
		{
			if(((sendValue << i)&0x80)!=0)	//如果数据第一位是1
			{
				HAL_GPIO_WritePin(LED1_SER_GPIO_Port,LED1_SER_Pin,GPIO_PIN_SET);		//高电平
			}
			else
			{
				HAL_GPIO_WritePin(LED1_SER_GPIO_Port,LED1_SER_Pin,GPIO_PIN_RESET);	//低电平
			}
			HAL_GPIO_WritePin(LED1_SCLK_GPIO_Port,LED1_SCLK_Pin,GPIO_PIN_RESET);	//产生一个SCLK上升沿
			HAL_GPIO_WritePin(LED1_SCLK_GPIO_Port,LED1_SCLK_Pin,GPIO_PIN_SET);
			}
		HAL_GPIO_WritePin(LED1_RCLK_GPIO_Port,LED1_RCLK_Pin,GPIO_PIN_RESET);	//产生一个RCLK上升沿
		HAL_GPIO_WritePin(LED1_RCLK_GPIO_Port,LED1_RCLK_Pin,GPIO_PIN_SET);
	}
	else if(sn_num == SN_LED2)
	{
		for(i = 0;i < 8;i++)
		{
			if(((sendValue << i)&0x80)!=0)
			{
				HAL_GPIO_WritePin(LED2_SER_GPIO_Port,LED2_SER_Pin,GPIO_PIN_SET);
			}
			else
			{
				HAL_GPIO_WritePin(LED2_SER_GPIO_Port,LED2_SER_Pin,GPIO_PIN_RESET);
			}
			HAL_GPIO_WritePin(LED2_SCLK_GPIO_Port,LED2_SCLK_Pin,GPIO_PIN_RESET);
			HAL_GPIO_WritePin(LED2_SCLK_GPIO_Port,LED2_SCLK_Pin,GPIO_PIN_SET);
		}
		HAL_GPIO_WritePin(LED2_RCLK_GPIO_Port,LED2_RCLK_Pin,GPIO_PIN_RESET);
		HAL_GPIO_WritePin(LED2_RCLK_GPIO_Port,LED2_RCLK_Pin,GPIO_PIN_SET);	
	}
	else if(sn_num == SN_DIG)
	{
		for(i = 0;i < 8;i++)
		{
			if(((sendValue << i)&0x80)!=0)
			{
				HAL_GPIO_WritePin(DIG_SER_GPIO_Port,DIG_SER_Pin,GPIO_PIN_SET);
			}
			else
			{
				HAL_GPIO_WritePin(DIG_SER_GPIO_Port,DIG_SER_Pin,GPIO_PIN_RESET);
			}
			HAL_GPIO_WritePin(DIG_SCLK_GPIO_Port,DIG_SCLK_Pin,GPIO_PIN_RESET);
			HAL_GPIO_WritePin(DIG_SCLK_GPIO_Port,DIG_SCLK_Pin,GPIO_PIN_SET);
		}
		HAL_GPIO_WritePin(DIG_RCLK_GPIO_Port,DIG_RCLK_Pin,GPIO_PIN_RESET);
		HAL_GPIO_WritePin(DIG_RCLK_GPIO_Port,DIG_RCLK_Pin,GPIO_PIN_SET);	
	}
}

void ShowNum(uint8_t row, uint8_t column, uint8_t value)
{
	if(row == 1)
	{
		switch(column)
		{
			case 1:	//如果是第一排第一个
					SN74HC595_Send_Data(SN_DIG,0xFE);
					SN74HC595_Send_Data(SN_LED1,sgh_value[value]);//显示值对应16进制数
				break;
			case 2:
					SN74HC595_Send_Data(SN_DIG,0xFD);
					SN74HC595_Send_Data(SN_LED1,(sgh_value[value]|0x80));
				break;
			case 3:
					SN74HC595_Send_Data(SN_DIG,0xFB);
					SN74HC595_Send_Data(SN_LED1,sgh_value[value]);
				break;
			default:
				break;
		}
		SN74HC595_Send_Data(SN_LED1,0x00);	//消影,防止错位
	}
	else
	{
		switch(column)
		{
			case 1:
					SN74HC595_Send_Data(SN_DIG,0xF7);
					SN74HC595_Send_Data(SN_LED2,sgh_value[value]);
				break;
			case 2:
					SN74HC595_Send_Data(SN_DIG,0xEF);
					SN74HC595_Send_Data(SN_LED2,(sgh_value[value]|0x80));
				break;
			case 3:
					SN74HC595_Send_Data(SN_DIG,0xDF);
					SN74HC595_Send_Data(SN_LED2,sgh_value[value]);
				break;
			default:
				break;
		}
		SN74HC595_Send_Data(SN_LED2,0x00);
	}
}
/* USER CODE END 2 */

        gpio.h

#ifndef __GPIO_H__
#define __GPIO_H__

#ifdef __cplusplus
extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/
#include "main.h"

/* USER CODE BEGIN Includes */

/* USER CODE END Includes */

/* USER CODE BEGIN Private defines */
#define SN_LED1 0x01
#define SN_LED2 0x02
#define SN_DIG  0x03
/* USER CODE END Private defines */

void MX_GPIO_Init(void);

/* USER CODE BEGIN Prototypes */
void SN74HC595_Send_Data(unsigned char sn_num,unsigned int sendValue);
void ShowNum(uint8_t row, uint8_t column, uint8_t value);
/* USER CODE END Prototypes */

#ifdef __cplusplus
}
#endif
#endif /*__ GPIO_H__ */

3.定时器 

定时器部分:

        tim.h

        这里是为了数码管的显示。

/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * @file    tim.c
  * @brief   This file provides code for the configuration
  *          of the TIM instances.
  ******************************************************************************
  * @attention
  *
  * Copyright (c) 2024 STMicroelectronics.
  * All rights reserved.
  *
  * This software is licensed under terms that can be found in the LICENSE file
  * in the root directory of this software component.
  * If no LICENSE file comes with this software, it is provided AS-IS.
  *
  ******************************************************************************
  */
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "tim.h"

/* USER CODE BEGIN 0 */

/* USER CODE END 0 */

TIM_HandleTypeDef htim3;

/* TIM3 init function */
void MX_TIM3_Init(void)
{

  /* USER CODE BEGIN TIM3_Init 0 */

  /* USER CODE END TIM3_Init 0 */

  TIM_ClockConfigTypeDef sClockSourceConfig = {0};
  TIM_SlaveConfigTypeDef sSlaveConfig = {0};
  TIM_MasterConfigTypeDef sMasterConfig = {0};
  TIM_OC_InitTypeDef sConfigOC = {0};

  /* USER CODE BEGIN TIM3_Init 1 */

  /* USER CODE END TIM3_Init 1 */
  htim3.Instance = TIM3;
  htim3.Init.Prescaler = 64-1;
  htim3.Init.CounterMode = TIM_COUNTERMODE_UP;
  htim3.Init.Period = 100-1;
  htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
  htim3.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;
  if (HAL_TIM_Base_Init(&htim3) != HAL_OK)
  {
    Error_Handler();
  }
  sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
  if (HAL_TIM_ConfigClockSource(&htim3, &sClockSourceConfig) != HAL_OK)
  {
    Error_Handler();
  }
  if (HAL_TIM_OC_Init(&htim3) != HAL_OK)
  {
    Error_Handler();
  }
  sSlaveConfig.SlaveMode = TIM_SLAVEMODE_RESET;
  sSlaveConfig.InputTrigger = TIM_TS_ITR0;
  if (HAL_TIM_SlaveConfigSynchro(&htim3, &sSlaveConfig) != HAL_OK)
  {
    Error_Handler();
  }
  sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
  sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
  if (HAL_TIMEx_MasterConfigSynchronization(&htim3, &sMasterConfig) != HAL_OK)
  {
    Error_Handler();
  }
  sConfigOC.OCMode = TIM_OCMODE_TIMING;
  sConfigOC.Pulse = 0;
  sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
  sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
  if (HAL_TIM_OC_ConfigChannel(&htim3, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN TIM3_Init 2 */

  /* USER CODE END TIM3_Init 2 */
  HAL_TIM_MspPostInit(&htim3);

}

void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* tim_baseHandle)
{

  if(tim_baseHandle->Instance==TIM3)
  {
  /* USER CODE BEGIN TIM3_MspInit 0 */

  /* USER CODE END TIM3_MspInit 0 */
    /* TIM3 clock enable */
    __HAL_RCC_TIM3_CLK_ENABLE();

    /* TIM3 interrupt Init */
    HAL_NVIC_SetPriority(TIM3_IRQn, 0, 0);
    HAL_NVIC_EnableIRQ(TIM3_IRQn);
  /* USER CODE BEGIN TIM3_MspInit 1 */

  /* USER CODE END TIM3_MspInit 1 */
  }
}
void HAL_TIM_MspPostInit(TIM_HandleTypeDef* timHandle)
{

  GPIO_InitTypeDef GPIO_InitStruct = {0};
  if(timHandle->Instance==TIM3)
  {
  /* USER CODE BEGIN TIM3_MspPostInit 0 */

  /* USER CODE END TIM3_MspPostInit 0 */

    __HAL_RCC_GPIOB_CLK_ENABLE();
    /**TIM3 GPIO Configuration
    PB4     ------> TIM3_CH1
    */
    GPIO_InitStruct.Pin = GPIO_PIN_4;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
    GPIO_InitStruct.Alternate = GPIO_AF1_TIM3;
    HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

  /* USER CODE BEGIN TIM3_MspPostInit 1 */

  /* USER CODE END TIM3_MspPostInit 1 */
  }

}

void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* tim_baseHandle)
{

  if(tim_baseHandle->Instance==TIM3)
  {
  /* USER CODE BEGIN TIM3_MspDeInit 0 */

  /* USER CODE END TIM3_MspDeInit 0 */
    /* Peripheral clock disable */
    __HAL_RCC_TIM3_CLK_DISABLE();

    /* TIM3 interrupt Deinit */
    HAL_NVIC_DisableIRQ(TIM3_IRQn);
  /* USER CODE BEGIN TIM3_MspDeInit 1 */

  /* USER CODE END TIM3_MspDeInit 1 */
  }
}

/* USER CODE BEGIN 1 */

/* USER CODE END 1 */

        tim.h

#ifndef __TIM_H__
#define __TIM_H__

#ifdef __cplusplus
extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/
#include "main.h"

/* USER CODE BEGIN Includes */

/* USER CODE END Includes */

extern TIM_HandleTypeDef htim3;

/* USER CODE BEGIN Private defines */

/* USER CODE END Private defines */

void MX_TIM3_Init(void);

void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim);

/* USER CODE BEGIN Prototypes */

/* USER CODE END Prototypes */

#ifdef __cplusplus
}
#endif

#endif /* __TIM_H__ */

4.主函数  

      main.h

/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * @file           : main.c
  * @brief          : Main program body
  ******************************************************************************
  * @attention
  *
  * Copyright (c) 2024 STMicroelectronics.
  * All rights reserved.
  *
  * This software is licensed under terms that can be found in the LICENSE file
  * in the root directory of this software component.
  * If no LICENSE file comes with this software, it is provided AS-IS.
  *
  ******************************************************************************
  */
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "i2c.h"
#include "tim.h"
#include "gpio.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */

/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */

/* USER CODE END PTD */

/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
#define SHT40_Write (0x44<<1)   		//写入地址
#define SHT40_Read  ((0x44<<1)+1)   //读出地址
/* USER CODE END PD */

/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */

/* USER CODE END PM */

/* Private variables ---------------------------------------------------------*/

/* USER CODE BEGIN PV */

/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
/* USER CODE BEGIN PFP */

/* USER CODE END PFP */

/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */

/* USER CODE END 0 */
  	uint16_t num = 0;
	uint8_t writeData[1] = {0xFD};
	uint8_t readData[6] = {0};
	uint16_t Temp = 0,Humi = 0;
	double Temperature = 0;
	double Humidity = 0;

void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim){
	if(htim == &htim3){
		num++;
		if(num < 100)
		{

    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */

			ShowNum(1,1,Temp/100);
			ShowNum(1,2,Temp/ 10 % 10);
			ShowNum(1,3,Temp%10);
	
		}
		else if(num < 200)
		{
			ShowNum(2,1,Humi/100);
			ShowNum(2,2,Humi/ 10 % 10);
			ShowNum(2,3,Humi%10);
		}
		else{
			num = 0;
			ShowNum(1,1,Temp/100);
			ShowNum(1,2,Temp/ 10 % 10);
			ShowNum(1,3,Temp%10);
		}

	}
}

/**
  * @brief  The application entry point.
  * @retval int
  */
  
int main(void)
{
  /* USER CODE BEGIN 1 */
//	uint16_t num = 0;
//	uint8_t writeData[1] = {0xFD};
//	uint8_t readData[6] = {0};
//	uint16_t Temp = 0,Humi = 0;
//	double Temperature = 0;
//	double 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_I2C1_Init();
  MX_TIM3_Init();
  HAL_TIM_Base_Start_IT(&htim3);
  /* USER CODE BEGIN 2 */
	HAL_TIM_PeriodElapsedCallback(&htim3);
	//使数码管全部熄灭
  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
	  SN74HC595_Send_Data(SN_DIG,0x00);
	  SN74HC595_Send_Data(SN_LED1,0x00);
      SN74HC595_Send_Data(SN_LED2,0x00);
	HAL_Delay(100);
	HAL_I2C_Master_Transmit(&hi2c1, (uint16_t)SHT40_Write, (uint8_t *)writeData, 1, HAL_MAX_DELAY);
		HAL_Delay(10);
	HAL_I2C_Master_Receive(&hi2c1, (uint16_t)SHT40_Read, (uint8_t *)readData, 6, HAL_MAX_DELAY);
	
	Temperature = (1.0 * 175 * (readData[0] * 256 + readData[1])) / 65535.0 - 45;
	Humidity = (1.0 * 125 * (readData[3] * 256 + readData[4])) / 65535.0 - 6.0;
	
	Temp = (uint16_t)(Temperature * 10);
	Humi = (uint16_t)(Humidity * 10);
    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */

//		if(num < 100)
//		{
//			ShowNum(1,1,Temp/100);
//			ShowNum(1,2,Temp/ 10 % 10);
//			ShowNum(1,3,Temp%10);
//	
//		}
//		else if(num < 200)
//		{
//			ShowNum(2,1,Humi/100);
//			ShowNum(2,2,Humi/ 10 % 10);
//			ShowNum(2,3,Humi%10);
//		}
//		else{
//			num = 0;
//			ShowNum(1,1,Temp/100);
//			ShowNum(1,2,Temp/ 10 % 10);
//			ShowNum(1,3,Temp%10);
//		}

  }
  /* USER CODE END 3 */
}

/**
  * @brief System Clock Configuration
  * @retval None
  */
void SystemClock_Config(void)
{
  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

  /** Configure the main internal regulator output voltage
  */
  HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1);

  /** Initializes the RCC Oscillators according to the specified parameters
  * in the RCC_OscInitTypeDef structure.
  */
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  RCC_OscInitStruct.HSIDiv = RCC_HSI_DIV1;
  RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
  RCC_OscInitStruct.PLL.PLLM = RCC_PLLM_DIV1;
  RCC_OscInitStruct.PLL.PLLN = 8;
  RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
  RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2;
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  {
    Error_Handler();
  }

  /** Initializes the CPU, AHB and APB buses clocks
  */
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
                              |RCC_CLOCKTYPE_PCLK1;
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;

  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
  {
    Error_Handler();
  }
}

/* USER CODE BEGIN 4 */

/* USER CODE END 4 */

/**
  * @brief  This function is executed in case of error occurrence.
  * @retval None
  */
void Error_Handler(void)
{
  /* USER CODE BEGIN Error_Handler_Debug */
  /* User can add his own implementation to report the HAL error return state */
  __disable_irq();
  while (1)
  {
  }
  /* USER CODE END Error_Handler_Debug */
}

#ifdef  USE_FULL_ASSERT
/**
  * @brief  Reports the name of the source file and the source line number
  *         where the assert_param error has occurred.
  * @param  file: pointer to the source file name
  * @param  line: assert_param error line source number
  * @retval None
  */
void assert_failed(uint8_t *file, uint32_t line)
{
  /* USER CODE BEGIN 6 */
  /* User can add his own implementation to report the file name and line number,
     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  /* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */

5.实物验证

6.程序文件 

链接:https://pan.baidu.com/s/1ykD0cl5duxzqGEhDIVcoSg?pwd=1234 
提取码:1234

7.总结

        跟随立创EDA的教程,完成了本次训练营的任务,也学习了stm32cube的使用,对于陌生的芯片确实能够加快学习的速度。

望诸君前途似锦

标签:TIM3,CODE,HAL,检测仪,温湿度,TIM,嘉立,USER,GPIO
From: https://blog.csdn.net/m0_74245657/article/details/140500764

相关文章

  • 零基础STM32单片机编程入门(十五) DHT11温湿度传感器模块实战含源码
    文章目录一.概要二.DHT11主要性能参数三.DHT11温度传感器内部框图四.DTH11模块原理图五.DHT11模块跟单片机板子接线和通讯时序1.单片机跟DHT11模块连接示意图2.单片机跟DHT11模块通讯流程与时序六.STM32单片机DHT11温度传感器实验七.CubeMX工程源代码下载八.小结一.......
  • 温湿度传感器
    前言&常见型号类型:DS18B20、DHT11DHT11概述相关文档:DHT11数据手册.pdfDHT11数字温湿度传感器是一款含有已校准数字信号输出的温湿度复合传感器。它应用专用的数字模块采集技术和温湿度传感技术,确保产品具有极高的可靠性与卓越的长期稳定性。传感器包括一个电阻式感湿元件......
  • 温湿度传感器的学习及基于串口和逻辑分析仪的验证
    目录温湿度传感器温湿度传感器的基本概述测量精度硬件接线时序分析接收数据分析代码全局变量配置DHT11为输出模式配置DHT11为输入模式配置初始化DHT11发送开始信号判断DHT11温湿度传感器是否应答接收一位数据接收一个字节的数据接收DHT11传输的数据串口USART1的初始化利用串口发送......
  • STM32驱动-DHT11(温湿度模块)
    STM32驱动-DHT11(温湿度模块)一、DHT11模块简介DHT11是一款含有已校准数字信号输出的温湿度复合传感器,它应用专用的数字模块采集技术和温湿度传感技术,确保产品具有极高的可靠性和卓越的长期稳定性。传感器包括一个电阻式感湿元件和一个NTC测温元件,并与一个高性能8位单片机相连接......
  • DH11温湿度检测模块
    目录DHT11温湿度传感器检测模块是否存在:使用LED检测DHT11模块是否接在设备上:读取温湿度数据:DHT11温湿度传感器 DHT11数字温湿度传感器是一款含有已校准数字信号输出的温湿度复合传感器,应用领域:暖通空调;汽车;消费品;气象站;湿度调节器;除湿器;家电;医疗;自动控制特点......
  • DH11温湿度检测模块、lcd1602、HC-08蓝牙构成温湿度数据管理系统
    目录温湿度通过串口上传PC: 温湿度数据管理系统:温湿度通过串口上传PC:sendByte(datas[0]/10+0x30);sendByte(datas[0]%10+0x30);这两行代码用于将一个字节(是DHT11传感器读取的湿度或温度的整数部分)转换为两个ASCII字符,并通过UART串口发送出去。+0x30:在ASCII......
  • 通过ESP32读取I2C温湿度传感器项目:协议与代码实例
    简介在本项目中,我们将使用ESP32开发板读取I2C温湿度传感器的数据。我们将详细介绍I2C协议,并提供图文并茂的代码实例,帮助你快速上手。项目流程选择硬件:ESP32开发板、I2C温湿度传感器(如DHT12、HTU21D、SHT30等)、连接线和面包板。了解I2C协议:I2C(Inter-IntegratedCircuit)是......
  • Arduino实现温湿度传感器以及数据上传到云(乐维互联)
    0准备材料0.1ESP-01S引脚及定义官方定义:序号pin功能1GND地线2IO0/GPIO0工作模式选择:①悬空:FlashBoot,工作模式②下拉:UARTDownLoad下载模式3IO2/GPIO2通用IO4RX/RXD数据接收端5TX/TXD谁发送端63V3/VCC3.3V,模块供电7RST1)外......
  • 基于51单片机的窗帘控制系统【温湿度,烟雾,红外,光照】(仿真)
    基于51单片机的窗帘控制系统【温湿度,烟雾,红外,光照】(仿真)给大家提供一些资料详细解释,有需要的自行提取,网盘地址我放在下面 链接:https://pan.baidu.com/s/1NigBeujDZTCFL0hdMiu7yg?pwd=syxp 提取码:syxp 分别利用温湿度传感器、烟雾传感器、光敏电阻、红外检测控制模块等......
  • 基于STM32的简易智能家居设计(嘉立创支持)
    一、项目功能概述1、OLED显示温湿度、空气质量,并可以设置报警阈值2、设置4个继电器开关,分别控制灯、空调、开关、风扇3、设计一个离线语音识别系统,可以语音控制打开指定开关、并且可以显示识别命令词到OLED屏上4、OLED实时显示4个继电器的状态5、设计一个低功耗开关电路,......