历史上的今天
今天是:2025年03月03日(星期一)
2020年03月03日 | stvd+stm8l051F3(2): 外部中断
2020-03-03 来源:eefocus
stvd+stm8l051F3(一): 外部中断
stvd: ST Visual Develop Version 4.3.9
ic:stm8l051F3
1、原理图
按键接在stm8l051F3的PB1脚,LED接在stm8l051F3的PD0脚
2、建立stvd key项目
打开stvd新建stm8l051_key项目,并将stm8l15x.h,stm8l15x_it.h,stm8l15x_it.c,stm8l15x_conf.h,stm8l15x_exti.c,stm8l15x_gpio.c文件加入项目;
stm8l15x_gpio.c:io相关源文件;
stm8l15x_exti.c:中断相关源文件;
3、修改代码
main.c:
/* MAIN.C file
*
* Copyright (c) 2002-2005 STMicroelectronics
*/
#include "stm8l15x.h"
//定义LED、按键端口
#define LED_PORT GPIOD
#define LED_PINS GPIO_Pin_0
#define KEY_PORT GPIOB
#define KEY_PINS GPIO_Pin_1
/*******************************************************************************
****入口参数:无
****出口参数:无
****函数备注:不精确延时函数
*******************************************************************************/
void Delay(__IO uint16_t nCount)
{
/* Decrement nCount value */
while (nCount != 0)
{
nCount--;
}
}
/*******************************************************************************
****函数说明:主函数
****入口参数:无
****出口参数:无
****函数备注:按键按下后在外部中断1中将LED亮灭变换
********************************************************************************/
void main(void)
{
GPIO_Init(LED_PORT,LED_PINS,GPIO_Mode_Out_PP_Low_Slow);//初始化LED端口
GPIO_Init(KEY_PORT, KEY_PINS, GPIO_Mode_In_PU_IT);//初始化按键,上拉输入,带中断
EXTI_DeInit (); //恢复中断的所有设置
EXTI_SetPinSensitivity (EXTI_Pin_1,EXTI_Trigger_Falling);//外部中断1,下降沿触发,向量号9
enableInterrupts();//使能中断
while (1)//等待中断
{
}
}
stm8l15x.h:
打开芯片型号宏定义
/* Uncomment the line below according to the target STM8L15x device used in your
application
*/
/* #define STM8L15X_LD */ /*!< STM8L15X_LD: STM8L15x Low density devices */
/* #define STM8L15X_MD */ /*!< STM8L15X_MD: STM8L15x Medium density devices */
/* #define STM8L15X_MDP */ /*!< STM8L15X_MDP: STM8L15x Medium density plus devices */
/* #define STM8L15X_HD */ /*!< STM8L15X_HD: STM8L15x/16x High density devices */
#define STM8L05X_LD_VL */ /*!< STM8L05X_LD_VL: STM8L051xx3 Low density value line devices */
/* #define STM8L05X_MD_VL */ /*!< STM8L05X_MD_VL: STM8L052xx6 Medium density value line devices */
/* #define STM8L05X_HD_VL */ /*!< STM8L05X_HD_VL: STM8L052xx8 High density value line devices */
/* #define STM8AL31_L_MD */ /*!< STM8AL31_L_MD: STM8AL3x Medium density devices */
stm8l15x_conf.h:
关闭USE_FULL_ASSERT宏
/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/* Uncomment the line below to expanse the "assert_param" macro in the
Standard Peripheral Library drivers code */
/* #define USE_FULL_ASSERT (1) */
/* Exported macro ------------------------------------------------------------*/
stm8l15x_it.c:
修改中断向量9响应函数INTERRUPT_HANDLER(EXTI1_IRQHandler,9),在该函数中添加自定义中断处理函数
INTERRUPT_HANDLER(EXTI1_IRQHandler,9)
{
/* In order to detect unexpected events during development,
it is recommended to set a breakpoint on the following instruction.
*/
EXTI_ClearITPendingBit (EXTI_IT_Pin1);//清除中断标志
GPIO_ToggleBits(GPIOD, GPIO_Pin_0);//翻转LED端口电平
}
stm8_interrupt_vector.c:
注释@far @interrupt void NonHandledInterrupt (void)函数,添加#include "stm8l15x_it.h",解决重定义拨错问题,
将_vectab中irq9的中断处理函数由NonHandledInterrupt修改为EXTI1_IRQHandler
/* BASIC INTERRUPT VECTOR TABLE FOR STM8 devices
* Copyright (c) 2007 STMicroelectronics
*/
/* 添加stm8l15x_it.h头文件 */
#include "stm8l15x_it.h"
typedef void @far (*interrupt_handler_t)(void);
struct interrupt_vector {
unsigned char interrupt_instruction;
interrupt_handler_t interrupt_handler;
};
/* 注释掉NonHandledInterrupt */
#if 0
@far @interrupt void NonHandledInterrupt (void)
{
/* in order to detect unexpected events during development,
it is recommended to set a breakpoint on the following instruction
*/
return;
}
#endif
extern void _stext(); /* startup routine */
struct interrupt_vector const _vectab[] = {
{0x82, (interrupt_handler_t)_stext}, /* reset */
{0x82, NonHandledInterrupt}, /* trap */
{0x82, NonHandledInterrupt}, /* irq0 */
{0x82, NonHandledInterrupt}, /* irq1 */
{0x82, NonHandledInterrupt}, /* irq2 */
{0x82, NonHandledInterrupt}, /* irq3 */
{0x82, NonHandledInterrupt}, /* irq4 */
{0x82, NonHandledInterrupt}, /* irq5 */
{0x82, NonHandledInterrupt}, /* irq6 */
{0x82, NonHandledInterrupt}, /* irq7 */
{0x82, NonHandledInterrupt}, /* irq8 */
{0x82, EXTI1_IRQHandler}, /* irq9 */
{0x82, NonHandledInterrupt}, /* irq10 */
{0x82, NonHandledInterrupt}, /* irq11 */
{0x82, NonHandledInterrupt}, /* irq12 */
{0x82, NonHandledInterrupt}, /* irq13 */
{0x82, NonHandledInterrupt}, /* irq14 */
{0x82, NonHandledInterrupt}, /* irq15 */
{0x82, NonHandledInterrupt}, /* irq16 */
{0x82, NonHandledInterrupt}, /* irq17 */
{0x82, NonHandledInterrupt}, /* irq18 */
{0x82, NonHandledInterrupt}, /* irq19 */
{0x82, NonHandledInterrupt}, /* irq20 */
{0x82, NonHandledInterrupt}, /* irq21 */
{0x82, NonHandledInterrupt}, /* irq22 */
{0x82, NonHandledInterrupt}, /* irq23 */
{0x82, NonHandledInterrupt}, /* irq24 */
{0x82, NonHandledInterrupt}, /* irq25 */
{0x82, NonHandledInterrupt}, /* irq26 */
{0x82, NonHandledInterrupt}, /* irq27 */
{0x82, NonHandledInterrupt}, /* irq28 */
{0x82, NonHandledInterrupt}, /* irq29 */
};
编译项目通过
4、测试
设置断点单步调试,按下按键led点亮,再按led熄灭。
史海拾趣
|
如何将SMDK2440变成多个版本?例如我的产品210,对应的BSP是smdk2440210,产品220对应的是smdk2440220 本人菜鸟,现在碰到一个问题,希望向大家求助一下. 现在我的wince目录中的PLATFORM只有smdk2440一个bsp,这样产生了很多不方便的地方. 第一,目前有3个系列的产品,虽然都是基于2440的,但是在BSP上,还是有些地方是不同的,要维护这三个系列的产品.虽然 ...… 查看全部问答> |
|
DDK可以编译成两种版本。一个Free另外一个好象是Checked版本 有什么不同。 有时候我用Checked编译通过 Free不能通过编译 晕。 还有 VC里面不能 _asm mov ebp,esp 不能修改ebp的值吗?… 查看全部问答> |
|
ARM D/A转换程序设计 1.编程实现多种波形(正弦波信号、三角波信号、方波信号)的输出,在 DA接口利用示波器观测实验输出。 2.在 LCD上显示信号… 查看全部问答> |
|
我用的是神州stm32103系列的芯片,用开发板提供的程序i2c读写的读写函数放在液晶显示初始化ili9320的初始化程序下面就不能运行,我跟踪了程序,是在i2c读写函数的checkevent这里出现死循环, 导致程序没有办法继续往下执行,求指点,很急。 ...… 查看全部问答> |
|
请假,利用AVR实现与液晶屏的访问,如果采用直接访问(给液晶屏分配一个地址空间),直接接到对应的地址和数据线上,对应的RD和WR信号分别接到AVR的RD和WR上。但是如果采用间接访问的话,液晶屏幕的RD和WR信号是不是一般不能接在对应AVR的RD和WR信 ...… 查看全部问答> |




