Re: 計時器中斷與LED
|
||||
---|---|---|---|---|
高級會員
|
謝謝兩位板大的協助
計時中斷的小實驗已成功\r 這對於目前身為初學者的我 無非是莫大的鼓舞 再次感謝各位的耐心地幫助小弟 感恩
發表於: 2009/10/21 16:15
|
|||
|
Re: 計時器中斷與LED
|
||||
---|---|---|---|---|
資深會員
|
你中斷函數的名稱打錯了
void _ISR_T1Interrupt(void) <=== 錯誤, 中間沒有空格, 這樣變成是一個普通的函數,而不是中斷程式 請把R大寫的那行 複製貼上,取代掉你的 void __attribute__((interrupt, no_auto_psv)) _T1Interrupt(void)
發表於: 2009/10/21 14:26
|
|||
|
Re: 計時器中斷與LED
|
||||
---|---|---|---|---|
高級會員
|
已經嘗試過
程式並沒有跳進中斷 而是在無窮迴圈繞 附上依版大所修改的程式 #include <p30F4011.h> #include <timer.h> #define FCY 7372800*2 _FOSC(CSW_FSCM_OFF & XT_PLL8); _FWDT(WDT_OFF); _FBORPOR(PBOR_OFF & MCLR_EN); _FGS(CODE_PROT_OFF); int main(void) { ADPCFG=0xffff; TRISE=0xfff0; ConfigIntTimer1( T1_INT_PRIOR_3& T1_INT_ON) ; OpenTimer1(T1_ON & T1_GATE_OFF &T1_PS_1_256& T1_SYNC_EXT_OFF &T1_SOURCE_INT,0xE100); while(1) { } } void _ISR_T1Interrupt(void) { LATEbits.LATE0=!LATEbits.LATE0; IFS0bits.T1IF=0;
發表於: 2009/10/21 13:56
|
|||
|
Re: 計時器中斷與LED
|
||||
---|---|---|---|---|
版主
|
Timer 的中斷可以用MPLAB SIM 來測試。
在 Debug --> Setting 設定好 Fosc 後,開啟 Stopwatch 就可以知道,將斷點設在中斷處,中斷有沒有發生及 Timer1 的中斷時間。
發表於: 2009/10/21 13:28
|
|||
|
Re: 計時器中斷與LED
|
||||
---|---|---|---|---|
版主
|
void __ISR__T1Interrupt(void)
改成 : void __attribute__((interrupt, no_auto_psv)) _T1Interrupt(void) 或 void _ISR _T1Interrupt(void) 注意一下_ 的數目,有的是一個,比較長的是兩個。
發表於: 2009/10/21 13:21
|
|||
|
Re: 計時器中斷與LED
|
||||
---|---|---|---|---|
高級會員
|
回Ryang板大
小弟已把計時中斷改成 ConfigIntTimer1( T1_INT_PRIOR_3& T1_INT_ON) ; OpenTimer1(T1_ON & T1_GATE_OFF &T1_PS_1_256& T1_SYNC_EXT_OFF &T1_SOURCE_INT,0xE100); Period改成1S T1_1_8 改成 T1_1_256 也用示波器去量測 無方波輸出 也無法閃爍 錯誤應該是中斷進不去 我是否沒有宣告到哪個規範以致於中斷進不去?? 請指教 感嗯
發表於: 2009/10/21 12:43
|
|||
|
Re: 計時器中斷與LED
|
||||
---|---|---|---|---|
版主
|
參照:
算一下就出來了: FCY = 7372800*2 = 14745600 Hz Pre-Scaler 為 1:8 所以 (14745600/8)/8192 = 4.5mS LED 這種閃的速度你看的出來嗎? 將 T1_1_8 改成 T1_1_256,並將 Period 0x2000 改成 28800 後再算一次。 (14745600/256)/28800= 500mS
發表於: 2009/10/21 11:01
|
|||
|
Re: 計時器中斷與LED
|
||||
---|---|---|---|---|
版主
|
void Init_Timer1(void)
FOSC= 7372800Hz 用 (Fosc/4/1000)*10)/1 計時為 10mS 的 Period 的值為 18432。試想你用 2000 去除以 Fosc/4 後的時間是不是太短了,你可以用示波器勾一下 RE0 看看有沒有方波輸出。 還有將 Timer 的 Pre-Scaler 設為: 1:256 看看。
發表於: 2009/10/21 10:48
|
|||
|
Re: 計時器中斷與LED
|
||||
---|---|---|---|---|
高級會員
|
回nicecookie大大
謝謝你 我會再試試看 若無法進中斷 是否應改用另外計時器去使用?? 剛剛我有照你的方法試了一下 他還是依然無法閃爍 所以我就推測 應該是計時器的中斷進不去的關係
發表於: 2009/10/20 23:09
|
|||
|