我正在努力使PIC16F1829进入睡眠模式。当数据手册在深度睡眠模式下的报价为20nA时,该单元消耗的电流约为18mA。有人可以帮忙吗?

根据数据表,我必须执行以下“ WDT,BOR,FVR和T1OSC
禁用,所有外围设备都未激活”,我认为如下所示?

    #include <pic16Lf1829.h>
    #include <plib/adc.h>
    #include <plib/pconfig.h>
    #include <plib/usart.h>


    // Use project enums instead of #define for ON and OFF.

    // CONFIG1
    #pragma config FOSC = ECL    // Oscillator Selection (INTOSC oscillator: I/O function on CLKIN pin)
    #pragma config WDTE = OFF       // Watchdog Timer Enable (WDT disabled)
    #pragma config PWRTE = OFF      // Power-up Timer Enable (PWRT disabled)
    #pragma config MCLRE = ON       // MCLR Pin Function Select (MCLR/VPP pin function is MCLR)
    #pragma config CP = OFF         // Flash Program Memory Code Protection (Program memory code protection is disabled)
    #pragma config CPD = OFF        // Data Memory Code Protection (Data memory code protection is disabled)
    #pragma config BOREN = OFF      // Brown-out Reset Enable (Brown-out Reset disabled)
    #pragma config CLKOUTEN = OFF   // Clock Out Enable (CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin)
    #pragma config IESO = ON        // Internal/External Switchover (Internal/External Switchover mode is enabled)
    #pragma config FCMEN = ON       // Fail-Safe Clock Monitor Enable (Fail-Safe Clock Monitor is enabled)

    // CONFIG2
    #pragma config WRT = OFF        // Flash Memory Self-Write Protection (Write protection off)
    #pragma config PLLEN = OFF      // PLL Enable (4x PLL disabled)
    #pragma config STVREN = ON      // Stack Overflow/Underflow Reset Enable (Stack Overflow or Underflow will cause a Reset)
    #pragma config BORV = LO        // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (Vbor), low trip point selected.)
    #pragma config LVP = ON         // Low-Voltage Programming Enable (Low-voltage programming enabled)


int main(int argc, char** argv) {
/*******************OSCILATOR CONFIGURATION*************/
    OSCCON = 0b01101000; // OSCILATOR CONTROL REGISTER 1MHz
    BORCON = 0x00;
    WDTCON    = 0x00; // Enable watchdog timer
/*******************************************************************************/


/**********************PORT A,B,C SETUP*************************************/

    ANSELB  =   0b00000000; /* Enable Digital input = 0 or Analogue = 1*/
    WPUB     =  0b00000000; /* Enable PULL UP 1 = yes 0 - NO*/
    TRISB   =   0b00000000; /* Tri-state PIN*/
    PORTB   =   0b00000000; /* Set PORTB Logic */

    WPUC =      0b00000000;
    ANSELC  =   0b00000000; /* Enable Digital input = 0 or Analogue = 1*/
    TRISC   =   0b00000000; /* Tri-state PIN*/
    PORTC =     0b00000000; /* Set PORTB Logic */

    WPUA =      0b00000000;
    ANSELA  =   0b00000000; /* Enable Digital input = 0 or Analogue = 1*/
    TRISA   =   0b00000000; /* Tri-state PIN*/
    PORTA   =   0b00000000; /* Set PORTB Logic */


    IOCBP   = 0b00100000;  /* INTERRUPT-ON-CHANGE PORTB POSITIVE EDGE REGISTER*/
    IOCBN   = 0b00000000;  /* INTERRUPT-ON-CHANGE PORTB NEGATIVE EDGE REGISTER*/
    INTCON  = 0b01011000;  /* Enable int on PIN Change*/
 /*******************************************************************************/

    bit_set(INTCON,7); /*ENABLE GLOBAL INTERUPTS*/

    ADCON0 = 0x00;
    ADCON1 = 0x00;

    T1CON  = 0x00;
    T2CON  = 0x00;
    FVRCON = 0x00; //FIXED VOLTAGE REFERENCE CONTROL REGISTER
    CM1CON0 = 0x00;
    CM1CON1 = 0x00;
    CM2CON1 = 0x00;
    CM2CON0 = 0x00;
    PWM1CON = 0x00;
    PWM2CON = 0x00;
    DACCON0 = 0X00;
    DACCON1 = 0X00;
    T1CON =   0X00;


    /********** MAIN LOOP START*******************/
        for(;;) {

    SLEEP();


           }

最佳答案

这可能是缺少异常处理的结果。您启用了中断,但是没有捕获中断的功能。如果出于某种原因将设置一个中断标志,则没有任何要清除的标志,并且由于设置了GIE(即使处于睡眠状态),您的图片也会跳转到中断向量。由于未指定中断功能,因此(取决于您的编译器)您可能会最终进入未编程的存储区,并以全速执行任意指令。

尝试使用相同的代码:

---  INTCON  = 0b01011000;  /* Enable int on PIN Change*/
+++  INTCON  = 0b00000000;  /* Disable all int */

关于c - Microchip PIC16F1829深度 sleep ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24258991/

10-12 15:04