Re: PIC18F4580 如何使用 3 個 interrupt
|
||||
---|---|---|---|---|
初級會員
|
問題解決了
謝謝!
發表於: 2009/1/16 16:32
|
|||
|
Re: PIC18F4580 如何使用 3 個 interrupt
|
||||
---|---|---|---|---|
版主
|
是的。
別忘了要離開前要把這個中斷旗號 (IF)清掉,不然跳回主程式後又會再次產生中斷的。
發表於: 2009/1/16 15:38
|
|||
|
Re: PIC18F4580 如何使用 3 個 interrupt
|
||||
---|---|---|---|---|
初級會員
|
謝謝回應
所以,請問一下 意思就是只有一個 low interrupt 的 subroutine 只是在這個 subroutine 加上一個判斷是哪一種中斷的意思嗎? 再次謝謝
發表於: 2009/1/16 15:09
|
|||
|
PIC18F4580 如何使用 3 個 interrupt
|
||||
---|---|---|---|---|
初級會員
|
各位好
我用的是 PIC18F4580 的晶片。目前遇到一個問題就是希望可以同時使用 3 個 interrupt,其中兩個是從 timer1 和 timer2 來的 interrupt, 另一個是 USART 的 interrupt 我目前需要用到兩個 timer (timer 1 和 timer 2) 且每隔一段時間個別會有 interrupt 發生 之前寫法就是設定其中一個為 high priority (timer2) 另一個設定成 low priority (timer1) main 裡面的設定為 IPR1bits.TMR1IP = 0; //設定為低優先中斷 IPR1bits.TMR2IP = 1; //設定為高優先中斷 RCONbits.IPEN=1; // 開啟中斷優先功能 INTCONbits.GIEL = 1; // 開啟低優先中斷功能 INTCONbits.GIEH = 1; // 開啟高優先中斷功能 其中 timer 1 的 interrupt 設定如: #pragma code low_vector=0x18 void low_interrupt (void) { _asm GOTO timer1_isr _endasm } #pragma code #pragma interruptlow timer1_isr timer2 的 interrupt 設定如下: #pragma code high_vector=0x08 void high_interrupt (void) { _asm GOTO timer2_isr _endasm } #pragma code #pragma interrupt timer2_isr timer1_isr 為timer 1 發生中斷時的 Subroutine, timer2_isr 為 timer2 發生中斷時的 subroutine 問題來了 現在我需要加上 USART 的功能 以前參考範例程式的部份,USART 也會利用 interrupt 來驅動 USART 的讀寫 我問題是 我要如何設定讓這三個 interrupt 同時存在且可以個別指定到所要的 subroutine? 我目前的作法是在 main 增加一行 IPR1bits.TMR1IP = 0; //設定為低優先中斷 IPR1bits.TMR2IP = 1; //設定為高優先中斷 IPR1bits.RCIP = 0; //設定為低優先中斷 RCONbits.IPEN=1; // 開啟中斷優先功能 INTCONbits.GIEL = 1; // 開啟低優先中斷功能 INTCONbits.GIEH = 1; // 開啟高優先中斷功能 且另外定義/設定了 USART 的中斷 priority #pragma code low_vector=0x18 void low_interrupt_usart (void) { _asm GOTO Rx_isr _endasm } #pragma code #pragma interruptlow Rx_isr Rx_isr 為我USART收到東西後的Subroutine 目前遇到的問題是 要是這樣寫的話,他只會一直在 Rx_isr subroutine 裡面跑,並不會跳到 timer1_isr timer2_isr 兩個 subroutine 請問各位,我要怎麼解決這樣的問題 或是我要怎麼能夠用 3 個 interrupt 同時存在? 謝謝各位看完這篇文章
發表於: 2009/1/16 12:15
|
|||
|