我是一个在项目中使用 STM32F4 发现板的初学者,我想知道我是否正确地解决了这个问题。不会测试我的毫秒延迟功能,但没有白费..
#include "stm32f4x.h"
#define LED_BLUE_GPIO GPIOC
#define LED_BLUE_PIN 8
void Delay_ms(uint16_t ms){
TIM3->ARR = ms; //timer 3
TIM3->CNT = 0;
while((TIM3->SR & TIM_SR_UIF)==0){}
TIM3->SR &= ~TIM_SR_UIF;
}
int main(void)
{
RCC->APB2ENR |= RCC_APB2ENR_IOPAEN | RCC_APB2ENR_IOPCEN;
RCC->APB1ENR |= RCC_APB1ENR_TIM3EN;
//initialization
TIM3->PSC = 23999; // f timer = fclk / 24000 => 1kHz
TIM3->ARR = 0xFFFF;
TIM3->CR1 = TIM_CR1_CEN;
DBGMCU->CR = DBGMCU_CR_DBG_TIM3_STOP;
while(1){
GPIOC->ODR = GPIO_ODR_ODR8;
Delay_ms(1000); //delay 1 sec
GPIOC->ODR = GPIO_ODR_ODR8;
Delay_ms(1000); //delay 1 sec
}
}