如何把下面的例程改成按一下用户按钮LED3的灯就亮,然后再按一下LED3灯就熄灭,是一直亮着不闪烁
/* Includes ------------------------------------------------------------------*/
#include "main.h"
static __IO uint32_t TimingDelay;
uint8_t BlinkSpeed = 0;
int main(void)
{
RCC_ClocksTypeDef RCC_Clocks;
/* Configure LED3 and LED4 on STM32F0-Discovery */
STM_EVAL_LEDInit(LED3);
STM_EVAL_LEDInit(LED4);
/* Initialize User_Button on STM32F0-Discovery */
STM_EVAL_PBInit(BUTTON_USER, BUTTON_MODE_GPIO);
/* SysTick end of count event each 1ms */
RCC_GetClocksFreq(&RCC_Clocks);
SysTick_Config(RCC_Clocks.HCLK_Frequency / 1000);
/* Initiate Blink Speed variable */
BlinkSpeed = 1;
while(1)
{
/* Check if the user button is pressed */
if(STM_EVAL_PBGetState(BUTTON_USER)== SET)
{
/* BlinkSpeed: 1 -> 2 -> 0, then re-cycle */
/* Turn on LD4 Blue LED during 1s each time User button is pressed */
STM_EVAL_LEDOn(LED4);
/* wait for 1s */
Delay(1000);
STM_EVAL_LEDOff(LED4);
BlinkSpeed++;
if(BlinkSpeed == 3)
{
BlinkSpeed = 0;
}
}
/* Test on blink speed */
if(BlinkSpeed == 2)
{
/* LED3 toggles each 100 ms */
STM_EVAL_LEDToggle(LED3);
/* maintain LED3 status for 100ms */
Delay(100);
}
else if(BlinkSpeed == 1)
{
/* LED3 toggles each 200 ms */
STM_EVAL_LEDToggle(LED3);
/* maintain LED3 status for 200ms */
Delay(200);
}
else
{
/* LED3 Off */
STM_EVAL_LEDOff(LED3);
}
}
}
void Delay(__IO uint32_t nTime)
{
TimingDelay = nTime;
while(TimingDelay != 0);
}
void TimingDelay_Decrement(void)
{
if (TimingDelay != 0x00)
{
TimingDelay--;
}
}
#ifdef USE_FULL_ASSERT
void assert_failed(uint8_t* file, uint32_t line)
{
while (1)
{}
}
#endif
/* Includes ------------------------------------------------------------------*/
#include "main.h"
static __IO uint32_t TimingDelay;
uint8_t BlinkSpeed = 0;
int main(void)
{
RCC_ClocksTypeDef RCC_Clocks;
/* Configure LED3 and LED4 on STM32F0-Discovery */
STM_EVAL_LEDInit(LED3);
STM_EVAL_LEDInit(LED4);
/* Initialize User_Button on STM32F0-Discovery */
STM_EVAL_PBInit(BUTTON_USER, BUTTON_MODE_GPIO);
/* SysTick end of count event each 1ms */
RCC_GetClocksFreq(&RCC_Clocks);
SysTick_Config(RCC_Clocks.HCLK_Frequency / 1000);
/* Initiate Blink Speed variable */
BlinkSpeed = 1;
while(1)
{
/* Check if the user button is pressed */
if(STM_EVAL_PBGetState(BUTTON_USER)== SET)
{
/* BlinkSpeed: 1 -> 2 -> 0, then re-cycle */
/* Turn on LD4 Blue LED during 1s each time User button is pressed */
STM_EVAL_LEDOn(LED4);
/* wait for 1s */
Delay(1000);
STM_EVAL_LEDOff(LED4);
BlinkSpeed++;
if(BlinkSpeed == 3)
{
BlinkSpeed = 0;
}
}
/* Test on blink speed */
if(BlinkSpeed == 2)
{
/* LED3 toggles each 100 ms */
STM_EVAL_LEDToggle(LED3);
/* maintain LED3 status for 100ms */
Delay(100);
}
else if(BlinkSpeed == 1)
{
/* LED3 toggles each 200 ms */
STM_EVAL_LEDToggle(LED3);
/* maintain LED3 status for 200ms */
Delay(200);
}
else
{
/* LED3 Off */
STM_EVAL_LEDOff(LED3);
}
}
}
void Delay(__IO uint32_t nTime)
{
TimingDelay = nTime;
while(TimingDelay != 0);
}
void TimingDelay_Decrement(void)
{
if (TimingDelay != 0x00)
{
TimingDelay--;
}
}
#ifdef USE_FULL_ASSERT
void assert_failed(uint8_t* file, uint32_t line)
{
while (1)
{}
}
#endif