• 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






睡不著怎麼辦?(Sleep mode)
#1
新會員
新會員


查看用戶資訊
在 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
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... ]

教育訓練中心

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