• slider image 442
  • slider image 483
  • slider image 484
  • slider image 485
  • slider image 486
  • slider image 487
  • slider image 488
  • slider image 491
:::


Browsing this Thread:   1 Anonymous Users






Re: 请教一个奇怪的中断服务程序问题
#3
新會員
新會員


查看用戶資訊
懂了,谢谢指教!

發表於: 2009/5/22 16:39
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 请教一个奇怪的中断服务程序问题
#2
版主
版主


查看用戶資訊
在GLD 有對中斷作定義: 如果有啟動 Timer1 的中斷,一但發生 Timer1 的中斷後就會跳到 _T1Interrupt( ) 的中斷函數。如果沒有定義此中斷的話就會跳到 _DefaultInterrupt( ) 的進入點,而此進入點為 0x000000 所以就進入 Reset 點執行,看起來像被 Reset 一樣。
LONG(DEFINED(__T1Interrupt) ? ABSOLUTE(__T1Interrupt) :
ABSOLUTE(__DefaultInterrupt));

底下有一個 NMI 中斷的攔截程式可以避免 NMI 發生時導致程式從Reset 開始。
********************************************************************
*
*  
Filename:   traps.c
*  Purpose:    Boilerplate file for handling traps.
*              If 
any trap is takenthe program will "dead lock"
*              in the trap handler.  The following traps are
*              covered (primary and alternate):
*                 
OscillatorFail
*                 AddressError
*                 StackError
*                 MathError
*
*********************************************************************/

/* Header Files */
#include "p30fxxxx.h"

/* Function Prototypes */
void _ISR _OscillatorFail(void);
void _ISR _AddressError(void);
void _ISR _StackError(void);
void _ISR _MathError(void);
void _ISR _AltOscillatorFail(void);
void _ISR _AltAddressError(void);
void _ISR _AltStackError(void);
void _ISR _AltMathError(void);


/* ************************************************************** */
/* Standard Exception Vector handlers if ALTIVT = 0, INTCON2<15> */
/* ************************************************************** */

void _ISR _OscillatorFail(void)
{

    
INTCON1bits.OSCFAIL 0;
    while(
1);     
}

void _ISR _AddressError(void)
{

    
INTCON1bits.ADDRERR 0;
    while(
1);     
}

void _ISR _StackError(void)
{

    
INTCON1bits.STKERR 0;
    while(
1);     
}

void _ISR _MathError(void)
{

    
INTCON1bits.MATHERR 0;
    while(
1);     
}


/* ************************************************************** */
/* Alternate Exception Vector handlers if ALTIVT = 1, INTCON2<15> */
/* ************************************************************** */


void _ISR _AltOscillatorFail(void)
{

    
INTCON1bits.OSCFAIL 0;
    while(
1);     
}

void _ISR _AltAddressError(void)
{

    
INTCON1bits.ADDRERR 0;
    while(
1);     
}

void _ISR _AltStackError(void)
{

    
INTCON1bits.STKERR 0;
    while(
1);     
}

void _ISR _AltMathError(void)
{

    
INTCON1bits.MATHERR 0;
    while(
1);     
}

Attach file:



jpg  (0.00 KB)


發表於: 2009/5/22 15:52
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


请教一个奇怪的中断服务程序问题
#1
新會員
新會員


查看用戶資訊
诚心请教:开了定时器中断,如果没写中断服务子程序的话,会出现什么情况?以下是我的程序,实际测试中发现上述情况下片子会复位,LED灯会闪烁。
测试条件为:
单片机——dsPIC30F4011
看门狗——关闭,掉电复位——关闭。

#include <p30f4011.h>

#define LED _LATC14

_FOSC(CSW_FSCM_OFF & XT_PLL4); //XT为4*PLL振荡器,失效保险时钟关闭
_FWDT(WDT_OFF & WDTPSA_512 & WDTPSB_1); //禁止看门狗定时器,复位时间2ms*512*1=1.024s
_FBORPOR( PBOR_OFF & MCLR_EN & //禁止掉电复位,使能MCLR复位
RST_PWMPIN & PWMxH_ACT_HI & PWMxL_ACT_HI); //PWM模块控制复位时引脚状态,输出高电平有效
_FGS(CODE_PROT_OFF);



void Init ( void )
{
uint tttry;
/* IO端口初始化 */
TRISB = 0x01FF; //RB设置为输入
TRISC = 0xA000; //RC14设置为输出,RC13,RC15设置为输入
LED=0; //RC14输出低电平
for(tttry=1000;tttry>=1;tttry--);
TRISD = 0x000F; //RD0~RD3设置为输入
TRISE = 0x0100; //RE8设置为输入,RE0~RE5设置为输出
TRISF = 0x001D; //RF1,RF5,RF6设置为输出,其余引脚为输入
_LATF6=0; //RF6引脚输出低电平


/* 定时器1初始化 */

T1CON=0; //关闭定时器1
TMR1=0; //定时器计数寄存器清零
PR1=25000; //计数至PR1溢出,溢出间隔为25000*1/4*8us=50ms
T1CON=0x8010; //定时器开,预分频比1:8,内部时钟,FOSC/4=4MHz/4=1MHz
_T1IP=4; //中断优先级为4
_T1IF=0; //清中断标志
_T1IE=1; //使能定时器1中断
}



void __attribute__((__interrupt__)) _T1Interrupt(void)
{
_T1IF=0; //清中断标志位
LED_timer++;
if(LED_timer>=20)
{
LED_timer=0;
}
return;
}

int main ( void )
{
Init();

while(1)
{
LED=1;
}
while(1){}
}

發表於: 2009/5/22 9:38
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部







You can view topic.
不可以 發起新主題
You cannot reply to posts.
You cannot edit your posts.
You cannot delete your posts.
You cannot add new polls.
You cannot vote in polls.
You cannot attach files to posts.
You cannot post without approval.
You cannot use topic type.
You cannot use HTML syntax.
You cannot use signature.
You cannot create PDF files.
You cannot get print page.

[進階搜尋]


:::

Microchip連結

https://www.facebook.com/microchiptechnologytaiwan/
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=13
https://mu.microchip.com/page/tmu
http://elearning.microchip.com.tw/modules/tad_link/index.php?cate_sn=1
https://page.microchip.com/APAC-PrefCenters-TW.html
http://www.microchip.com/
http://www.microchip.com/treelink
http://www.microchipdirect.com/
http://www.microchip.com.cn/newcommunity/index.php?m=Video&a=index&id=103
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=2
http://www.microchip.com.tw/Data_CD/eLearning/index.html
http://www.microchip.com.tw/RTC/RTC_DVD/
https://www.microchip.com/development-tools/
https://www.youtube.com/user/MicrochipTechnology
[ more... ]

教育訓練中心

!開發工具購買
辦法說明 [業界客戶] [教育單位]
----------------------------------
!校園樣品申請
辦法說明 [教師資格] [學生資格]
----------------------------------