之前的代码中按键似乎有点不灵敏,这是修改后的代码,按键可以准确地调节LED闪烁的时间:
int main(void)
{
volatile uint16_t wait = 100;
SYSTEM_Initialize();
USART0_Enable();
printf("Hello World\r\n");
SW0_SetDigitalInput();
SW0_SetPullUp();
Led0_SetHigh();
while(1)
{
if(0==SW0_GetValue()){
DELAY_milliseconds(50);
if(0==SW0_GetValue()){
wait <<= 1;
if(wait>1600)
wait = 100;
}
}
printf("wait=%d\r\n",wait);
Led0_Toggle();
DELAY_milliseconds(wait);
}
}
|