在线看毛片网站电影-亚洲国产欧美日韩精品一区二区三区,国产欧美乱夫不卡无乱码,国产精品欧美久久久天天影视,精品一区二区三区视频在线观看,亚洲国产精品人成乱码天天看,日韩久久久一区,91精品国产91免费

<menu id="6qfwx"><li id="6qfwx"></li></menu>
    1. <menu id="6qfwx"><dl id="6qfwx"></dl></menu>

      <label id="6qfwx"><ol id="6qfwx"></ol></label><menu id="6qfwx"></menu><object id="6qfwx"><strike id="6qfwx"><noscript id="6qfwx"></noscript></strike></object>
        1. <center id="6qfwx"><dl id="6qfwx"></dl></center>

            新聞中心

            EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > stm32快速學(xué)習(xí)3——簡單按鍵中斷

            stm32快速學(xué)習(xí)3——簡單按鍵中斷

            作者: 時(shí)間:2016-11-17 來源:網(wǎng)絡(luò) 收藏
            2個(gè)按鍵中斷,控制2個(gè)LED

            Main文件

            本文引用地址:http://www.biyoush.com/article/201611/315442.htm

            #include"stm32f10x.h"

            voidRCC_Configuration(void);

            voidGPIO_Configuration(void);

            voidEXTI_Configuration(void);//外部中斷設(shè)置

            voidNVIC_Configuration(void);//中斷優(yōu)先級別設(shè)置

            unsignedcharled_bit1=0;

            unsignedcharled_bit2=0;

            intmain(void)

            {

            RCC_Configuration();

            GPIO_Configuration();

            EXTI_Configuration();

            NVIC_Configuration();

            GPIO_SetBits(GPIOA,GPIO_Pin_0);

            GPIO_SetBits(GPIOA,GPIO_Pin_1);

            while(1);

            }

            voidRCC_Configuration(void)

            {

            RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA |RCC_APB2Periph_AFIO ,ENABLE);

            }

            voidGPIO_Configuration(void)

            {

            GPIO_InitTypeDefGPIO_InitStructure;

            GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0|GPIO_Pin_1;

            GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;

            GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;

            GPIO_Init(GPIOA,&GPIO_InitStructure);

            GPIO_InitStructure.GPIO_Pin=GPIO_Pin_3|GPIO_Pin_8;

            GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN_FLOATING;

            GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;

            GPIO_Init(GPIOD,&GPIO_InitStructure);

            }

            voidEXTI_Configuration(void)

            {

            EXTI_InitTypeDefEXTI_InitStructure;

            GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource3);

            EXTI_InitStructure.EXTI_Line=EXTI_Line3;

            EXTI_InitStructure.EXTI_Mode=EXTI_Mode_Interrupt;

            EXTI_InitStructure.EXTI_Trigger=EXTI_Trigger_Falling;

            EXTI_InitStructure.EXTI_LineCmd=ENABLE;

            EXTI_Init(&EXTI_InitStructure);

            GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource8);

            EXTI_InitStructure.EXTI_Line=EXTI_Line8;

            EXTI_InitStructure.EXTI_Mode=EXTI_Mode_Interrupt;

            EXTI_InitStructure.EXTI_Trigger=EXTI_Trigger_Falling;

            EXTI_InitStructure.EXTI_LineCmd=ENABLE;

            EXTI_Init(&EXTI_InitStructure);

            }

            voidNVIC_Configuration(void)

            {

            /*

            查看固件庫手冊,關(guān)于中斷部分NVIC_IRQChannel

            PA3、PA8分別設(shè)置

            EXTI3_IRQChannel外部中斷線3中斷

            EXTI9_5_IRQChannel外部中斷線9-5中斷

            關(guān)于中斷線,查看STM32 Reference Manual的9.2.5外部中斷/事件線路映像

            stm32使用了4個(gè)位來保存優(yōu)先級別

            查固件庫

            Table273.先占優(yōu)先級和從優(yōu)先級值

            占先優(yōu)先級->主

            副優(yōu)先級->次

            號碼越小,等級越高

            判斷主的級別->一個(gè)高一個(gè)低->ok

            判斷主的級別->兩個(gè)都相同->判斷次的級別->一個(gè)高一個(gè)低->ok

            判斷主的級別->兩個(gè)都相同->判斷次的級別->兩個(gè)都相同->按照列表順序運(yùn)行

            */

            NVIC_InitTypeDefNVIC_InitStructure;

            NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);//占先優(yōu)先級、副優(yōu)先級的資源分配

            NVIC_InitStructure.NVIC_IRQChannel=EXTI3_IRQn;//指定中斷源

            NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1;//占先優(yōu)先級設(shè)定

            NVIC_InitStructure.NVIC_IRQChannelSubPriority=0;//副優(yōu)先級設(shè)定

            NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;

            NVIC_Init(&NVIC_InitStructure);

            NVIC_InitStructure.NVIC_IRQChannel=EXTI9_5_IRQn;

            NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0;

            NVIC_InitStructure.NVIC_IRQChannelSubPriority=0;

            NVIC_Init(&NVIC_InitStructure);

            }

            stm32f10x_it.c中加入

            externunsignedcharled_bit1,led_bit2;

            voidEXTI9_5_IRQHandler(void)

            {

            if(EXTI_GetITStatus(EXTI_Line8)!=RESET)

            {

            //添加中斷處理程序

            if(led_bit1)

            {

            GPIO_SetBits(GPIOA,GPIO_Pin_1);

            led_bit1=0;

            }

            else

            {

            GPIO_ResetBits(GPIOA,GPIO_Pin_1);

            led_bit1=1;

            }

            EXTI_ClearFlag(EXTI_Line8);

            }

            }

            voidEXTI3_IRQHandler(void)

            {

            if(EXTI_GetITStatus(EXTI_Line3)!=RESET)

            {

            if(led_bit2)

            {

            GPIO_SetBits(GPIOA,GPIO_Pin_0);

            led_bit2=0;

            }

            else

            {

            GPIO_ResetBits(GPIOA,GPIO_Pin_0);

            led_bit2=1;

            }

            EXTI_ClearFlag(EXTI_Line3);

            }

            }



            關(guān)鍵詞: stm32按鍵中

            評論


            技術(shù)專區(qū)

            關(guān)閉