Settings | Sign in | Sign up

There are currently 2 posts.

【程序】STM32L476RG通过寄存器操作GPIO口点亮LED灯

Floor 1 巨大八爪鱼 5/23/17 19:49
#include <stm32l476xx.h>

void delay(void)
{
    uint32_t i;
    for (i = 0; i < 200000; i++);
}

int main(void)
{
    RCC->AHB2ENR = RCC_AHB2ENR_GPIOAEN; // 开PA时钟
    
    GPIOA->MODER &= ~GPIO_MODER_MODE5_1; // PA5设为输出(推挽输出)
    GPIOA->BSRR = GPIO_BSRR_BS5; // PA5设为高电平
    
    while (1)
    {
        delay();
        GPIOA->ODR ^= GPIO_ODR_OD5; // 反转PA5上的电平
    }
}
Floor 2 巨大八爪鱼 5/23/17 19:50
注意,由于大部分GPIO口的默认输出模式为模拟模式(MODE=11),因此在设为输出的时候(MODE改为01)应将MODE高位清零。

Content converter:

Reply the post
Content:
User: You are currently anonymous.
Captcha:
Unclear? Try another one.
©2010-2025 Purasbar Ver3.0 [Mobile] [Desktop]
Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported license.