首页 > 其他 > 详细

外部中断实验

时间:2020-05-14 23:12:04      阅读:101      评论:0      收藏:0      [点我收藏+]

1.IO口外部中断向量表中只分配了7个中断向量。也就是智能使用7个中断服务函数。

2.中断服务函数列表:

EXTI0_IRQHandler

EXTI1_IRQHander

EXTI2_IRQHandler

EXTI3_IRQHandler

EXTI4_IRQHandler

EXTI9_5_IRQHandler

EXTI15_10_IRQHandler

3.外部中断的一般配置步骤:

技术分享图片

 

 技术分享图片

 

 

//ÍⲿÖжÏ0·þÎñ³ÌÐò
void exti0_irqhandler(void)
{
    delay_ms(10);    //Ïû¶¶
    if(wk_up==1)     
    {
        beep=!beep; //·äÃùÆ÷·­×ª 
    }         
     exti_clearitpendingbit(exti_line0); //Çå³ýline0ÉϵÄÖжϱê־λ 
}    
//ÍⲿÖжÏ2·þÎñ³ÌÐò
void exti2_irqhandler(void)
{
    delay_ms(10);    //Ïû¶¶
    if(key2==0)      
    {                 
   led0=!led0; 
    }         
     exti_clearitpendingbit(exti_line2);//Çå³ýline2ÉϵÄÖжϱê־λ 
}
//ÍⲿÖжÏ3·þÎñ³ÌÐò
void exti3_irqhandler(void)
{
    delay_ms(10);    //Ïû¶¶
    if(key1==0)     
    {
        led1=!led1;
    }         
     exti_clearitpendingbit(exti_line3);  //Çå³ýline3ÉϵÄÖжϱê־λ  
}
//ÍⲿÖжÏ4·þÎñ³ÌÐò
void exti4_irqhandler(void)
{
    delay_ms(10);    //Ïû¶¶
    if(key0==0)     
    {                 
        led0=!led0;    
        led1=!led1;    
    }         
     exti_clearitpendingbit(exti_line4);//Çå³ýline4ÉϵÄÖжϱê־λ  
}
       
//ÍⲿÖжϳõʼ»¯³ÌÐò
//³õʼ»¯pe2~4,pa0ΪÖжÏÊäÈë.
void extix_init(void)
{
    nvic_inittypedef   nvic_initstructure;
    exti_inittypedef   exti_initstructure;
    
    key_init(); //°´¼ü¶ÔÓ¦µÄio¿Ú³õʼ»¯
 
    rcc_apb2periphclockcmd(rcc_apb2periph_syscfg, enable);//ʹÄÜsyscfgʱÖÓ
    
 
    syscfg_extilineconfig(exti_portsourcegpioe, exti_pinsource2);//pe2 Á¬½Óµ½ÖжÏÏß2
    syscfg_extilineconfig(exti_portsourcegpioe, exti_pinsource3);//pe3 Á¬½Óµ½ÖжÏÏß3
    syscfg_extilineconfig(exti_portsourcegpioe, exti_pinsource4);//pe4 Á¬½Óµ½ÖжÏÏß4
    syscfg_extilineconfig(exti_portsourcegpioa, exti_pinsource0);//pa0 Á¬½Óµ½ÖжÏÏß0
    
  /* ÅäÖÃexti_line0 */
  exti_initstructure.exti_line = exti_line0;//line0
  exti_initstructure.exti_mode = exti_mode_interrupt;//ÖжÏʼþ
  exti_initstructure.exti_trigger = exti_trigger_rising; //ÉÏÉýÑØ´¥·¢ 
  exti_initstructure.exti_linecmd = enable;//ʹÄÜline0
  exti_init(&exti_initstructure);//ÅäÖÃ
    
    /* ÅäÖÃexti_line2,3,4 */
    exti_initstructure.exti_line = exti_line2 | exti_line3 | exti_line4;
  exti_initstructure.exti_mode = exti_mode_interrupt;//ÖжÏʼþ
  exti_initstructure.exti_trigger = exti_trigger_falling; //ϽµÑØ´¥·¢
  exti_initstructure.exti_linecmd = enable;//ÖжÏÏßʹÄÜ
  exti_init(&exti_initstructure);//ÅäÖÃ
 
    nvic_initstructure.nvic_irqchannel = exti0_irqn;//ÍⲿÖжÏ0
  nvic_initstructure.nvic_irqchannelpreemptionpriority = 0x00;//ÇÀÕ¼ÓÅÏȼ¶0
  nvic_initstructure.nvic_irqchannelsubpriority = 0x02;//×ÓÓÅÏȼ¶2
  nvic_initstructure.nvic_irqchannelcmd = enable;//ʹÄÜÍⲿÖжÏͨµÀ
  nvic_init(&nvic_initstructure);//ÅäÖÃ
    
    nvic_initstructure.nvic_irqchannel = exti2_irqn;//ÍⲿÖжÏ2
  nvic_initstructure.nvic_irqchannelpreemptionpriority = 0x03;//ÇÀÕ¼ÓÅÏȼ¶3
  nvic_initstructure.nvic_irqchannelsubpriority = 0x02;//×ÓÓÅÏȼ¶2
  nvic_initstructure.nvic_irqchannelcmd = enable;//ʹÄÜÍⲿÖжÏͨµÀ
  nvic_init(&nvic_initstructure);//ÅäÖÃ
    
    
    nvic_initstructure.nvic_irqchannel = exti3_irqn;//ÍⲿÖжÏ3
  nvic_initstructure.nvic_irqchannelpreemptionpriority = 0x02;//ÇÀÕ¼ÓÅÏȼ¶2
  nvic_initstructure.nvic_irqchannelsubpriority = 0x02;//×ÓÓÅÏȼ¶2
  nvic_initstructure.nvic_irqchannelcmd = enable;//ʹÄÜÍⲿÖжÏͨµÀ
  nvic_init(&nvic_initstructure);//ÅäÖÃ
    
    
    nvic_initstructure.nvic_irqchannel = exti4_irqn;//ÍⲿÖжÏ4
  nvic_initstructure.nvic_irqchannelpreemptionpriority = 0x01;//ÇÀÕ¼ÓÅÏȼ¶1
  nvic_initstructure.nvic_irqchannelsubpriority = 0x02;//×ÓÓÅÏȼ¶2
  nvic_initstructure.nvic_irqchannelcmd = enable;//ʹÄÜÍⲿÖжÏͨµÀ
  nvic_init(&nvic_initstructure);//ÅäÖÃ
//       
}

 

外部中断实验

原文:https://www.cnblogs.com/pquan/p/12890904.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!