#include "delay.h"
#include "sys.h"
#include "usart.h"
#include "led.h"
#include "lcd1602.h"
#include "pwm_output.h"
#include "pwm_output.c"
#define KEY1 GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_10)//讀取按鍵0
#define KEY2 GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_13)//讀取按鍵1
#define KEY3 GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_2)//讀取按鍵2
#define KEY4 GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_11)//讀取按鍵3(WK_UP)
#define KEY5 GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_1)//讀取按鍵3(WK_UP)
void KEY_Init(void) //IO初始化
{
GPIO_InitTypeDef GPIO_InitStructure;
/*開啟按鍵端口(PC)時鐘*/
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);
GPIO_InitStructure.GPIO_Pin= GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_10|GPIO_Pin_11|GPIO_Pin_13;//KEY0-KEY2;
GPIO_InitStructure.GPIO_Mode= GPIO_Mode_IPU;
GPIO_Init(GPIOC,&GPIO_InitStructure);
}
/* 按鍵,彈起有效*/
void KEY_Scan(u8 mode)
{
static u8 key_up=1;//???????
if(mode)
key_up=1; //????
if((KEY1==0||KEY2==0||KEY3==0||KEY4==0||KEY5==0))
{
delay_ms(10);//???
key_up=0;
if(KEY1==0)
{
KEY1_flag=1;
if(0== KEY1_press_flag)
{
KEY1_Event_exec_flag= 0;
KEY1_press_flag= 1;
}
}
if(KEY2==0)
{
KEY2_flag=1;
if(0== KEY2_press_flag)
{
KEY2_Event_exec_flag= 0;
KEY2_press_flag= 1;
}
}
if(KEY3==0)
{
KEY3_flag=1;
if(0== KEY3_press_flag)
{
KEY3_Event_exec_flag= 0;
KEY3_press_flag= 1;
}
}
if(KEY4==0)
{
if(0== KEY4_flag)
{
KEY4_flag=1;
}
if(0== KEY4_press_flag)
{
KEY4_Event_exec_flag= 0;
KEY4_press_flag= 1;
}
}
if(KEY5==0)
KEY5_flag=1;
}
if((KEY1==1||KEY2==1||KEY3==1||KEY4==1||KEY5==1))
{
delay_ms(10);//???
key_up=0;
if(KEY1==1)
{
KEY1_flag=0;
if(KEY1_press_flag == 1)
{
KEY1_press_flag= 0;
if(0== KEY1_Event_exec_flag)
KEY1_Event_exec_flag= 1;
}
}
if(KEY2==1)
{
KEY2_flag=0;
if(KEY2_press_flag== 1)
{
KEY2_press_flag= 0;
if(0== KEY2_Event_exec_flag)
KEY2_Event_exec_flag= 1;
}
}
if(KEY3==1)
{
KEY3_flag=0;
if(KEY3_press_flag== 1)
{
KEY3_press_flag= 0;
if(0== KEY3_Event_exec_flag)
KEY3_Event_exec_flag= 1;
}
}
if(KEY4==1)
{
if(1== KEY4_flag)
{
KEY4_flag=0;
}
if(KEY4_press_flag== 1)
{
KEY4_press_flag= 0;
if(0== KEY4_Event_exec_flag)
KEY4_Event_exec_flag= 1;
}
}
if(KEY5==1)
KEY5_flag=0;
}
}
int main(void)
{
u8 str[] = "ATOM@ALIENTEK";
delay_init();
NVIC_Configuration();
uart_init(9600);
GPIO_Configuration();
LED_Init();
LCD1602_Init();
/* TIM3 PWM波輸出初始化,并使能TIM3 PWM輸出 */
TIM3_PWM_Init();
LCD1602_Show_Str(1, 0, str);
LCD1602_Show_Str(2, 1, "I love STM32");
while(1)
{
LED0 = 0;
delay_ms(200);
LED0 = 1;
delay_ms(200);
}
}
|