Home > other >  Based on the stm32f103vet6 MQ2 smoke alarm design
Based on the stm32f103vet6 MQ2 smoke alarm design

Time:12-16

As title, is now the program code is as follows:
# include "stm32f10x. H"

Int a=0;


int main()
{



GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd (RCC_APB2Periph_GPIOA, ENABLE);
GPIO_InitStructure. GPIO_Pin=GPIO_Pin_5 | GPIO_Pin_6;
GPIO_InitStructure. GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_InitStructure. GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init (GPIOA, & amp; GPIO_InitStructure);

//GPIO_InitTypeDef GPIO_InitStructure;
//RCC_APB2PeriphClockCmd (RCCPeriph_GPIOA, ENABLE);

GPIO_InitStructure. GPIO_Pin=GPIO_Pin_2;
GPIO_InitStructure. GPIO_Mode=GPIO_Mode_IPU;
GPIO_Init (GPIOA, & amp; GPIO_InitStructure);

NVIC_InitTypeDef NVIC_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;

NVIC_PriorityGroupConfig (NVIC_PriorityGroup_1);
NVIC_InitStructure. NVIC_IRQChannel=EXTI2_IRQn;
NVIC_InitStructure. NVIC_IRQChannelPreemptionPriority=0;
NVIC_InitStructure. NVIC_IRQChannelSubPriority=0;
NVIC_InitStructure. NVIC_IRQChannelCmd=ENABLE;
NVIC_Init (& amp; NVIC_InitStructure);



EXTI_InitStructure. EXTI_Line=EXTI_Line2;
EXTI_InitStructure. EXTI_Mode=EXTI_Mode_Interrupt;
EXTI_InitStructure. EXTI_Trigger=EXTI_Trigger_Rising_Falling;
EXTI_InitStructure. EXTI_LineCmd=ENABLE;
EXTI_Init (& amp; EXTI_InitStructure);


GPIO_EXTILineConfig (GPIO_PortSourceGPIOA GPIO_PinSource0);

While (1)
{



}

}

Void EXTI2_IRQHandler (void)
{
If (EXTI_GetFlagStatus (EXTI_Line2))
{
A=~ a;
GPIO_WriteBit (GPIOA, GPIO_Pin_5 | GPIO_Pin_6, a);
}

EXTI_ClearFlag (EXTI_Line2);

}

Because I a small white will not join the key input to realize manual solution p (PA5 for leds pins, PA6 buzzer pin), bosses, please help me to modify the program, thanks a lot!
  • Related