【STM8-SO8-DISCO】+(2) EXIT做按键点灯
目的:为了验证STM8S001的IO EXTI功能,做个实验就是按下键改变灯的状态。
1,在上个项目【STM8-SO8-DISCO】+ 基本定时器四中点灯的基础上改写
2,根据原理图和资料定义按键- #define USER_BUTTON_GPIO_PORT (GPIOC)
- #define USER_BUTTON_GPIO_PINS (GPIO_PIN_3) //这里可以设置为PC3,PC4,PC5中任何一个。
[color=rgb(51, 102, 153) !important]复制代码
3,定义一个EXIT的初始化函数:
- void Exit_Init()
- {
- GPIO_Init(USER_BUTTON_GPIO_PORT, (USER_BUTTON_GPIO_PINS),GPIO_MODE_IN_FL_IT);//GPIO初始化
- /* Initialize the Interrupt sensitivity */
- EXTI_SetExtIntSensitivity(EXTI_PORT_GPIOC, EXTI_SENSITIVITY_FALL_ONLY);//EXIT 外部中断触发设置下降沿触发
- //EXTI_SetTLISensitivity(EXTI_TLISENSITIVITY_FALL_ONLY); stm8s001 没有最高外部中断IO PD7
- enableInterrupts();
- }
[color=rgb(51, 102, 153) !important]复制代码
4,中断里找到下面函数加入LED1_Toggle();
- INTERRUPT_HANDLER(EXTI_PORTC_IRQHandler, 5)
- {
- /* In order to detect unexpected events during development,
- it is recommended to set a breakpoint on the following instruction.
- */
- LED1_Toggle();
- }
[color=rgb(51, 102, 153) !important]复制代码
5,注销到原来TIM4中断中的内容(避免效果不好)。
- INTERRUPT_HANDLER(TIM4_UPD_OVF_IRQHandler, 23)
- {
- /* In order to detect unexpected events during development,
- it is recommended to set a breakpoint on the following instruction.
- */
- // static uint16_t tims=0;
- // tims++;
- // if(tims >5000)
- // {
- // tims =0;
- // LED1_Toggle();
- // }
- }
[color=rgb(51, 102, 153) !important]复制代码
6,编译调试试验。
本文转载于【STM8-SO8-DISCO】+ (2)EXIT中断中做按键去点灯
http://www.stmcu.org.cn/module/forum/thread-619236-1-1.html
|