That could work. You can move the sleep stuff to be after the loop. You drop out of the loop when neither button is pressed, then go to sleep.
Make sure you have the interrupts for wake-up set up on your two button GPIOs.
You should always (again) make sure that main() ends with an infinite loop. So after initialising sleep, loop forever.
well, can I implement that by a simple While(1) loop which the while(BIG_SW==1||SMALL_SW==1) and an if statement where the sleep instruction is placed?
and for the interrupts, I really don't know how to set up those

; but here I go so bear with me:
10.3 Interrupts During Sleep
Interrupts can be used to wake from Sleep. To wake
from Sleep, the peripheral must be able to operate
without the system clock. The interrupt source must
have the appropriate Interrupt Enable bit(s) set prior to
entering Sleep.
On waking from Sleep, if the GIE bit is also set, the
processor will branch to the interrupt vector. Otherwise,
the processor will continue executing instructions after
the SLEEP instruction. The instruction directly after the
SLEEP instruction will always be executed before
branching to the ISR. Refer to Section 11.0 “Power-
Saving Operation Modes” for more details.
so according to this, the peripheral used to wake up the CPU must be able to operate without the system clock, and here we will be using BIG/SMALL_SW as our interrupt source, the question is how many external interrupt pins do I have? here I found two different things in the datasheet, a External interrupt input and Interrupt-on-change input both can wake up the cpu from sleep...
so I looked up this IOC thingy and came up with this:
17.0 INTERRUPT-ON-CHANGE
An interrupt can be generated by detecting a signal that
has either a rising edge or a falling edge. Any individual
pin, or combination of pins, can be configured to
generate an interrupt. The interrupt-on-change module
has the following features:
• Interrupt-on-Change enable (Master Switch)
• Individual pin configuration
• Rising and falling edge detection
• Individual pin interrupt flags
Figure 17-1 is a block diagram of the IOC module.
so this looks more promising, so I have to set the ioc and IOCIE bit of the PIE0 registers for both RA4 and RA5 which is my BIG/SMALL_SW pins to falling edge trigger...
So this is what I came with, notice I did not include the idle setup yet:
int main(void)
{
OSCFRQ=0b010; // OSCFRQ(HFFRQ0-2) SET OSCILLATOR TO 4MHz
TRISAbits.TRISA0=0; // TRISA0(RA0) BIG LIGHT DRIVE, OUTPUT
TRISAbits.TRISA1=0; // TRISA1(RA1) SMALL LIGHT DRIVE, OUTPUT
TRISAbits.TRISA2=1; // TRISA2(RA2) ANALOG POT, INPUT
TRISAbits.TRISA4=1; // TRISA4(RA4) BIG LIGHT SWITCH, INPUT
TRISAbits.TRISA5=1; // TRISA5(RA5) SMALL LIGHT SWITCH, INPUT
ANSELAbits.ANSA2=1; // ANSELA2(ANSA2) ANALOG POT, INPUT ANALOG
CCP1PPSbits.CCP1PPS=0b00000; // BIG LIGHT DRIVER (PWM->RA4), OUTPUT
CCP2PPSbits.CCP2PPS=0b00001; // SMALL LIGHT DRIVER (PWM->RA5), OUTPUT
ADCON0bits.CHS=0b000010; // ANALOG CHANNEL SELECTION BITS (RA2)
ADCON1bits.ADCS=0b111; // ADC COVERSION CLOCK SELECTION BITS (ADCRC)
ADCON0bits.ADON=1; // ANALOG CHANNEL SELECTION BITS (ADCON HIGH)
ADCON1bits.ADPREF=0b00; //ADC POSITIVE VOLTAGE REFRENCE CONFIGRATION bits (VREF+ IS VDD)
ADCON1bits.ADFM=1; // ADC RESULT FORMAT SELECTION BITS (RIGHT JUSTIFIED)
BIG_SW=PORTAbits.RA4; //READ RA4 AND ASSIGN IT TO BIG_SW
SMALL_SW=PORTAbits.RA5; //READ RA5 AND ASSIGN IT TO SMALL_SW
PIE0bits.IOCIE=1;//INTERUPT-ON-CHANGE ENABLE BIT IS SET
IOCANbits.IOCAN4=1;//INTERUPT-ON-CHANGE PORTA (RA4) NEGATIVE EDGE TRIGGERED
IOCANbits.IOCAN5=1;//INTERUPT-ON-CHANGE PORTA (RA5) NEGATIVE EDGE TRIGGERED
while(1)
{
while(BIG_SW==1||SMALL_SW==1)
{
PMD1bits.TMR2MD=0b0; // TIMER2 MOUDLE ENABLED
T2CONbits.CKPS=0b000; //TIMER2 PRESCALER SET TO 1:1
T2CONbits.OUTPS=0b0000; //TIMER2 POST-SCALER SET TO 1:1
T2PRbits.T2PR=0b01100011; // PR2 REGESTER SET TO 99
T2CLKCONbits.CS=0b0011; // TIMER2 CLOCK SOURCE SELECT BIT (HFINTOSC)
CCP1CONbits.CCP1FMT=1; //CCPW PULSE WIDTH Alignment bit (RIGHT JUSTIFIED)
CCP1CONbits.CCP1MODE=0b1111; // MODE IS SET TO PWM
CCP2CONbits.CCP2FMT=1; //CCPW PULSE WIDTH Alignment bit (RIGHT JUSTIFIED)
CCP2CONbits.CCP2MODE=0b1111; // MODE IS SET TO PWM
if(BIG_SW==1)
{
ADC_RESULT();
CCPR1=RESULT;
PIR4bits.TMR2IF=0b0;
T2CONbits.T2ON=0b1;
}
if(SMALL_SW==1)
{
ADC_RESULT();
CCPR2=RESULT;
PIR4bits.TMR2IF=0b0;
T2CONbits.T2ON=0b1;
}
}
if (BIG_SW==0&&SMALL_SW==0)
{
SLEEP;
}
}
}
the sleep thou gave me an error:
main.c:130:13: error: use of undeclared identifier 'SLEEP'