dima82
Newbie level 1
Hello,
I'm trying to use WDT for power saving modes with 18f4550 micro-controller, but it seems only to go to sleep and it won't wake up.
The code is bellow. Am I doing something wrong?
#include <P18f4550.h>
int COUNTER=0xFF;
#pragma config DEBUG = ON
#pragma config ICPRT = OFF
#define NOP
#define DELAY
#define WDT
//#pragma config CONFIG2Hbits.WDTEN = ON
#pragma config WDTPS = 32768
void main(void)
{
TRISC=0;
TRISD=0;
TRISAbits.TRISA0=0;
ADCON0 = 0x01;
ADCON1 = 0x00;
ADCON2 = 0x1D;
while(1)
{
ADCON0bits.GO = 1;
while (ADCON0bits.DONE == 1);
PORTC=ADRESL;
PORTD=0xFF;
FSR0L=0x00;
LOOP: EECON1 = 0x06; //WRITE TO MEMORY
INDF0 = ADRESH;
EEDATA = INDF0;
// EEDATA = 0xFF;
EECON1bits.WREN = 1;
INTCONbits.GIE = 0;
EECON2 = 0x55;
EECON2 = 0xAA;
EECON1bits.WR = 1;
INTCONbits.GIE = 1;
EECON1bits.WREN = 0;
DELAY(250);
EEADR = FSR0L;
NOP;
NOP;
FSR0L++;
COUNTER--;
// CONFIG2H = 0x1F;
WDTCONbits.SWDTEN = 1; //enable watchdog timer
Sleep();
WDTCONbits.SWDTEN = 0; //turn off watchdog timer
if (COUNTER!=0x00)
goto LOOP;
}
}
I'm trying to use WDT for power saving modes with 18f4550 micro-controller, but it seems only to go to sleep and it won't wake up.
The code is bellow. Am I doing something wrong?
#include <P18f4550.h>
int COUNTER=0xFF;
#pragma config DEBUG = ON
#pragma config ICPRT = OFF
#define NOP
#define DELAY
#define WDT
//#pragma config CONFIG2Hbits.WDTEN = ON
#pragma config WDTPS = 32768
void main(void)
{
TRISC=0;
TRISD=0;
TRISAbits.TRISA0=0;
ADCON0 = 0x01;
ADCON1 = 0x00;
ADCON2 = 0x1D;
while(1)
{
ADCON0bits.GO = 1;
while (ADCON0bits.DONE == 1);
PORTC=ADRESL;
PORTD=0xFF;
FSR0L=0x00;
LOOP: EECON1 = 0x06; //WRITE TO MEMORY
INDF0 = ADRESH;
EEDATA = INDF0;
// EEDATA = 0xFF;
EECON1bits.WREN = 1;
INTCONbits.GIE = 0;
EECON2 = 0x55;
EECON2 = 0xAA;
EECON1bits.WR = 1;
INTCONbits.GIE = 1;
EECON1bits.WREN = 0;
DELAY(250);
EEADR = FSR0L;
NOP;
NOP;
FSR0L++;
COUNTER--;
// CONFIG2H = 0x1F;
WDTCONbits.SWDTEN = 1; //enable watchdog timer
Sleep();
WDTCONbits.SWDTEN = 0; //turn off watchdog timer
if (COUNTER!=0x00)
goto LOOP;
}
}