#include "stm32f10x.h"
#include <stdio.h>
#include <String.h>
void RCC_cfg(void);
void GPIO_cfg(void);
void Delay(uint32_t nCount);
void NVIC_cfg(void);
void EXTIX_Init(void);
u8 cnt;
int main(void)
{
cnt=0;
RCC_cfg();
GPIO_cfg();
NVIC_cfg();
EXTIX_Init();
while(1){
GPIO_SetBits(GPIOF,GPIO_Pin_6);
GPIO_SetBits(GPIOF,GPIO_Pin_7);
GPIO_SetBits(GPIOF,GPIO_Pin_8);
GPIO_SetBits(GPIOF,GPIO_Pin_9);
Delay(0x2fffff);
}
}
void RCC_cfg(void)
{
RCC_APB2PeriphClockCmd ( RCC_APB2Periph_GPIOF|RCC_APB2Periph_GPIOG|RCC_APB2Periph_AFIO,ENABLE);
}
void GPIO_cfg(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOF,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(GPIOG,&GPIO_InitStructure);
}
void Delay ( uint32_t nCount)
{
for(;nCount !=0;nCount--);
}
void NVIC_cfg(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x02;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x01;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void EXTIX_Init(void)
{
EXTI_InitTypeDef EXTI_InitStructure;
EXTI_ClearITPendingBit(EXTI_Line6);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOG,GPIO_PinSource6);
EXTI_InitStructure.EXTI_Line=EXTI_Line6;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_Init(&EXTI_InitStructure);
}
void EXTI9_5_IRQHandler(void)
{
Delay(1000);
if(!(GPIOG->IDR & 0x0040))
{
switch(cnt)
{case 0:
GPIO_ResetBits(GPIOF,GPIO_Pin_6);
Delay(0x2fffff);
break;
case 1:
GPIO_ResetBits(GPIOF,GPIO_Pin_7);
Delay(0x2fffff);
break;
case 2:
GPIO_ResetBits(GPIOF,GPIO_Pin_8);
Delay(0x2fffff);
break;
case 3:
GPIO_ResetBits(GPIOF,GPIO_Pin_9);
Delay(0x2fffff);
break;
}
}
cnt++;
if(cnt==4)
cnt=0;
EXTI_ClearITPendingBit(EXTI_Line6);
}