帮我写一段stm32点亮小灯的c'语言代码
时间: 2023-05-11 21:04:01 浏览: 105
Sure, here's a sample code for lighting up a LED on an STM32 microcontroller using C language:
```
#include "stm32f4xx.h"
int main(void)
{
// Enable the clock for GPIOA peripheral
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
// Configure PA5 as output
GPIO_InitTypeDef GPIO_InitStruct;
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_5;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOA, &GPIO_InitStruct);
// Turn on the LED
GPIO_SetBits(GPIOA, GPIO_Pin_5);
while(1)
{
// Do nothing
}
}
```
This code initializes the GPIOA peripheral and configures pin PA5 as an output. It then turns on the LED connected to that pin and enters an infinite loop.
阅读全文