新聞中心

        EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 【STM32 Cotex-M3處理器系列編程】外部按鍵中斷

        【STM32 Cotex-M3處理器系列編程】外部按鍵中斷

        作者: 時(shí)間:2016-11-27 來源:網(wǎng)絡(luò) 收藏
        #include "stm32f10x.h"
        unsigned int TimingDelay;
        void Delay(unsigned int x)
        {
        TimingDelay=x;
        while(TimingDelay--);
        }
        void EXTI9_5_IRQHandler(void) //中斷處理函數(shù)
        {
        unsigned int tt;
        tt=6553500;
        if(EXTI_GetITStatus(EXTI_Line5)!=RESET)
        {
        GPIO_SetBits(GPIOC, GPIO_Pin_7);
        while(tt--);
        GPIO_ResetBits(GPIOC, GPIO_Pin_7);
        while(tt--);
        EXTI_ClearFlag(EXTI_Line5);//清除中斷標(biāo)志
        EXTI_ClearITPendingBit(EXTI_Line5);//清除EXTI線路掛起位
        }
        }
        int main(void)
        {
        //配置IO口
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE,ENABLE);//IO口使能設(shè)置
        GPIO_InitTypeDef GPIO_InitStructure; //定義結(jié)構(gòu)體
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_Init(GPIOC, &GPIO_InitStructure);
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //設(shè)置為上拉輸入
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_Init(GPIOE, &GPIO_InitStructure);
        //配置外部中斷控制器
        EXTI_InitTypeDef EXTI_InitStructure;
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);//使能時(shí)鐘
        EXTI_InitStructure.EXTI_Line = EXTI_Line5; //使用IO口5作為中斷口
        EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; //設(shè)置EXTI線路為中斷請(qǐng)求
        EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; //下降沿觸發(fā)
        EXTI_InitStructure.EXTI_LineCmd = ENABLE;
        EXTI_Init(&EXTI_InitStructure);
        GPIO_EXTILineConfig(GPIO_PortSourceGPIOE,GPIO_PinSource5);//將PE5掛接到EXTI9_5_IRQn中斷源上
        //配置中斷控制器
        NVIC_InitTypeDef NVIC_InitStructure;
        NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0); //選擇中斷組0
        NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn; //指定中斷源,0-4管腳屬于EXTI0_IRQn~EXTI4_IRQn,5-9管腳屬于EXTI9_5_IRQn,10-15管腳屬于EXTI15_10_IRQn
        //NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3;
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;//無先占優(yōu)先級(jí),從優(yōu)先級(jí)為1
        NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
        NVIC_Init(&NVIC_InitStructure);
        while(1);
        }
        //以下是報(bào)錯(cuò)函數(shù)
        #ifdef USE_FULL_ASSERT
        void assert_failed(uint8_t* file, uint32_t line)
        {
        while (1)
        {
        }
        }
        #endif


        關(guān)鍵詞: STM32Cotex-M3按鍵中

        評(píng)論


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

        關(guān)閉
        主站蜘蛛池模板: 子洲县| 萨迦县| 梁山县| 孟津县| 寿光市| 高碑店市| 东阳市| 搜索| 台安县| 江陵县| 资兴市| 宜宾县| 岑巩县| 龙州县| 宜君县| 巴青县| 百色市| 咸丰县| 新巴尔虎右旗| 桂东县| 铁岭县| 兴海县| 洱源县| 南平市| 丘北县| 政和县| 固安县| 灵宝市| 蒲城县| 安远县| 攀枝花市| 高淳县| 怀化市| 乐都县| 乡宁县| 玉环县| 南平市| 沙洋县| 来凤县| 宁明县| 旺苍县|