STM32F407的GPIO操作

 

/*
#include "stm32f4_discovery.h"
#include "stm32f4xx_conf.h"
 


uint32_t Gb_TimingDelay;
void Delay(uint32_t nTime);

void main( )
{
    SysTick_Config(SystemCoreClock / 1000); //设置systemtick 一毫秒中断
    RCC->AHB1ENR |= 0x00000008; //使能GPIOD 时钟
    RCC->APB2ENR |= (1<<14); //使能syscfg 时钟
    GPIOD->MODER &= 0x00FFFFFF; //设置PD12,13,14,15 输出
    GPIOD->MODER |= 0x55000000;
    GPIOD->OTYPER &= 0xFFFF0FFF; //设置PD12,13,14,15 推挽输出
    GPIOD->OSPEEDR &= 0x00FFFFFF; //PD12,13,14,15 速度100m
    GPIOD->OSPEEDR |= 0xff000000;
    SYSCFG->CMPCR = 0x00000001; //使用IO 补偿单元,
    //当GPIO 速度超过50M 的时候要考虑使用此设置
    GPIOD->PUPDR &= 0x00FFFFFF; //PD12,13,14,15 无上拉无下拉
    GPIOD->BSRRH = 0xf000; //reset register GPIOx_BSRRH, write only
    //set register GPIOx_BSRRL, write only
   
    while(1)
    {
        GPIOD->BSRRH = 0xf000;
        GPIOD->BSRRL = 0x1000;
        Delay(100);
        GPIOD->BSRRH = 0xf000;
        GPIOD->BSRRL = 0x1000<<1;
        Delay(100);
        GPIOD->BSRRH = 0xf000;
        GPIOD->BSRRL = 0x1000<<2;
        Delay(100);
        GPIOD->BSRRH = 0xf000;
        GPIOD->BSRRL = 0x1000<<3;
        Delay(100);
    }
}

void Delay(uint32_t nTime)
{
    Gb_TimingDelay = nTime;
    while(Gb_TimingDelay != 0);
}
void SysTick_Handler(void)
{
    if (Gb_TimingDelay != 0x00)
    {
        Gb_TimingDelay--;
    }
}
*/

#include "stm32f4_discovery.h"
#include "stm32f4xx_conf.h"
 
uint32_t Gb_TimingDelay;
void Delay(uint32_t nTime);

void main( )
{
    SysTick_Config(SystemCoreClock / 1000); //设置systemtick 一毫秒中断
   
    /*
    //Initialize LEDs mounted on STM32F4-Discovery board
    STM_EVAL_LEDInit(LED4);
    STM_EVAL_LEDInit(LED3);
    STM_EVAL_LEDInit(LED5);
    STM_EVAL_LEDInit(LED6);
     
    //Turn on LED4 and LED5
    STM_EVAL_LEDOn(LED4);
    STM_EVAL_LEDOn(LED5);
   
    while(1)
    {
        //Toggle LED3 and LED6
        STM_EVAL_LEDToggle(LED3);
        STM_EVAL_LEDToggle(LED6);

        //Insert a delay
        Delay(100);

        //Toggle LED4 and LED5
        STM_EVAL_LEDToggle(LED4);
        STM_EVAL_LEDToggle(LED5);

        //Insert a delay
        Delay(100);    
    }
    */
   
    //-------------------------------------
    GPIO_InitTypeDef  GPIO_InitStructure;
 
    //Enable the GPIO_LED Clock
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);

    //Configure the GPIO_LED pin
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(GPIOD, &GPIO_InitStructure);
    //点亮这个灯
    GPIOD->BSRRL = GPIO_Pin_12;
   
    while(1)
    {
        // 
        GPIOD->ODR ^= GPIO_Pin_12;
        //Insert a delay
        Delay(100);    
    }
   
}

void Delay(uint32_t nTime)
{
    Gb_TimingDelay = nTime;
    while(Gb_TimingDelay != 0);
}
void SysTick_Handler(void)
{
    if (Gb_TimingDelay != 0x00)
    {
        Gb_TimingDelay--;
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值