Browsing this Thread:
1 Anonymous Users
|
睡不著怎麼辦?(Sleep mode)
|
|
新會員
Joined
: 2006/7/3 16:06 最後登入時間
: 2007/12/14 8:26
Group:
註冊會員
Level : 1 HP : 0 / 5 MP : 1 / 291 EXP : 21
|
在 18F452 1.用 INT0(RB0) 外部中斷將 CPU 從 Sleep 喚醒 --> 成功 2.用 RB4 關機,讓 CPU 進入 Sleep mode --> 成功 3.用 RB0 當開關,按一下開,按一下關 --> Sleep 後馬上自動開機
開機時在中斷程序將 INT0IE=0, 關機時先 INT0IE=1, 然後 Sleep 應該沒錯吧? 感覺上好像一進入 Sleep 馬上出現 INT0 中斷,又把 CPU 叫醒,所以在 INT0IE=1 之前又加上 1 秒的 Delay,避免 RB0 按鈕跳起來時產生中斷,但結果還是一樣,要如何解決呢?以下是程式碼,請各位先進不吝指教 ---------------------------------------------------------------------- #include <p18f452.h> #include <delays.h>
#define P_SW PORTBbits.RB0 #define P_OFF PORTBbits.RB4 #define LED PORTCbits.RC0
void isr_high_direct(void); void isr_high(void);
void main(void) { TRISBbits.TRISB0 = 1; // INT0 中斷 TRISBbits.TRISB4 = 1; // TACT Switch TRISCbits.TRISC0 = 0; LED = 0;
PIR1 = 0; PIR2 = 0; INTCON = 0; INTCON2 = 0; INTCON3 = 0; PIE1 = 0; PIE2 = 0; RCONbits.IPEN = 1; INTCONbits.GIEL = 0; INTCONbits.GIEH = 1; INTCON2bits.INTEDG0 = 0; INTCONbits.INT0IE = 1; Sleep(); while (1) { if (P_OFF == 0) { LED = 0; while (P_OFF == 0); Delay10KTCYx(100); INTCONbits.INT0IE = 1; Sleep(); } if (P_SW == 0) { LED = 0; while (P_SW == 0); Delay10KTCYx(100); INTCONbits.INT0IE = 1; Sleep(); } } }
#pragma code isrhighcode = 0x0008 void isr_high_direct(void) { _asm goto isr_high _endasm } #pragma code
#pragma interrupt isr_high void isr_high(void) { LED = 1; Delay10KTCYx(100); INTCONbits.INT0IE = 0; INTCONbits.INT0IF = 0; } #pragma code
發表於: 2006/7/29 23:51
|
|
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.