• 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: 關於Timer0中斷 pic18f4520
#5
版主
版主


查看用戶資訊
今到公司再詳看PIC18F4520 Data Sheet,就如 nicecookie 所講,只有 INT0 不受IPEN的控制永遠指向 0x0008。如果IPEN 設為 0 ,中斷向量將與 PIC16F 相容變成只有一個中斷進入點,電此進入點位址還是維持在 PIC18F 的 0x0008,而 0x0018 就沒有用了。

發表於: 2009/4/6 14:04
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 關於Timer0中斷 pic18f4520
#4
資深會員
資深會員


查看用戶資訊
IPEN=0 時
中斷向量就是只有0x08, 而非0x18
這樣就可和PIC16 中斷模式相容
所以你的執行結果是正確的


另外, PIC18裡只有INT0無法設定高低優先權
其餘中斷都可以設定優先權


可以參考datasheet中斷結構圖就清楚了

發表於: 2009/4/6 10:02
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 關於Timer0中斷 pic18f4520
#3
新會員
新會員


查看用戶資訊
看看INTCON2的TMROIP是否設成High priority

發表於: 2009/4/6 9:08
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 關於Timer0中斷 pic18f4520
#2
版主
版主


查看用戶資訊
因在家裡,無順手資料可查。記億中 Timer 0 & INT0 只能設成高優先權中斷,並無法設成低優先權中斷。請查一下 Data Sheet 裡的中斷架構方塊圖。

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


關於Timer0中斷 pic18f4520
#1
初級會員
初級會員


查看用戶資訊
報歉之前的問題有打錯更正
下述是根據微處理器原理與應用-C語言與PIC18微控制器這本書的範例,裡面的timer0是設定成溢位中斷,高低優先中斷關閉,中斷向量設在0x0018,但是這樣都沒辦法正確的進入中斷,如果設成0x0008便可以了,想請問為什麼會這樣呢?

//**********************************************************
//* Ex8_4_But_TMR0INT.c
//* 程式將偵測按鍵SW3的狀態,並遞加計數的內容。
//* 利用中斷功能,當計數數值超過四次反轉燈號。
//**********************************************************
#include <p18f4520.h> //納入微控制器定義檔
#include <timers.h> //納入計時器函式庫定義檔

// 結構位元定義
#pragma config OSC=HS, BOREN=OFF, BORV = 2, PWRT=ON, WDT=OFF, LVP=OFF

#define OSC_CLOCK 10 // 工作時序頻率定義
#define push_no 4 //預設觸發次數
#define count_val 256-push_no

//宣告函式原型
void Init_TMR0(void);
void timer0_isr (void);

//宣告並安排中斷執行程式記憶體位置
#pragma code low_vector=0x18
void low_interrupt (void)
{
_asm GOTO timer0_isr _endasm
}
#pragma code

#pragma interruptlow timer0_isr

void timer0_isr (void)
{
INTCONbits.TMR0IF = 0; // 清除中斷旗標
WriteTimer0(count_val);
PORTD=PORTD^0xFF; // 使用運算敘述將LED燈號反轉

}


void main (void) {

PORTD = 0x0F;// 將PORTD設定為b'00001111'
TRISD = 0; // 將TRISD設為0,PORTD設定為輸出
TRISAbits.TRISA4=1;// 將按鍵3所對應的RA4設定為輸入

Init_TMR0(); // 初始化設定Timer0函式

INTCONbits.PEIE = 1; // 開啟周邊中斷功能
INTCONbits.GIE = 1; // 開啟全域中斷控制

while (1) ; // 無窮迴圈
}

void Init_TMR0 (void){
OpenTimer0(TIMER_INT_ON &T0_8BIT &T0_SOURCE_EXT &T0_EDGE_RISE &T0_PS_1_1 );

WriteTimer0(count_val); // 相當TMR0L=count_val
INTCONbits.TMR0IF = 0; // 清除中斷旗標

}

發表於: 2009/4/4 2:43
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... ]

教育訓練中心

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