为什么我用HAL库就能点亮,用库函数的时候就不可以呢?
这是LED.c的代码
#include "stm32f10x.h" // Device header
#include "LED.h"
/*初始化LED*/
void LEDConfig(void){
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);//开启CPIO外设时钟
GPIO_InitTypeDef GPIO_Initstruct;//定义句柄结构体
GPIO_Initstruct.GPIO_Pin=GPIO_Pin_13;//选择引脚
GPIO_Initstruct.GPIO_Speed=GPIO_Speed_50MHz;//配置速度为50MHz
GPIO_Initstruct.GPIO_Mode=GPIO_Mode_Out_PP;//配置引脚为推挽输出
GPIO_Init(GPIOC,&GPIO_Initstruct);//初始化GPIO
GPIO_SetBits(GPIOC,GPIO_Pin_13);//关闭LED灯
}
/*打开LED*/
void LED_ON(void){
GPIO_ResetBits(GPIOC,GPIO_Pin_13);//开启LED
}
/*关闭LED*/
void LED_OFF(void){
GPIO_SetBits(GPIOC,GPIO_Pin_13);
}
这是main.h的
#include "stm32f10x.h" // Device header
#include "LED.h"
#include "ADC.h"
#include "USART.h"
void Delay(uint32_t Count);//简单延时函数
uint16_t ADCValue = 0;
uint32_t ADCValue2[4];
int main(void){
//SystemInit();
LEDConfig();
ADCConfig();
USARTConfig();
LED_ON();
while(1){
}
}
void Delay(uint32_t Count){
for(;Count!=0;Count--);
}
1、LED_ON函数和LED_OFF函数的内容写反了,GPIO_SetBits为亮灯,GPIO_ReSetBits为灭灯。
2、检查输出IO口是否正确,即led灯对应的io口是否为PC13。
总体来说代码写得没有问题,一些细节的方面需要注意,设置IO口高低电平电亮led灯需要看具体的开发板原理图设计,即led灯的另一段是高电平还是低电平。
如果解决了,希望点个关注采纳。
hal库都会了,还有必要学标准库吗...