你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

查看: 7548|回复: 2

STM8s103的定时器4定时中断问题

[复制链接]

5

主题

14

回帖

0

蝴蝶豆

新手上路

最后登录
1970-1-1
发表于 2011-11-4 20:27:26 | 显示全部楼层 |阅读模式
定时器4初始化
void timer_init( void )
{
 TIM4_CNTR = 0x00;   //计数器
 TIM4_PSCR = 0x07;   //分频数128
 TIM4_ARR = 0xFA;   //自动重载值
 TIM4_SR = 0x00;
 TIM4_IER = 0x01;   //更新中断使能
 TIM4_CR1 = 0x01;   //使能计数器
}
@far @interrupt void Time4_20ms_interrupt( void )
{
 LED();
}
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, NonHandledInterrupt}, /* 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, Time4_20ms_interrupt}, /* irq23 */
 {0x82, NonHandledInterrupt}, /* irq24 */
 {0x82, NonHandledInterrupt}, /* irq25 */
 {0x82, NonHandledInterrupt}, /* irq26 */
 {0x82, NonHandledInterrupt}, /* irq27 */
 {0x82, NonHandledInterrupt}, /* irq28 */
 {0x82, NonHandledInterrupt}, /* irq29 */
};
 
以上为定时器4及中断处理函数,中断映射函数,但是运行时却无法正常进中断
回复

使用道具 举报

134

主题

4489

回帖

239

蝴蝶豆

版主

最后登录
2020-12-9
发表于 2011-11-5 11:34:33 | 显示全部楼层

RE:STM8s103的定时器4定时中断问题

如下定义:
#ifdef _COSMIC_
@far @interrupt void TIM4_UPD_OVF_IRQHandler (void) {
#else
void TIM4_UPD_OVF_IRQHandler (void) interrupt 23 {
#endif
        TIM4->SR1&=~TIM4_SR1_UIF;                // clear overflow flag
        return;
}
回复 支持 反对

使用道具 举报

0

主题

1

回帖

0

蝴蝶豆

新手上路

最后登录
2015-3-25
发表于 2015-3-25 12:02:17 | 显示全部楼层
main.c:

#include "stm8s103f2u.h"
//int a,b,c;
void initLED(void);
void initTIM4(void);

/*void delay_10us(int us);
void delay_ms(unsigned int ms);*/

@far @interrupt void TIM4light(void);
main()
{  
        initLED();
        initTIM4();
        _asm("rim");
        TIM4_CR1|=0x01;
        while (1){
               
        }
}

void initLED(void){
        PC_DDR=0x70;
        PC_CR1=~0x70;
        PC_CR2=~0x70;
//        PC_ODR=0x70;
}

void initTIM4(void){
        TIM4_PSCR=0x07;
        TIM4_IER=0x01;
        TIM4_CNTR=255;
        TIM4_ARR=255;
}


中断向量表:

/*        BASIC INTERRUPT VECTOR TABLE FOR STM8 devices
*        Copyright (c) 2007 STMicroelectronics
*/
#include "stm8s103f2u.h"
int i;
typedef void @far (*interrupt_handler_t)(void);

struct interrupt_vector {
        unsigned char interrupt_instruction;
        interrupt_handler_t interrupt_handler;
};

@far @interrupt void NonHandledInterrupt (void)
{  
  return;
}

@far @interrupt void TIM4light (void)
{
       
        i++;
       
        if(i==61)
        { i=0;
                if(PC_ODR==0x70)
                {
                        PC_ODR=~0x70;
                }
                else
              {
                                  PC_ODR=0x70;
                                }
}
  TIM4_SR=0x00;
        return;
}

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, NonHandledInterrupt}, /* 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, TIM4light}, /* irq23 */
        {0x82, NonHandledInterrupt}, /* irq24 */
        {0x82, NonHandledInterrupt}, /* irq25 */
        {0x82, NonHandledInterrupt}, /* irq26 */
        {0x82, NonHandledInterrupt}, /* irq27 */
        {0x82, NonHandledInterrupt}, /* irq28 */
        {0x82, NonHandledInterrupt}, /* irq29 */
};

我的也进入不了中断,求大神!


回复 支持 反对

使用道具 举报

关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
STM32N6 AI生态系统
STM32MCU,MPU高性能GUI
ST ACEPACK电源模块
意法半导体生物传感器
STM32Cube扩展软件包
关注我们
微信公众号二维码 微信公众号
手机版二维码 手机版