蓝桥杯嵌入式(STM32G431RBT6)扩展板——光敏电阻

1.原理图

原理图

2.CUbemx配置

配置

3.代码

(1)dadc.c

#include "dadc.h"
double getADC(ADC_HandleTypeDef *pin)
{
   
    unsigned int value;
    //开启ADC
    HAL_ADC_Start(pin);
    
    //获取ADC的值
    value=HAL_ADC_GetValue(pin);
    
    //12位精度即4096
    //4096就代表3.3V
    return value*(3.3/4096);
}


(2)dadc.h

#ifndef __DADC_H__
#define __DADC_H__

#include "main.h"
double getADC(ADC_HandleTypeDef *pin);



#endif

(3)main.c

/* 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 "adc.h"
#include "gpio.h"

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


#include "lcd.h"
#include "led.h"
#include "dadc.h"
#<
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值