本人新手,板子是f0discovery,带
芯片F051,目前挑战闪烁灯,但是不知道何故,灯一直亮,完全不闪,源程序如下:
#include "
STM32f0xx.h"
#include "stm32f0xx_rcc.h"
#include "stm32f0xx_flash.h"
#include "stm32f0xx_cec.h"
#include "stm32f0xx_gpio.h"
#include <stdio.h>
void RCC_Config(void)
{
RCC_DeInit();
RCC_HSICmd(ENABLE);
while (RCC_GetFlagStatus(RCC_FLAG_HSIRDY) != SET) /* check out, if HSI ready */
{
}
FLASH_PrefetchBufferCmd(ENABLE); /* Enable Flash */
FLASH_SetLatency(FLASH_Latency_1); /* Flash wait two State */
RCC_HCLKConfig(RCC_SYSCLK_Div1);
RCC_PCLKConfig(RCC_HCLK_Div2);
RCC_PLLConfig(RCC_PLLSource_HSI_Div2, RCC_PLLMul_16); /* PLLCLK = HSI/2 * 16 = 64 MHz */
RCC_PLLCmd(ENABLE);
while (RCC_GetFlagStatus(RCC_FLAG_PLLRDY) != SET) /* check out, if PLL ready */
{
}
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); /* SYSCLK = PLLCLK = 64 MHz -> APB1 = 32 MHz, APB2 = 64 MHz */
while (RCC_GetSYSCLKSource() != 0x08) /* check out, if SYSCLK uses PLLCLK */
{
}
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC, ENABLE);
}
void GPIO_Config(void)
{
GPIO_InitTypeDef GPIO_InitS;
GPIO_InitS.GPIO_Pin = GPIO_Pin_9;
GPIO_InitS.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitS.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitS.GPIO_OType = GPIO_OType_PP;
GPIO_Init(GPIOC,&GPIO_InitS);
}
int main(void)
{
int i = 0;
while(1)
{
RCC_Config();
GPIO_Config();
while (1)
{
GPIO_SetBits(GPIOC, GPIO_Pin_9);
GPIO_ResetBits(GPIOC, GPIO_Pin_9);
}
}
}
开头我以为频率太快可能不行,所以把开关灯的setbits和resetbits加上循环,变成:
for(i=1;i<30;i++)
{GPIO_SetBits(GPIOC, GPIO_Pin_9);}
for(i=1;i<30;i++)
{GPIO_ResetBits(GPIOC, GPIO_Pin_9);}
让其有延时,灯还是不闪,各位知道是什么原因吗?谢谢
能不能关闭灯
一周热门 更多>