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

論壇索引


Board index » All Posts (hidecool)




Re: 問題:PIC18F452 用TIMER0做內部中斷定時器
#11
新會員
新會員


如您所說

加了while(1);

順暢許多

感謝大大指點!

發表於: 2009/1/7 19:28
頂部


問題:PIC18F452 用TIMER0做內部中斷定時器
#12
新會員
新會員


#include <p18f452.h>
#include <timers.h>
#include <portb.h>
#include <delays.h>

void high_isr(void);
unsigned int ct=0;

#pragma code high_priority_vector = 0x08

void high_interrupt_vector(void)
{
_asm
goto high_isr
_endasm
}

#pragma code
#pragma interrupt high_isr

void high_isr(void)
{
if(INTCONbits.INT0IF==1)
{
ct++;
INTCONbits.INT0IF=0;
}
if(INTCONbits.TMR0IF==1)
{
INTCONbits.TMR0IF=0;
WriteTimer0(18661);
LATD=ct;
ct=0;
}
}

void main (void)
{
TRISB = 0xff;
TRISD = 0;
WriteTimer0(18661);
OpenTimer0(TIMER_INT_ON & T0_16BIT & T0_SOURCE_INT & T0_PS_1_256);
OpenRB0INT(PORTB_CHANGE_INT_ON & FALLING_EDGE_INT & PORTB_PULLUPS_ON );
RCONbits.IPEN=1;
INTCONbits.GIEH=1;
INTCONbits.TMR0IE=1;
INTCONbits.INT0IE=1;
}


以上是我編寫老師的定時計數器程式...不知為何...無法正常運行
此程式是希望能計算三秒內(TIMER0定時3秒)
RB0(INT0)接收到的電壓訊號次數,然後由PORTD輸出

電壓訊號我是使用電容式麥克風經過處理後使之變為類似開關之做動
(有聲音就有電壓;反之則沒有。電壓大小與輸入電壓相等5V)

以上程式不了解的地方為主程式的地方
void main (void)
{
TRISB = 0xff; //設定PORTB為輸入,對吧?
TRISD = 0; //設定PORTD為輸出,對吧?
WriteTimer0(18661); //設定定時器初始值
OpenTimer0(TIMER_INT_ON & T0_16BIT & T0_SOURCE_INT & T0_PS_1_256); //開啟TIMER0功能並設定
OpenRB0INT(PORTB_CHANGE_INT_ON & FALLING_EDGE_INT & PORTB_PULLUPS_ON ); //開啟RB0INT功能並設定

RCONbits.IPEN=1; //優先中斷權啟用
INTCONbits.GIEH=1; //INEN=1時,高優先中斷啟用
INTCONbits.TMR0IE=1; //開啟TIMER0溢出中斷
INTCONbits.INT0IE=1; //開啟INT0中斷
}

其中TIMER功能設定的地方,查書有查到bit0-7的功能設定
但不知道如何寫入括號內
希望有人能解說誇號內設定之意思
例如:
TIMER_INT_ON 為設定TIMER啟動 如何啟動??
T0_16BIT 設定TIMER0為16位元
..依此類推..

外部中斷的OpenRB0INT括號內之設定也幫忙解說一下

再來就是後面接著的
RCONbits.IPEN=1;
INTCONbits.GIEH=1;
INTCONbits.TMR0IE=1;
INTCONbits.INT0IE=1;
這些 這樣設定對嗎? 有缺什麼嗎??
請各位大大指教 謝謝

發表於: 2009/1/5 21:48
頂部



« 1 (2)



:::

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... ]

教育訓練中心

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