#include<stm32f10x_lib.h>
#define GPIO_B 1
#define FTRI 1
#define RTRI 2
void LED_Config(){
RCC->APB2ENR|=1<<(2+4);
GPIOE->CRL&=0x00000000;
GPIOE->CRL|=0x00000003;
GPIOE->ODR|=0x00000001;
}
void GPIO_Config(){
RCC->APB2ENR|=1<<(2+1);
GPIOB->CRL&=0x00000000;
GPIOB->CRL|=0x03800000;
GPIOB->ODR|=0x00000040;
}
void NVIC_Config(u8 GPIOx,u8 BITx,u8 TRIM){
u8 EXTIADDR=BITx/4;
u8 EXTIOFFSET=(BITx%4)*4;
RCC->APB2ENR|=0x01;
AFIO->EXTICR[EXTIADDR]&=~(0x000F<<EXTIOFFSET);
AFIO->EXTICR[EXTIADDR]|=GPIOx<<EXTIOFFSET;
EXTI->IMR|=1<<BITx;
if(TRIM&0x01)
EXTI->FTSR|=1<<BITx;
if(TRIM&0x02)
EXTI->RTSR|=1<<BITx;
}
void PriorityGroup_Config(u8 NVIC_Group){
SCB->AIRCR&=0x0000F8FF;
SCB->AIRCR|=0x05FA0000;
SCB->AIRCR|=((~NVIC_Group)&0x07)<<8;
}
void Priority_Config(u8 NVIC_PreemptionPriority,u8 NVIC_SubPriority,u8 NVIC_Channel,u8 NVIC_Group){
u32 temp;
u8 IPRADDR=NVIC_Channel/4;
u8 IPROFFSET=(NVIC_Channel%4)*8+4;
temp=NVIC_PreemptionPriority<<(4-NVIC_Group);
temp|=NVIC_SubPriority&(0x0F>>NVIC_Group);
temp&=0x0000000F;
NVIC->ISER[NVIC_Channel/32]|=1<<(NVIC_Channel%32);
NVIC->IPR[IPRADDR]|=temp<<IPROFFSET;
}
void EXTI_Config(){
NVIC_Config(GPIO_B,5,RTRI);
PriorityGroup_Config(2);
Priority_Config(2,2,EXTI9_5_IRQChannel,2);
}
void EXTI9_5_IRQHandler(){
GPIOE->ODR&=0x00000000;
EXTI->PR=1<<5;
}
int main(){
LED_Config();
GPIO_Config();
EXTI_Config();
while(1){}
}
把中断程序改成
void EXTI9_5_IRQHandler(){
static u8 b=0;
if(b){
GPIOE->ODR&=0x00000000;
b=0;
}
else{
GPIOE->ODR|=0x00000001;
b=1;
}
EXTI->PR=1<<5;
}
发现效果比较好。平时写程序一定要手工查代码,不是一写完就编译,这样效果比较好
文章评论(0条评论)
登录后参与讨论