初级会员
- 积分
- 94
- 金钱
- 94
- 注册时间
- 2019-7-20
- 在线时间
- 26 小时
|
发表于 2019-7-20 10:33:21
|
显示全部楼层
- #include "stm32f10x.h"
- #include "led.h"
- #include "key.h"
- #include "delay.h"
- void EXIT_init()
- {
- GPIO_InitTypeDef GPIO_InitSY;
- EXTI_InitTypeDef EXTI_InitSY;
- NVIC_InitTypeDef NVIC_InitSY;
-
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOE,ENABLE);
- RCC_APB1PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);
-
- GPIO_InitSY.GPIO_Mode=GPIO_Mode_IPU;
- GPIO_InitSY.GPIO_Pin=GPIO_Pin_3|GPIO_Pin_4;
- GPIO_InitSY.GPIO_Speed=GPIO_Speed_50MHz;
- GPIO_Init(GPIOE,&GPIO_InitSY);
-
-
- GPIO_InitSY.GPIO_Mode=GPIO_Mode_IPD;
- GPIO_InitSY.GPIO_Pin=GPIO_Pin_0;
- GPIO_Init(GPIOA,&GPIO_InitSY);
-
- GPIO_EXTILineConfig(GPIO_PortSourceGPIOE,GPIO_PinSource3);
- EXTI_InitSY.EXTI_Line=EXTI_Line3;
- EXTI_InitSY.EXTI_LineCmd=ENABLE;
- EXTI_InitSY.EXTI_Mode=EXTI_Mode_Interrupt;
- EXTI_InitSY.EXTI_Trigger=EXTI_Trigger_Falling;
-
- EXTI_Init(&EXTI_InitSY);
-
- GPIO_EXTILineConfig(GPIO_PortSourceGPIOE,GPIO_PinSource4);
- EXTI_InitSY.EXTI_Line=EXTI_Line4;
- EXTI_Init(&EXTI_InitSY);
-
- GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource0);
- EXTI_InitSY.EXTI_Line=EXTI_Line0;
- EXTI_InitSY.EXTI_Trigger=EXTI_Trigger_Rising;
- EXTI_Init(&EXTI_InitSY);
-
- NVIC_InitSY.NVIC_IRQChannel=EXTI0_IRQn;
- NVIC_InitSY.NVIC_IRQChannelCmd=ENABLE;
- NVIC_InitSY.NVIC_IRQChannelPreemptionPriority=2;
- NVIC_InitSY.NVIC_IRQChannelSubPriority=1;
- NVIC_Init(&NVIC_InitSY);
-
- NVIC_InitSY.NVIC_IRQChannel=EXTI3_IRQn;
- NVIC_InitSY.NVIC_IRQChannelCmd=ENABLE;
- NVIC_InitSY.NVIC_IRQChannelPreemptionPriority=1;
- NVIC_InitSY.NVIC_IRQChannelSubPriority=2;
- NVIC_Init(&NVIC_InitSY);
-
- NVIC_InitSY.NVIC_IRQChannel=EXTI4_IRQn;
- NVIC_InitSY.NVIC_IRQChannelCmd=ENABLE;
- NVIC_InitSY.NVIC_IRQChannelPreemptionPriority=3;
- NVIC_InitSY.NVIC_IRQChannelSubPriority=1;
- NVIC_Init(&NVIC_InitSY);
- }
- void EXTI0_IRQHandler()
- {
- delay_ms(10);
- if(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_0)==1)
- {
- PBout(5)=~PBout(5);
- }
- EXTI_ClearITPendingBit(EXTI_Line0);
- }
- void EXTI3_IRQHandler()
- {
- delay_ms(10);
- if(GPIO_ReadInputDataBit(GPIOE,GPIO_Pin_3)==0)
- {
- PEout(5)=~PEout(5);
- }
- EXTI_ClearITPendingBit(EXTI_Line3);
- }
- void EXTI4_IRQHandler()
- {
- delay_ms(10);
- if(GPIO_ReadInputDataBit(GPIOE,GPIO_Pin_4)==0)
- {
- PEout(5)=~PEout(5);
- PBout(5)=~PBout(5);
- }
- EXTI_ClearITPendingBit(EXTI_Line4);
- }
-
- int main(void)
- {
-
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
- delay_init();
- led_init();
- EXIT_init();
-
- while(1);
-
-
- }
- 你可能配错了哪里,前后对调了,都可,我的精英板
复制代码 |
|