Re: 利用Timer中斷來掃描按鍵
|
||||
---|---|---|---|---|
資深會員
|
nicecookie感謝您的協助,我再試試看!
發表於: 2009/7/9 15:28
|
|||
|
Re: 利用Timer中斷來掃描按鍵
|
||||
---|---|---|---|---|
資深會員
|
參照:
你的 debounce變數應該 永遠也計數不到10 吧
發表於: 2009/7/9 13:15
|
|||
|
Re: 利用Timer中斷來掃描按鍵
|
||||
---|---|---|---|---|
資深會員
|
參照:
會說while - loop 大於100ms 不適合 意思是會使按鍵偵測變的鈍鈍的 不介意這種問題的話,也沒甚麼不能用的 一般會到主程式才執行掃描是希望中斷程式能越短越好 如果while - loop 時間太長時, 當然也只好在timer中斷裡面就直接進行掃瞄了 另外,如果按鍵數不多的話 用pin change的中斷功能也是很適合當作按鍵偵測的
發表於: 2009/7/9 12:48
|
|||
|
Re: 利用Timer中斷來掃描按鍵
|
||||
---|---|---|---|---|
資深會員
|
參照:
其實我也只會一些基本的東西而已,能分享的也不多啦 搞不好說錯了 誤導人家 也說不定 版主和MASTER等的其他大大,才是高手 有時候會因為個人情緒好惡,不小心寫了些情緒或批評的話 不知道會不會因此害microchip少了不少客人勒
發表於: 2009/7/9 12:39
|
|||
|
Re: 利用Timer中斷來掃描按鍵
|
||||
---|---|---|---|---|
資深會員
|
nicecookie謝謝您的指教,我常在microchip討論區上看您幫許多人解答,對於我們這些初學者來說,你的不吝指教真的可以幫助很多人,謝謝!
發表於: 2009/7/9 9:36
|
|||
|
Re: 利用Timer中斷來掃描按鍵
|
||||
---|---|---|---|---|
資深會員
|
請問nicecookie先進:
如果main()大於100ms則該用何種方法? 煩請告知,Thanks.
發表於: 2009/7/9 9:33
|
|||
|
Re: 利用Timer中斷來掃描按鍵
|
||||
---|---|---|---|---|
資深會員
|
f(FLAGbits.TMR1INT==1 & PORTAbits.RA4==0 )
不能用 &,那是邏輯運算子 條件判斷要用 &&
發表於: 2009/7/9 8:56
|
|||
|
Re: 利用Timer中斷來掃描按鍵
|
||||
---|---|---|---|---|
資深會員
|
各位高手,我用這樣的方式一直沒辦法讀取按鍵狀態,
不知道是否哪裡觀念有錯,請各位指導一下,謝謝! 以下程式是用來練習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
|
|||
|
Re: 利用Timer中斷來掃描按鍵
|
||||
---|---|---|---|---|
資深會員
|
真的很感謝各位大大提供的方式,我先試一下,若有問題再請教各位,希望能成功,謝謝!
發表於: 2009/7/7 20:30
|
|||
|