智能车制作
标题:
STM32F4演示例程之GPIO初始化与设置
[打印本页]
作者:
demon
时间:
2012-5-20 23:50
标题:
STM32F4演示例程之GPIO初始化与设置
[attach]24764[/attach]
/************************************
标题:操作GPIO的练习
软件平台:IAR for ARM6.21
硬件平台:stm32f4-discovery
主频:168M
author:小船
data:2012-01-16
*************************************/
#include <stm32f4xx.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(500);
GPIOD->BSRRH = 0xf000;
GPIOD->BSRRL = 0x1000<<1;
Delay(500);
GPIOD->BSRRH = 0xf000;
GPIOD->BSRRL = 0x1000<<2;
Delay(500);
GPIOD->BSRRH = 0xf000;
GPIOD->BSRRL = 0x1000<<3;
Delay(500);
}
}
void Delay(uint32_t nTime)
{
Gb_TimingDelay = nTime;
while(Gb_TimingDelay != 0);
}
void SysTick_Handler(void)
{
if (Gb_TimingDelay != 0x00)
{
Gb_TimingDelay--;
}
}
作者:
hang
时间:
2012-5-20 23:54
CW 写的有木有有木有。。。
作者:
0726silence
时间:
2012-5-21 12:48
顶 ,正
打算学32
作者:
竹子
时间:
2012-5-21 12:50
作者:
0726silence
时间:
2012-5-21 12:51
顶,正打算学32 的
作者:
小宋--河南-
时间:
2012-6-2 18:32
有人在用KEIL 4的吗
欢迎光临 智能车制作 (http://dns.znczz.com/)
Powered by Discuz! X3.2