STM32 IO 조작 (LED 점등)

작성자:CodeSnippets
언어:
C
28 조회
0 즐겨찾기
6시간 전

코드 구현

C
#include "stm32f1xx_hal.h"

int main(void) {
    HAL_Init(); // Initialize the HAL library
    SystemClock_Config(); // Configure the system clock

    __HAL_RCC_GPIOC_CLK_ENABLE(); // Enable the GPIOC clock

    GPIO_InitTypeDef GPIO_InitStruct = {0};
    GPIO_InitStruct.Pin = GPIO_PIN_13; // Select the PC13 pin
    GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; // Configure as push-pull output
    GPIO_InitStruct.Pull = GPIO_NOPULL; // No pull-up/down resistor
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; // Low-speed mode
    HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); // Initialize the GPIO

    while (1) {
        HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_13); // Toggle the state of PC13 pin
        HAL_Delay(500); // Delay for 500ms
    }
}

아래는 HAL 라이브러리를 사용하여 LED를 점등하는 단순한 STM32 프로그램 예시입니다.

#STM32#LED

스니펫 설명

  • 실제 개발 시에는 사용 중인 특정 STM32 모델에 맞춰 핀 및 클럭 설정을 조정하십시오.
  • 프로그램을 컴파일한 후 ST-Link 또는 J-Link 등의 디버깅 도구를 통해 STM32 칩에烧录(프로그래밍)합니다. 모든 것이 정상이라면 500ms 간격으로 LED가 깜빡이는 것을 확인할 수 있습니다.

댓글

로딩 중...