/*
#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--;
}
}
『本文转载自网络,版权归原作者所有,如有侵权请联系删除』