gpt4 book ai didi

c - Microchip PIC16F1829深度 sleep

转载 作者:行者123 更新时间:2023-12-04 10:31:55 25 4
gpt4 key购买 nike

我正在努力让 PIC16F1829 进入休眠模式。该装置消耗大约 18mA,而数据表在深度 sleep 模式下引用 20nA。谁能帮忙?

根据数据表,我必须执行以下操作“WDT、BOR、FVR 和 T1OSCdisabled, all Peripherals Inactive”,我认为这是完成的,如下所示?

    #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();


}

最佳答案

这可能是缺乏异常处理的结果。您启用了中断,但您没有捕获它们的功能。如果出于任何原因,中断标志将被设置,没有什么可以清除它并且你的 pic 将分支到中断 vector ,因为 GIE 已设置(即使在 sleep 中)。由于您没有指定中断函数,您可能(取决于您的编译器)最终进入未编程的内存区域全速执行任意指令。

尝试使用相同的代码:

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

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com