赞
踩
- void pir_init(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF, ENABLE);
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
- GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
- GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
- GPIO_Init(GPIOF, &GPIO_InitStructure);
- }
- void pir_run()
- {
- if(PFin(13) == 1)
- {
- printf("有人靠近\n");
- }
- else
- {
- printf("周边没人\n");
- }
- }
- NVIC_InitStruct.NVIC_IRQChannel = 中断通道;
- NVIC_InitStruct.NVIC_IRQChannelCmd = 开始工作;
- NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority =抢占优先
- 级;
- NVIC_InitStruct.NVIC_IRQChannelSubPriority =相应优先级
- void pir_interrupt_init()
- {
- //exti13与F13连接
- SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOF,EXTI_PinSource13
- );
- //配置EXTI
- EXTI_InitTypeDef EXTI_InitStruct;
- EXTI_InitStruct.EXTI_Line = EXTI_Line13;
- EXTI_InitStruct.EXTI_LineCmd = ENABLE;
- EXTI_InitStruct.EXTI_Mode = EXTI_Mode_Interrupt;
- EXTI_InitStruct.EXTI_Trigger = EXTI_Trigger_Rising_Falling;
- EXTI_Init(&EXTI_InitStruct);
- //分组模式
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
- NVIC_InitTypeDef NVIC_InitStruct;
- NVIC_InitStruct.NVIC_IRQChannel = EXTI15_10_IRQn;
- NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;
- NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority =2;
- NVIC_InitStruct.NVIC_IRQChannelSubPriority =2;
- NVIC_Init(&NVIC_InitStruct);
- }
- static uint32_t i = 0;
- void EXTI15_10_IRQHandler()
- {
- if(EXTI_GetITStatus(EXTI_Line13) != RESET)//确认中断事件
- {
- i++;
- if(i%2 == 0)
- {
- printf("有人靠近\n");
- }
- else
- {
- printf("有人离开\n");
- }
- EXTI_ClearITPendingBit(EXTI_Line13);//清除挂起中断标志位
- }
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。