#include "
STM32f4xx.h"
void MY_NVIC_ProperityGroupConfig( uint8_t NVIC_Group )
{
uint32_t temp,temp1;
temp1 = (~NVIC_Group)&0x07;//ÖжÏÓÅÏȼ¶·Ö×éÉèÖã¨ÇÀÕ¼ÓÅÏȼ¶ºÍÏàÓ¦ÓÅÏȼ¶µÄ±ÈÀý·ÖÅ䣩
temp1 <<= 8;//µÃ°Ñ·Ö×éÉèÖÃÇé¿öÒƶ¯µ½AIRCR¼Ä´æÆ÷µÄ8-10λ
temp = SCB->AIRCR;//¶ÁÈ¡¼Ä´æÆ÷SCB->AIRCRµÄÖµ
temp &= 0x0000F8FF;//Çå¿ÕÏÈÇ°·Ö×é
temp |= 0x05FA0000;//дÈëÔ¿³×
temp |= temp1; //Ìí¼ÓÓÅÏȼ¶·Ö×éÉèÖÃÇé¿ö
SCB->AIRCR = temp; //ÉèÖ÷Ö×é
}
void MY_NVIC_Init1(uint8_t NVIC_Preemp
tiion/*ÇÀÕ¼ÓÅÏȼ¶ÊýÖµ*/, uint8_t NVIC_SubProprity/*ÏìÓ¦ÓÅÏȼ¶ÊýÖµ*/, uint8_t NVIC_Channel/*ÖжϱàºÅ£¨0¡«59£©*/,uint8_t NVIC_Group /*ÖжϷÖ×éÉèÖÃ*/)
{
uint32_t temp;
uint8_t IPADDR = NVIC_Channel/4;//ÓÉÓÚÿ¸öÖжÏÕ¼¾Ý8룬IPADDRΪѰÕÒ¾ßÌåÔÚÄĸö×Ö¶ÎÄÚ
uint8_t IPROFFSET = NVIC_Channel%4;
IPROFFSET = IPROFFSET*8+4;//ÔÚ×Ö¶ÎÖеÄÆ«ÒÆÖµ
MY_NVIC_ProperityGroupConfig( NVIC_Group );//ÉèÖÃÖжÏÓÅÏȼ¶·Ö×é
temp = NVIC_Preemptiion< temp |= NVIC_SubProprity&( 0x0f>>NVIC_Group );//ÏìÓ¦ÓÅÏȼ¶ÉèÖúó4-NVIC_Groupλ
temp &= 0x0f;
NVIC->IP[NVIC_Channel] |= temp <<4;//½«ÓÅÏȼ¶ÉèÖõ½ÏàÓ¦µÄ¼Ä´æÆ÷ÖРλÖÃΪIPADDR¸ö×ÖµÄIPROFFSETλ
if (NVIC_Channel<32) //Èç¹ûÖжÏÊýÁ¿Ð¡ÓÚ32ÉèÖõÚÒ»¸ö¼Ä´æÆ÷½øÐÐʹÄÜ
NVIC->ISER[0] |= 1< else
NVIC->ISER[1] |= 1<
}
/*ÒÔϳÌÐòÊǶÔIO¿ÚµÄÍⲿÖжϽøÐÐÉèÖÃ*/
void Ex_NVIC_Config(uint8_t GPIOx/*ÄĸöIO×é*/,uint8_t BITx/*IO×éµÄÄÄһλ*/,uint8_t TRIM/*IO×éµÄ´¥·¢·½Ê½*/)
{
uint8_t EXTADDR;
uint8_t EXTOFFSET;
EXTADDR=BITx/4;//ÇóÈ¡¶ÔÓ¦ÍⲿÖжϵÄ×Ö¶ÎλÖÃÐÅÏ¢
EXTOFFSET=(BITx%4)*4;//ÇóÈ¡¶ÔÓ¦ÍⲿÖжϵÄÆ«ÒÆÐÅÏ¢
//RCC->AHB2ENR |=0x01;//ʹÄܶÔÓ¦µÄIO¿Ú
SYSCFG->EXTICR[EXTADDR] |= GPIOx< //EXTI->IMR|=1< //EXTI->EMR|=1< if (TRIM&0x01) EXTI->FTSR|=1< if (TRIM&0x02) EXTI->RTSR|=1< }
int main()
{
RCC->AHB1ENR |= 0x00000005;//³õʼ»¯PA¿ÚʱÖÓ,PC¿ÚʱÖÓ
GPIOA->MODER |= ((0x1 << 2*5));
GPIOA->OTYPER |= ((0x0 << 5));
//GPIOA->OSPEEDR &= ~((3ul << 2*5));
GPIOA->OSPEEDR |= ((0x2 << 2*5));
GPIOA->PUPDR |= ((0x0 << 2*5));
RCC->APB2ENR |= (1<<14); //syscfgʱÖÓʹÄÜ
//MY_NVIC_ProperityGroupConfig( 2 );
MY_NVIC_Init1(1,1,13,1);
/*ÉèÖÃIO¿Ú PC13¸¡¿ÕÊäÈë*/
GPIOC->MODER&=0xFCFFFFFF;
GPIOC->PUPDR&=0xFCFFFFFF;
Ex_NVIC_Config(2,13,1);
EXTI->IMR|=1<<13;//ÖжÏÆÁ±Î¼Ä´æÆ÷£¬ÉèÖÿªÆôÏßÉϵÄÖжÏ
EXTI->EMR|=1<<13;//ʼþÆÁ±Î¼Ä´æÆ÷ʼþ¿ªÆô
while(1)
{
}
}
void EXTI15_10_IRQHandler1 ()
{
if(EXTI->PR && 0x1<<13 != 0) //ÍⲿÖжÏÊÇ·ñ¹ÒÆð
{
GPIOA->ODR^=0x20;
EXTI->PR = (0x1<<13); //ÍⲿÖжϽâ³ý¹ÒÆð
}
}
0