主要功能描述: stm32 中通过按键按下不同时长选择不同的函数入口。这里不同函数入口用亮不同的灯来演示。 软件平台: keil_MDK422 硬件平台: stm32开发板(核心芯片stm32f103RB) 固件库版本: v2.0 - /**** main.c *****/
- /* Includes platform dependent ------------------------------------------*/
- #include "configuration.h" // Configuration of the platform
- #include "stm32f10x_lib.h"
- extern u8 gcKeyCountEnable;
- extern u16 gcKeyCnt;
- int main(void)
- {
- int i = 0;
- ConfigureInterfaces();
- GPIO_KEY_Config();
- LED_config();
- while (1)
- {
- while( IS_KeyDown( GPIO_KEY_PORT, GPIO_KEY1) == 1)
- {
- gcKeyCountEnable = 1;
- if(gcKeyCnt>8) break;
- }
- if(gcKeyCnt > 1 && gcKeyCnt < 3 )
- {
- GPIO_ResetBits(GPIO_LED_RED, GPIO_RED_PIN);
- for(i = 0; i<5000; i++)
- gcKeyCnt = 0 ;
- gcKeyCountEnable = 0;
- }
- else if(gcKeyCnt > 5 )
- {
- GPIO_ResetBits(GPIO_LED_GREEN , GPIO_GREEN_PIN);
- for(i = 0; i<5000; i++)
- gcKeyCnt = 0 ;
- gcKeyCountEnable = 0;
- }
- else if (gcKeyCnt== 0)
- {
- GPIO_SetBits(GPIO_LED_GREEN , GPIO_GREEN_PIN);
- GPIO_SetBits(GPIO_LED_RED , GPIO_RED_PIN);
- }
- }
- }
-
- /****** st32mf10x_it.c *******/
-
- void TIM2_IRQHandler(void)
- {
- if (TIM_GetITStatus(TIM2, TIM_IT_Update) != RESET)
- {
- TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
-
- if( gcKeyCountEnable==1 )
- gcKeyCnt ++;
- }
- }
|