用stm32f407寄存器点亮流水灯的代码
时间: 2023-10-23 10:11:00 浏览: 61
以下是可以提供的代码:
```
#include "stm32f4xx.h"
void delay(uint32_t time);
int main(void)
{
// Enable clock for GPIO Port D
RCC->AHB1ENR |= RCC_AHB1ENR_GPIODEN;
// Set pin 12, 13, 14 and 15 as output pins
GPIOD->MODER |= GPIO_MODER_MODE12_0 | GPIO_MODER_MODE13_0 | GPIO_MODER_MODE14_0 | GPIO_MODER_MODE15_0;
while(1)
{
// Turn on LED 1
GPIOD->BSRR = GPIO_BSRR_BS12;
delay(500000);
// Turn on LED 2
GPIOD->BSRR = GPIO_BSRR_BS13;
delay(500000);
// Turn on LED 3
GPIOD->BSRR = GPIO_BSRR_BS14;
delay(500000);
// Turn on LED 4
GPIOD->BSRR = GPIO_BSRR_BS15;
delay(500000);
// Turn off all LEDs
GPIOD->BSRR = GPIO_BSRR_BR12 | GPIO_BSRR_BR13 | GPIO_BSRR_BR14 | GPIO_BSRR_BR15;
delay(500000);
}
}
void delay(uint32_t time)
{
while(time--)
{
__asm("NOP");
}
}
```
阅读全文