Also with WDT enabled, it will wake the PIC from sleep when it times out, preventing any long "sleep". I don't see any WDT timer reset anywhere in the code...
Thanks sir
Iam done as below but for case 3 not run code not wakeup pic from sleep
using sw
/*
* File: led_sleep_pic12f675.c
* Author: Yogesh Shende
* Created on April 11, 2021, 11:46 AM
*/
// PIC12F675 Configuration Bit Settings
// 'C' source line config statements
// CONFIG
#pragma config FOSC = INTRCIO // Oscillator Selection bits (INTOSC oscillator: I/O function on GP4/OSC2/CLKOUT pin, I/O function on GP5/OSC1/CLKIN)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT enabled)
#pragma config PWRTE = OFF // Power-Up Timer Enable bit (PWRT enabled)
#pragma config MCLRE = OFF // GP3/MCLR pin function select (GP3/MCLR pin function is digital I/O, MCLR internally tied to VDD)
#pragma config BOREN = OFF // Brown-out Detect Enable bit (BOD enabled)
#pragma config CP = OFF // Code Protection bit (Program Memory code protection is disabled)
#pragma config CPD = OFF // Data Code Protection bit (Data memory code protection is disabled)
// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.
#include <xc.h>
#include <stdint.h>
#include<stdlib.h>
#define l1 GP0 // LED1
#define l2 GP1 // LED2
//#define sw GP2 // sw1
#define l3 GP4 // LED4
#define l4 GP5 // LED5
#define sw GP3 // switch 1
#define _XTAL_FREQ 4000000
unsigned char count=0;
volatile unsigned int flag=0,i;
void ledloop1(void);
void ledloop2(void);
void switchcase ();
void main(void)
{
ANSEL = 0x00; // Set ports as digital I/O, not analog input
ADCON0 = 0x00; // Shut off the A/D Converter
CMCON = 0x07; // Shut off the Comparator
VRCON = 0x00; // Shut off the Voltage Reference
TRISIO = 0b11001000; // GP3 input, rest all output
GPIO = 0x00; // Make all pins 0
WPU=0; //WEAK PULL-UP REGISTER 0
//INTCONbits.INTF=0; /* Clear INT0 interrupt flag */
//INTCONbits.INTE=0; /* Enable INTOIF interrupt */
INTCONbits.GIE=1; /* Enable global interrupt */
INTCONbits.GPIE=1;
IOC3=1; //INTERRUPT-ON-CHANGE GPIO REGISTER on GP3 pin
while(1)
{
if(sw==1)
{
__delay_ms(5);
while(sw==1)
{
if(flag<3)
{
flag=flag++;
}
}
}
switch (flag)
{
case 0:
{
// if (sw != 1&&flag==0) // 1st step if switch sw=0 or sw=1 led blink and sleep
// {
__delay_ms(10);
ledloop1();
__delay_ms(100);
SLEEP();
//}
}
break;
case 1:
{
// if (sw == 1&&flag==1) //2nd step if switch sw=0 or sw=1 led blink and sleep
// while (flag)
{__delay_ms(10);
ledloop1();
__delay_ms(40);
SLEEP();
// }
}
break;
case 2:
//if (sw == 1&&flag==2) //3rd step if sw pressed 2nd time the operation run continue until sw=0
//{
// __delay_ms(10);
while(sw)
{
l3=1; // Led 3 Continue on until we release sw=0;
for (count=0; count<10; count++)
{
ledloop2();
__delay_ms(50); // delay for flash
}
}
//}
break;
}
}
}
}
//void __interrupt() ISR()
//{
// while(GPIF)
// {
// if(flag<3)
// {
// flag=flag++;
// }
// flag=0;
// }
//GPIO=flag;
//}
//
void ledloop1(void)
{
for(i=0;i<10;i++)
{
l1=~l1;
__delay_ms(60);
}
}
void ledloop2(void)
{
while(1)
{
for(i=0;i<10;i++)
{
l2=~l3;
__delay_ms(60);
}
}
}