#include "GPIO_LED.h" unsigned char LED[2]; extern unsigned int LocalTime; int GPIO_LED_init(void) { GPIO_InitTypeDef GPIO_InitStructure; //打开相应GPIO口的时钟 LED0_RccOpen(); GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; GPIO_InitStructure.GPIO_Pin = LED0_LINE; GPIO_Init(LED0_Port,&GPIO_InitStructure); GPIO_ResetBits(LED0_Port,LED0_LINE); //打开相应GPIO口的时钟 LED1_RccOpen(); GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; GPIO_InitStructure.GPIO_Pin = LED1_LINE; GPIO_Init(LED1_Port,&GPIO_InitStructure); GPIO_ResetBits(LED1_Port,LED1_LINE); GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7; GPIO_Init(GPIOB,&GPIO_InitStructure); LED[0]=0; LED[1]=0; return 1; } void GPIO_LED_Tick(void) { static unsigned int LedTime=0; static unsigned char LedFlag=0; //=============================== if(LocalTime>LedTime) { LedTime=LocalTime+500; if(LedFlag==0) LedFlag=1; else LedFlag=0; } //=============================== switch(LED[1]) { case 1: GPIO_SetBits(LED0_Port,LED0_LINE); break; case 0: GPIO_ResetBits(LED0_Port,LED0_LINE); break; case 2: GPIO_WriteBit(LED0_Port,LED0_LINE,(BitAction)LedFlag); break; } //=============================== switch(LED[0]) { case 1: GPIO_SetBits(LED1_Port,LED1_LINE); break; case 0: GPIO_ResetBits(LED1_Port,LED1_LINE); break; case 2: GPIO_WriteBit(LED1_Port,LED1_LINE,(BitAction)LedFlag); break; } //=============================== }