Re: PIC18F中斷問題
|
||||
---|---|---|---|---|
新會員
|
謝謝Beee 的解說,我會再花點時間研究一下,如果有其他問題再麻煩前輩們了,Thanks.
發表於: 2010/2/24 18:54
|
|||
|
PIC18F中斷問題
|
||||
---|---|---|---|---|
新會員
|
大家好
關於中斷的觀念我看了很久找些資料,還是有很多地方無法了解希望各位前輩能夠給我些意見 首先我利用C18教材EX5-2簡化了一些地方來進行測試, 目的是利用timer2中斷讓portD累加而已,檔案如下: //************************ #include <p18cxxx.h> #include <timers.h> #include <delays.h> #pragma config OSC=HS #pragma config PWRT=OFF #pragma config BOREN=OFF, BORV=1 #pragma config WDT=OFF #pragma config CCP2MX=PORTC #pragma config STVREN=OFF, LVP=OFF, DEBUG=OFF #pragma config CPD=OFF void isr_high(void); volatile unsigned char Long_Count ; void main(void) { TRISD=0x00; // Set output port for LED driver PORTD=0x00; /***********************************/ /* Interrupt Time */ /***********************************/ RCONbits.IPEN=1; // Enable Interrupt Priority bit IPR1bits.TMR2IP=1; // Set Timer2 for High Priority INTCONbits.GIEH=1; // Enable High Priority Interrupt OpenTimer2 ( TIMER_INT_ON // Turn On the Timer2 with Interrupt & T2_PS_1_16 & T2_POST_1_10); PR2 = 199; //8 bits value 0~255 Long_Count=0; while(1); // Loop Here! } //************************************************ //* #pragma Interrupt Declarations * //************************************************ #pragma code isrhighcode = 0x0008 void isr_high_direct(void) { _asm //begin in-line assembly goto isr_high //go to isr_high function _endasm //end in-line assembly } #pragma code //************************************************ //* Function: isr_high(void) * //************************************************ #pragma interrupt isr_high void isr_high(void) { PIR1bits.TMR2IF=0; // Clear Timer2 interrupt Flag if (Long_Count <= 12) Long_Count++; else { Long_Count=0; PORTD++ ; } } #pragma code Q1:為何我將上面的中斷向量位址0x0008 改為0x0018程式依然可以正常運作? 這整個程式不是設定為高優先中斷嗎? Q2:同樣的為什麼我將 #pragma interrupt 改為 #pragma interruptlow程式依然正常運作? Timer與0x0008向量不都是設定為高優先中斷嗎? Q3:18F系列的中斷向量有兩個,但是中斷源有很多個,意思就是說這兩個中斷向量只能被其中兩個中斷源使用是嗎? Q4:在18F4520的 datasheet中 Figure9-1裡面有interrupt logic,裡面畫有高優先低優先中斷向量,圖中只有出現Timer0,並沒有Timer1~Timer3,那是表示除了Timer0之外其他timer都不能使用這兩個中斷向量嗎? 既然如此為何上面這範例的中斷還是可以運作? 問題有點多麻煩前輩提點,謝謝
發表於: 2010/2/23 23:10
|
|||
|