基于STM32风速风向检测仿真

目录

一、项目描述

二、仿真

三、程序

资料下载地址:基于STM32风速风向检测仿真​​​​​​​

一、项目描述

获取风速风向值并在OLED液晶上显示。

二、仿真

系统未上电

系统上电

 更改风速风向

三、程序

主程序

#include "main.h"
#include "stm32f1xx.h"
#include "./usart/bsp_debug_usart.h"
#include <stdlib.h>
#include "./adc/bsp_adc.h"
#include "string.h"
#include "oled.h"

uint16_t value[5];
char strvalue[10];

uint8_t Wind_Direc[10][10] = 
{
	"north    ",		//北风
	"northeast", 		//东北风
	"east     ",		//东风
	"southeast",		//东南风
	"south    ",		//南风
	"southwest",        //西南风
	"west     ",		//西风
	"northwest",		//西北风
};
int main(void)
{   
  SystemClock_Config();//配置系统时钟为72 MHz 
  DEBUG_USART_Config(); //初始化USART1 配置模式为 115200 8-N-1 
  DisPlay_Init();//配置OLED液晶屏
  ADCx_Init();//AD功能初始化
  HAL_ADCEx_Calibration_Start(&hadcx);//启用ADC校准
  HAL_ADC_Start(&hadcx );//开始采集
  delay_ms(10);//等待AD采集
  while (1)
  {
	Get_Pressure_Gas_Value();
  }
}

void Get_Pressure_Gas_Value(void)
{
	static  int idx = 0;
	 value[0] = ADC_Get_Average(0,1);
	 Current_Voltage = value[0] * 100 / 4095;//采集电位计电压
	 sprintf(strvalue,"%d   ",Current_Voltage);//整型数据转化为字符串
	 OLED_ShowString(45,2,strvalue);//显示风速
	 
	  value[1] = ADC_Get_Average(1,1);
	  if(value[1] < 511 )
	  {
		  idx = 0;
	  }
	  else if(value[1] < 1022 && value[1] >= 511)
	  {
		  idx = 1;
	  }
	  else if(value[1] < 1533 && value[1] >= 1022)
	  {
		  idx = 2;
	  }
	  else if(value[1] < 2044 && value[1] >= 1533)
	  {
		  idx = 3;
	  }
	  else if(value[1] < 2555 && value[1] >= 2044)
	  {
		  idx = 4;
	  }
	  else if(value[1] < 3066 && value[1] >= 2555)
	  {
		  idx = 5;
	  }
	  else if(value[1] < 3577 && value[1] >= 3066)
	  {
		  idx = 6;
	  }
	  else if( value[1] >= 3577)
	  {
		  idx = 7;
	  }

	  OLED_ShowString(45,4,Wind_Direc[idx]);//显示
	  printf("WindSpeed = %d\r\nWindDirect = %s\r\n"  ,Current_Voltage,Wind_Direc[idx]);
	  HAL_Delay(10);

}

/**
  * @brief  System Clock Configuration
  *         The system Clock is configured as follow : 
  *            System Clock source            = PLL (HSE)
  *            SYSCLK(Hz)                     = 72000000
  *            HCLK(Hz)                       = 72000000
  *            AHB Prescaler                  = 1
  *            APB1 Prescaler                 = 2
  *            APB2 Prescaler                 = 1
  *            HSE Frequency(Hz)              = 8000000
  *            HSE PREDIV1                    = 1
  *            PLLMUL                         = 9
  *            Flash Latency(WS)              = 2
  * @param  None
  * @retval None
  */
void SystemClock_Config(void)
{
  RCC_ClkInitTypeDef clkinitstruct = {0};
  RCC_OscInitTypeDef oscinitstruct = {0};
  
  /* Enable HSE Oscillator and activate PLL with HSE as source */
  oscinitstruct.OscillatorType  = RCC_OSCILLATORTYPE_HSE;
  oscinitstruct.HSEState        = RCC_HSE_ON;
  oscinitstruct.HSEPredivValue  = RCC_HSE_PREDIV_DIV1;
  oscinitstruct.PLL.PLLState    = RCC_PLL_ON;
  oscinitstruct.PLL.PLLSource   = RCC_PLLSOURCE_HSE;
  oscinitstruct.PLL.PLLMUL      = RCC_PLL_MUL5;
  if (HAL_RCC_OscConfig(&oscinitstruct)!= HAL_OK)
  {
    /* Initialization Error */
    while(1); 
  }

  /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 
     clocks dividers */
  clkinitstruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
  clkinitstruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  clkinitstruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  clkinitstruct.APB2CLKDivider = RCC_HCLK_DIV1;
  clkinitstruct.APB1CLKDivider = RCC_HCLK_DIV2;  
  if (HAL_RCC_ClockConfig(&clkinitstruct, FLASH_LATENCY_2)!= HAL_OK)
  {
    /* Initialization Error */
    while(1); 
  }
}

  • 1
    点赞
  • 36
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

森旺电子

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值