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


Browsing this Thread:   1 Anonymous Users




(1) 2 »


Re: 利用Timer中斷來掃描按鍵~成功了...感謝大家
#18
資深會員
資深會員


查看用戶資訊
感謝大家提供的意見,在我每次失敗的時候我就把討論區開出來看一看,仔細想想各位的用法,一步一步的try出來,我把程式po出來,希望哪天有人需要時可以得到幫助,但針對每個人不同的狀況不見得有效,謝謝!


if(PORTAbits.RA4==0)
FLAGbits.kin=1;
if(FLAGbits.kin==1)
{
if(FLAGbits.TMR1INT==1)
{
keydelay++;
FLAGbits.TMR1INT=0;
if(keydelay==20)
{
while(~PORTAbits.RA4);
PORTDbits.RD0=!PORTDbits.RD0;
keydelay=0;
FLAGbits.kin=0;
}
}
}

發表於: 2009/7/9 22:56
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 利用Timer中斷來掃描按鍵
#17
資深會員
資深會員


查看用戶資訊
nicecookie感謝您的協助,我再試試看!

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


Re: 利用Timer中斷來掃描按鍵
#16
資深會員
資深會員


查看用戶資訊
參照:

lancer0498 寫道:


while(1)
{
scankey();
}
}

void scankey()
{
if(FLAGbits.TMR1INT==1 && PORTAbits.RA4==0 )
{
debounce++;
FLAGbits.TMR1INT=0;
if(debounce==10)
{
PORTDbits.RD0=!PORTDbits.RD0;
debounce=0;
}
}
else
debounce=0; //不能這裡 =0
}



你的 debounce變數應該 永遠也計數不到10 吧

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


Re: 利用Timer中斷來掃描按鍵
#15
資深會員
資深會員


查看用戶資訊
參照:

jlian 寫道:
如果main()大於100ms則該用何種方法?


會說while - loop 大於100ms 不適合
意思是會使按鍵偵測變的鈍鈍的
不介意這種問題的話,也沒甚麼不能用的


一般會到主程式才執行掃描是希望中斷程式能越短越好
如果while - loop 時間太長時,
當然也只好在timer中斷裡面就直接進行掃瞄了


另外,如果按鍵數不多的話
用pin change的中斷功能也是很適合當作按鍵偵測的

發表於: 2009/7/9 12:48
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 利用Timer中斷來掃描按鍵
#14
資深會員
資深會員


查看用戶資訊
參照:

lancer0498 寫道:
nicecookie謝謝您的指教,我常在microchip討論區上看您幫許多人解答,對於我們這些初學者來說,你的不吝指教真的可以幫助很多人,謝謝!


其實我也只會一些基本的東西而已,能分享的也不多啦
搞不好說錯了 誤導人家 也說不定
版主和MASTER等的其他大大,才是高手

有時候會因為個人情緒好惡,不小心寫了些情緒或批評的話
不知道會不會因此害microchip少了不少客人勒

發表於: 2009/7/9 12:39
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 利用Timer中斷來掃描按鍵
#13
資深會員
資深會員


查看用戶資訊
nicecookie謝謝您的指教,我常在microchip討論區上看您幫許多人解答,對於我們這些初學者來說,你的不吝指教真的可以幫助很多人,謝謝!

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


Re: 利用Timer中斷來掃描按鍵
#12
資深會員
資深會員


查看用戶資訊
請問nicecookie先進:
如果main()大於100ms則該用何種方法?

煩請告知,Thanks.

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


Re: 利用Timer中斷來掃描按鍵
#11
資深會員
資深會員


查看用戶資訊
f(FLAGbits.TMR1INT==1 & PORTAbits.RA4==0 )

不能用 &,那是邏輯運算子

條件判斷要用 &&

發表於: 2009/7/9 8:56
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 利用Timer中斷來掃描按鍵
#10
資深會員
資深會員


查看用戶資訊
各位高手,我用這樣的方式一直沒辦法讀取按鍵狀態,
不知道是否哪裡觀念有錯,請各位指導一下,謝謝!
以下程式是用來練習TIMER中斷讀取按鍵寫的!

#include <p18f4520.h>
#include <timers.h>

#pragma config OSC=HS,BOREN=OFF,LVP=OFF,BORV=2,WDT=OFF,PWRT=ON

#define TMR1_VAL 55536
#define OSC_CLOCK 10

unsigned char debounce=0;

void scankey();

struct
{
unsigned TMR1INT:1;
}FLAGbits;

void timer1_isr(void);

#pragma code high_vector=0x08
void high_interrupt(void)
{
_asm GOTO timer1_isr _endasm
}
#pragma code

#pragma interrupt timer1_isr
void timer1_isr(void)
{
PIR1bits.TMR1IF=0;
WriteTimer1(TMR1_VAL);
FLAGbits.TMR1INT=1;
}

void main(void)
{
PORTD=0x01;
TRISD=0;
TRISAbits.TRISA4=1; // 設定RA4為數位輸入腳位
FLAGbits.TMR1INT=0;

OpenTimer1( TIMER_INT_ON &
T1_16BIT_RW &
T1_SOURCE_INT &
T1_PS_1_1 &
T1_OSC1EN_ON &
T1_SYNC_EXT_OFF );

WriteTimer1(TMR1_VAL);

PIR1bits.TMR1IF = 0; // 清除中斷旗標
IPR1bits.TMR1IP = 1; // 設定為高優先中斷
RCONbits.IPEN=1; // 開啟中斷優先功能
INTCONbits.GIEL = 1; // 開啟低優先中斷功能
INTCONbits.GIEH = 1; // 開啟高優先中斷功能
FLAGbits.TMR1INT=0;

while(1)
{
scankey();
}
}

void scankey()
{
if(FLAGbits.TMR1INT==1 & PORTAbits.RA4==0 )
{
debounce++;
FLAGbits.TMR1INT=0;
if(debounce==10)
{
PORTDbits.RD0=!PORTDbits.RD0;
debounce=0;
}
}
else
debounce=0;
}

發表於: 2009/7/8 22:48
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 利用Timer中斷來掃描按鍵
#9
資深會員
資深會員


查看用戶資訊
真的很感謝各位大大提供的方式,我先試一下,若有問題再請教各位,希望能成功,謝謝!

發表於: 2009/7/7 20:30
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... ]

教育訓練中心

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