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


Browsing this Thread:   1 Anonymous Users






Re: PIC18F4580 如何使用 3 個 interrupt
#5
初級會員
初級會員


查看用戶資訊
問題解決了
謝謝!

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


Re: PIC18F4580 如何使用 3 個 interrupt
#4
版主
版主


查看用戶資訊
是的。
別忘了要離開前要把這個中斷旗號 (IF)清掉,不然跳回主程式後又會再次產生中斷的。

發表於: 2009/1/16 15:38
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: PIC18F4580 如何使用 3 個 interrupt
#3
初級會員
初級會員


查看用戶資訊
謝謝回應

所以,請問一下
意思就是只有一個 low interrupt 的 subroutine
只是在這個 subroutine 加上一個判斷是哪一種中斷的意思嗎?

再次謝謝

發表於: 2009/1/16 15:09
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: PIC18F4580 如何使用 3 個 interrupt
#2
版主
版主


查看用戶資訊
一個中斷不是說只能做一個中斷處理,只要一進入中斷時先去判斷是誰發生了中斷就去服務誰。這樣就可以有多種中斷可以處理。

void interruptlow Timer-isr (void)
{
        if (
T0IF) {            // Tomer0 interrupt
                
TMR0 =250 ;    // Reload the Timer value
                
T0IF ;    // Clear Timer0 INT flag
              
}

        if (
INTF) {
                
Relay ;     // Turn the relay on
                
INTF ;    // Clear the interrupt
              
}
}

發表於: 2009/1/16 13:58
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


PIC18F4580 如何使用 3 個 interrupt
#1
初級會員
初級會員


查看用戶資訊
各位好

我用的是 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
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... ]

教育訓練中心

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