首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >带有内部振荡器的睡眠模式(PIC 18f46j50)

带有内部振荡器的睡眠模式(PIC 18f46j50)
EN

Stack Overflow用户
提问于 2017-04-30 02:03:40
回答 1查看 804关注 0票数 1

我正在对我的PIC进行编程,并试图将其置于深度睡眠模式。我想使用深度睡眠功能,唤醒事件应该是由WDT interupt创建的。但我的问题是,不可能到达中断。设备将继续休眠。

代码语言:javascript
复制
#include <xc.h> 

// 'C' source line config statements

// CONFIG1L
#pragma config WDTEN = ON       // Watchdog Timer (Enabled)
#pragma config PLLDIV = 1       // PLL Prescaler Selection bits (No prescale (4 MHz oscillator input drives PLL directly))
#pragma config STVREN = ON      // Stack Overflow/Underflow Reset (Enabled)
#pragma config XINST = OFF       // Extended Instruction Set (Enabled)

// CONFIG1H
#pragma config CPUDIV = OSC1    // CPU System Clock Postscaler (No CPU system clock divide)
#pragma config CP0 = OFF        // Code Protect (Program memory is not code-protected)

// CONFIG2L
#pragma config OSC = HS         // Oscillator (HS, USB-HS)
#pragma config T1DIG = ON       // T1OSCEN Enforcement (Secondary Oscillator clock source may be selected)
#pragma config LPT1OSC = OFF    // Low-Power Timer1 Oscillator (High-power operation)
#pragma config FCMEN = ON       // Fail-Safe Clock Monitor (Enabled)
#pragma config IESO = ON        // Internal External Oscillator Switch Over Mode (Enabled)

// CONFIG2H
#pragma config WDTPS = 32768    // Watchdog Postscaler (1:32768)

// CONFIG3L
#pragma config DSWDTOSC = INTOSCREF// DSWDT Clock Select (DSWDT uses INTRC)
#pragma config RTCOSC = INTOSCREF// RTCC Clock Select (RTCC uses INTRC)
#pragma config DSBOREN = ON     // Deep Sleep BOR (Enabled)
#pragma config DSWDTEN = ON     // Deep Sleep Watchdog Timer (Enabled)
#pragma config DSWDTPS = 8192  // Deep Sleep Watchdog Postscaler (1:8,192 (8.5 seconds))

// CONFIG3H
#pragma config IOL1WAY = ON     // IOLOCK One-Way Set Enable bit (The IOLOCK bit (PPSCON<0>) can be set once)
#pragma config MSSP7B_EN = MSK7 // MSSP address masking (7 Bit address masking mode)

// CONFIG4L
#pragma config WPFP = PAGE_63   // Write/Erase Protect Page Start/End Location (Write Protect Program Flash Page 63)
#pragma config WPEND = PAGE_WPFP// Write/Erase Protect Region Select (valid when WPDIS = 0) (Page WPFP<5:0> through Configuration Words erase/write protected)
#pragma config WPCFG = OFF      // Write/Erase Protect Configuration Region (Configuration Words page not erase/write-protected)

// CONFIG4H
#pragma config WPDIS = OFF      // Write Protect Disable bit (WPFP<5:0>/WPEND region ignored)

// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.




void sleep_f()
{
    //INTCON  &= ~0xF8;           /* Disable all interrupt sources */
    //INTCON3 &= ~0x38;
    PIR2bits.OSCFIF = 1;
    //RCONbits.IPEN = 0;   
    // OSCCON        = 0b01110000;
     OSCCONbits.IDLEN = 0 ;  // 0 Sleep mode a 1 idle mod 
    //WDTCONbits.SWDTEN = 1;  /* Enable the regular Watch Dog Time out too */
    WDTCONbits.REGSLP = 0; 
    //DSCONLbits.DSBOR = 1;
    //DSCONHbits.RTCWDIS = 0;
    DSCONHbits.DSEN = 0; // We run deep slep
    Sleep();  
}
void main()
{
    TRISD6 = 0;
    TRISDbits.TRISD4 = 0;
    LATD6  = 1;
            int i;
    while (1){
    LATD4 = 0; 
    int i;
    for (i = 0;i < 10000; i++) asm("nop");
    LATD4 = 1;  // Blink led if everything is OK. 
    sleep_f();
    DSCONLbits.RELEASE = 0;
    WDTCONbits.DS = 0;
    for (i = 0;i < 30000; i++) asm("nop");
    }
}

你知道我的代码出了什么问题吗?我已经在上面堆了3天了。如果有任何帮助,我将不胜感激。

EN

回答 1

Stack Overflow用户

发布于 2017-05-04 01:35:43

我不确定您是否意识到DSWDT周期设置为8192,而正常的WDT设置为32768,这意味着根据数据表,触发需要8.5秒和2.25分钟。为了进行调试,我将其设置为几秒钟。当您确定它正在工作时,将WDT增加到所需的时间段。也许延迟环路太短而没有注意到任何闪烁?不带睡眠功能的led是否闪烁?此行不执行任何操作,因为此位是只读的。

代码语言:javascript
复制
WDTCONbits.DS = 0;

这一行

代码语言:javascript
复制
DSCONHbits.DSEN = 0; // We run deep slep

应该是

代码语言:javascript
复制
DSCONHbits.DSEN = 1; // We run deep sleep

数据表指出,1表示深度睡眠,0表示睡眠。当您的设备进入正常睡眠时,WDT在2.25分(定标器为32768)而不是DSWDT 8.5秒(DSWDT定标器为8192)触发。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43698896

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档