#include "stm32f10x.h"
#include "sys.h"
#include "delay.h"
#include "led.h"
#include "key.h"
int main (void)
{
u8 a;
RCC_Configuration();//RCC时钟类的设置
LED_Init ();//led初始化
KEY_Init ();//按键初始化
while(1)
{
if(!GPIO_ReadInputDataBit(KEYPORT,KEY1))
{
delay_ms(20); //防抖
if(!GPIO_ReadInputDataBit(KEYPORT,KEY1))
{
a++;
if(a>3)
{
a=0;
}
GPIO_Write(LEDPORT,a);
while(!GPIO_ReadInputDataBit(KEYPORT,KEY1));
}
}
}
}
This is a program that lights up the button light. When you press it once, LED1 lights up, when you press it a second time, LED2 lights up. When you press it three times, LED1 and LED2 light up at the same time. When writing a program, you must have a clear idea. The microcontroller needs to determine whether the button is pressed. At this time, a delay is needed to prevent accidental jitter. If the state is still the same after the delay, execute the following program.