智能车制作
标题:
STM32F4演示例程之操作EXTI的练习
[打印本页]
作者:
demon
时间:
2012-5-20 23:56
标题:
STM32F4演示例程之操作EXTI的练习
[attach]24768[/attach]
/************************************
标题:操作EXTI的练习
软件平台:IAR for ARM6.21
硬件平台:stm32f4-discovery
主频:168M
author:小船
data:2012-01-17
*************************************/
#include <stm32f4xx.h>
void Led_Init (void);
void main ()
{
RCC->AHB1ENR |= 0x00000009; //使能GPIOD和GPIOA时钟
RCC->APB2ENR |= (1<<14); //使能syscfg时钟
SCB->AIRCR = 0x05AF0000 | 0x400; //中断优先级分组 抢占:响应=3:1
Led_Init();
GPIOA->MODER &= 0xFFFFFFFC; //浮空输入模式
GPIOA->PUPDR &= 0xFFFFFFFC;
EXTI->IMR |= ( 1 << 0 ); //不屏蔽外中断线0
EXTI->FTSR |= ( 1 << 0 ); //下降沿触发
SYSCFG->EXTICR[1] &= 0xFFFFFF00; //配置外中断线0到PA口
NVIC->IP[6] = 0xe0; //最低抢占优先级,最高响应优先级1110
NVIC->ISER[0] |= (1<<6); //使能中断线6,也就是外中断0
while(1)
{
};
}
void Led_Init()
{
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;
GPIOD->PUPDR &= 0x00FFFFFF; //PD12,13,14,15 无上拉无下拉
GPIOD->BSRRH = 0xf000; //reset register GPIOx_BSRRH, write only
//set register GPIOx_BSRRL, write only
SYSCFG->CMPCR = 0x00000001; //使用IO补偿单元
}
void EXTI0_IRQHandler(void)
{
uint32_t tmp;
if(EXTI->PR & 0x00000001 != 0) //检查是不是外中断0挂起
{
tmp = (~GPIOD->ODR) & 0x0000f000; //PD15 14 13 12翻转,板子上四个LED的亮灭
GPIOD->ODR &= 0xffff0fff;
GPIOD->ODR |= tmp;
EXTI->PR = (1<<0); //外中断0解除挂起
}
}
作者:
0726silence
时间:
2012-5-21 12:49
顶,正打算学32 的
欢迎光临 智能车制作 (http://dns.znczz.com/)
Powered by Discuz! X3.2