打印
[其他ST产品]

ST中TB中断只能进入一次

[复制链接]
2865|14
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
bluergreen|  楼主 | 2008-9-19 15:41 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
@interrupt void TB_INIT(void)
{
    PADR=0;
    return;
}
void main(void)
{
    PADDR=0x0F;
    PAOR=0x0F;
    LTCSR=0x10;
    _asm("nop");
    _asm("rim");
    PADR=0X0C;
    
}
我不知道在主程序中如何去等待中断,就像汇编中可以用JRA *指令来等待中断,而C语言中是不是用while(1)呢?我用过了好像不行,最令我觉得奇怪的是这个中断程序只能够进入一次,第二次并不能够进入,请问一下各位达人是什么问题呢
沙发
bluergreen|  楼主 | 2008-9-19 15:43 | 只看该作者

返回中断指令

返回中断调用的指令是用return吗,

使用特权

评论回复
板凳
香水城| | 2008-9-19 15:55 | 只看该作者

什么芯片?TB是什么?什么软件?

使用特权

评论回复
地板
bluergreen|  楼主 | 2008-9-19 16:15 | 只看该作者

ST7FLITE05YOM6,TB是8位定时器,STVD7的开发软件

使用特权

评论回复
5
bluergreen|  楼主 | 2008-9-19 16:16 | 只看该作者

给个ST系列C语言范例参考

最好上传个带有中断程序的例子作为参考,多谢!

使用特权

评论回复
6
grant_jx| | 2008-9-19 16:54 | 只看该作者

ST7有个外设软件库,里面有详细的描述可参考,ST网站可下载

/*
*******************************************************************************
* COPYRIGHT 2002 STMicroelectronics
* Source File Name : main.c                      
* Group            : IPSW,CMG-IPDF
* Author           : MCD Application Team
* Date First Issued: 8/3/2002
********************************Documentation**********************************
* General Purpose - This file gives an example application programme for LITE 
                    Timer.
********************************RevisionHistory********************************
_______________________________________________________________________________
 Date : 8/3/2002                    Release : 1.0 
 Date :28/04/04                     MISRA changes               
******************************************************************************/
#include "ST7lib_config.h"                              /*  select ST7FLITE0 */
#define LT_WDG   

//prototype declaration
void LT_ICAP_IT_Routine(void);
void LT_TB_IT_Routine(void);
void main(void);

volatile unsigned int count;  
void main (void)
{  
                                           /* PB3 and PB1 as pushpull output */
    IO_Output(IO_PUSH_PULL,IO_PORT_B,((unsigned char)IO_PIN_3 | 
                                                    (unsigned char)IO_PIN_1 ));
        /*Set Time base to 1ms,Input capture and Timebase interrupts enabled */
    LT_Init(((unsigned char)LT_ICAP_IT_ENABLE|(unsigned char)LT_TB_IT_ENABLE));
                                               /* Clear I bit in CC register */
    EnableInterrupts                /* Micro defined in the st7lib_config.h */
#ifdef LT_WDG                                 /* Use of force watchdog reset */
    LT_WDG_Enable();
    LT_WDG_Reset(LT_FORCD_WDG_RESET);
#endif /* LT_WDG_ */
    while(1);                                            /* For Testing only */
}
                                                              /* Program end */


/******************************************************************************
Use of Input capture Interrupt service routine
- User has to write this function and map the interrupt vector in .prm file in
  case of HIWARE or in vector_xxx.c in case of COSMIC.
- An example of LED toggles at port PB1 is given, which will be executed when
  capture occurs.
- This gets automatically executed if the ICAP interrupt of the LT is enabled. 
  If the same functions are called in the main Tree and the interrupt Tree, the 
  function Reentrant error occurs in case COSMIC compiler is used with models 
  other than stack models.
Functions description
- The lt_hr.h is to be included when the actual hardware register are read to 
  clear the flags.For configuring the port pins, I/O library is used.
******************************************************************************/

#ifdef _HIWARE_                                  /* Test for HIWARE Compiler */
#pragma TRAP_PROC SAVE_REGS            /* Additional registers will be saved */
#else
#ifdef _COSMIC_                                  /* Test for Cosmic Compiler */
@interrupt @nostack
#else
#error "Unsupported Compiler!"                /* Compiler Defines not found! */
#endif
#endif
void LT_IC_IT_Routine(void)
{
    unsigned char ICAP_Value, i;
                                                     /* i = LTICR; Clear ICF */
    LT_Clear_Flag(LT_FLAG_ICF);                    /* Call only to clear ICF */
    ICAP_Value = LT_ICAP_Getvalue(); /* Get capture value and also clear ICF */
    IO_Write (IO_PORT_B,IO_PIN_1,IO_DATA_HIGH);        /* Turn ON LED at PB1 */
    for ( i=0;i<=100;i++)                                           /* Delay */
    {
        Nop
    }
    IO_Write (IO_PORT_B,IO_PIN_1,IO_DATA_LOW);        /* Turn OFF LED at PB1 */
}


/******************************************************************************
Use of TimebaseInterrupt service routine
- User has to write this function and map the interrupt vector in .prm file in 
  case of HIWARE or in vector_xxx.c in case of COSMIC.
- An example of LED toggles after every 5 seconds is given.This routine is 
  executed when overflow occurs (TBF=1).
- This gets automatically executed when TBF interrupt of the LT is enabled. If 
  the same functions are called in the main Tree and the interrupt Tree, the 
  function Reentrant error occurs in case COSMIC compiler is used with models 
  other than stack models.
Functions description
- The lt_hr.h is to be included when the actual hardware register are read to 
  clear the flags.For configuring the port pins, I/O library is used.
******************************************************************************/
#ifdef _HIWARE_                                  /* Test for HIWARE Compiler */
#pragma TRAP_PROC SAVE_REGS            /* Additional registers will be saved */
#else
#ifdef _COSMIC_                                  /* Test for Cosmic Compiler */
@interrupt @nostack
#else
#error "Unsupported Compiler!"                /* Compiler Defines not found! */
#endif
#endif
void LT_TB_IT_Routine(void)
{
    unsigned char Temp;
                                                     /* i = LTCSR; Clear ICF */
    LT_Clear_Flag(LT_FLAG_TBF);                    /* Call only to clear TBF */
                                                   /* Routine up to the user */
    count++;
    if(count == 5000)
    {
        Temp = IO_Read (IO_PORT_B );                        /* TO Toggle PB3 */
        if (Temp & 0x08)
        {
            IO_Write (IO_PORT_B,IO_PIN_3,IO_DATA_LOW);/* Turn OFF LED at PB3 */
        }
        else
        {
            IO_Write (IO_PORT_B,IO_PIN_3,IO_DATA_HIGH);/* Turn ON LED at PB3 */
        }
        count = 0;
    }
}
/******************** (c) 2002  ST Microelectronics *************END OF FILE**/        

使用特权

评论回复
7
bluergreen|  楼主 | 2008-9-20 11:21 | 只看该作者

给个具体一点的链接可以吗,谢谢

使用特权

评论回复
8
香水城| | 2008-9-20 12:07 | 只看该作者

ST的官方网站上有

使用特权

评论回复
9
bluergreen|  楼主 | 2008-9-22 08:52 | 只看该作者

#pragma用法

使用特权

评论回复
10
bluergreen|  楼主 | 2008-9-22 08:54 | 只看该作者

6楼具体例子中有#pragma的使用,请解释一下

#pragma TRAP_PROC SAVE_REGS            /* Additional registers will be saved */
@interrupt @nostack

使用特权

评论回复
11
grant_jx| | 2008-9-22 09:00 | 只看该作者

看看条件编译的条件好不好

#pragma关键字是HIWARE编译器的,不是COSMIC的,如果使用COSMIC编译器,中断函数申明应该是:

@interrupt @nostack void LT_TB_IT_Routine(void)


HIWARE是以前的ST7 C编译器,出这个编译器的公司很久以前被Freescale收购了,现在已经不在出了。


楼上的使用的编译器是COSMIC,请在阅读的时候忽略掉
#ifdef _HIWARE_              /* Test for HIWARE Compiler */
……………………
#else
内容即可。

使用特权

评论回复
12
bluergreen|  楼主 | 2008-9-22 11:44 | 只看该作者

多谢,我明白了

使用特权

评论回复
13
8bit_mcu| | 2008-9-23 09:41 | 只看该作者

其他先不说,至少得加上下面两句

@interrupt void TB_INIT(void)
{   LTCSR;    ////清中断
    PADR=0;
    return;
}
void main(void)
{
    PADDR=0x0F;
    PAOR=0x0F;
    LTCSR=0x10;
    _asm("nop");
    _asm("rim");
    PADR=0X0C;
    while(1);/////等待中断
    

使用特权

评论回复
14
grant_jx| | 2008-9-23 11:54 | 只看该作者

ST7的中断特点

ST 8bit MCU中断的特点,进去先执行读状态寄存器的操作,这样做的目的是清中断标志未,免得出去了又直接进来了。不过有些中断标志位可能还需要在读了状态寄存器后再跟着访问一下相应外设的某个寄存器的低8位。典型的就是定时器,想直接通过指令来清标志位是不可以的。

楼上的代码对LT的状态寄存器操作有些遗漏,给你补上。

@interrupt void TB_INIT(void)
{
   unsigned char Temp;
   Temp = LTCSR;    ////清中断
   PADR=0;
   return;
}

使用特权

评论回复
15
bluergreen|  楼主 | 2008-9-24 12:03 | 只看该作者

多谢各位高手的解答,我现在已经明白了如何使用定时器了

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

22

主题

56

帖子

0

粉丝