#include "main.h" int main(void){ unsigned long Delay=500; char flag=0; LED_Init(); Key_Init(); // Wait until PushButton is pressed PA0=1 while(!GPIO_ReadInputDataBit(Key_Port,Key_Pin)); while(1){ Set_Reset_LED1(Delay%1000); if(Delay==1000) flag=1; if(Delay==0 ) flag=0; if(GPIO_ReadInputDataBit(Key_Port,Key_Pin)){ if(flag==0) Delay++; if(flag==1) Delay--; } } } //-------------------------------------------------------------------- void Key_Init(void){ GPIO_InitTypeDef GPIO_InitStructure; /* GPIOA Periph clock enable */ RCC_AHB1PeriphClockCmd(KEY_GPIO_RCC, ENABLE); /* Configure PA0 in input mode */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; GPIO_Init(GPIOA, &GPIO_InitStructure); } //-------------------------------------------------------------------- void LED_Init(void){ GPIO_InitTypeDef GPIO_InitStructure; /* LED_PORT Periph clock enable */ RCC_AHB1PeriphClockCmd(LED_GPIO_RCC, ENABLE); /* Configure PD12 in output pushpull mode */ GPIO_InitStructure.GPIO_Pin = LED1; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(LED_PORT, &GPIO_InitStructure); } //-------------------------------------------------------------------- void Set_Reset_LED1(unsigned long Delay){ GPIO_SetBits(LED_PORT, LED1); usDelay(Delay); GPIO_ResetBits(LED_PORT, LED1); usDelay(1000-Delay); } //-------------------------------------------------------------------- void usDelay(unsigned long usTime){ unsigned long i,j, nCount=0x29; for(i=0;i < usTime;i++) for(j=0;j < nCount;j++); }