新手上路
- 积分
- 27
- 金钱
- 27
- 注册时间
- 2023-9-4
- 在线时间
- 10 小时
|
程序烧录后,按下开关,只会闪一下,大佬们帮忙看一下问题
#include "stm8s.h"
#include "hal_key.h"
#include "hal_led.h"
#include "hal_tim4.h"
bool fPowerOn_flag = TRUE;
void hal_keyInit()
{
hal_keyConfig();
}
void hal_keyConfig()
{
/* Initialize I/O in Input Mode with Interrupt for Joystick */
GPIO_Init(GPIOD,GPIO_PIN_2, GPIO_MODE_IN_FL_IT);
/* Initialize the Interrupt sensitivity */
EXTI_SetExtIntSensitivity(EXTI_PORT_GPIOD, EXTI_SENSITIVITY_FALL_ONLY);
EXTI_SetTLISensitivity(EXTI_TLISENSITIVITY_FALL_ONLY);
enableInterrupts();
while(1)
{
if(fPowerOn_flag == TRUE)
{
GPIO_Init(GPIOC,GPIO_PIN_7,GPIO_MODE_OUT_PP_LOW_FAST);//PC7
hal_LED_U_Drive(1);
hal_LED_V_Drive(1);
hal_LED_I_Drive(1);
// GPIO_Init(GPIOC,GPIO_PIN_7,GPIO_MODE_IN_FL_NO_IT);//PC7
// halt(); //进入停机模式
}else
{
// GPIO_Init(GPIOC,GPIO_PIN_7,GPIO_MODE_OUT_PP_LOW_FAST);//PC7
// hal_LED_U_Drive(1);
// hal_LED_V_Drive(1);
// hal_LED_I_Drive(1); //上电
GPIO_Init(GPIOC,GPIO_PIN_7,GPIO_MODE_IN_FL_NO_IT);//PC7
halt(); //进入停机模式
}
}
}
INTERRUPT_HANDLER(EXTI_PORTD_IRQHandler, 6)
{
/* In order to detect unexpected events during development,
it is recommended to set a breakpoint on the following instruction.
*/
Delay(10); //延时消抖
if(!GPIO_ReadInputPin(GPIOD,GPIO_PIN_2)) //判断按钮是否按下
{
if(fPowerOn_flag) //按键按下
{
fPowerOn_flag = TRUE ;//标志至为1
}else
{
fPowerOn_flag = FALSE; //标志至为0
}
}
}
|
-
-
|