WindWalker
New Member
Hello,
I'm trying this with a PIC16F722. I wrote the code so the interrupt would happen at falling edge, I enabled pull-up resistors at PORTB, so I think interrupt should happen when shorting RB0 (INT) pin to Ground.
The PIC should do the following: light a LED for 5 seconds (RB7 as output), wait 1 second, go to sleep, wait for interrupt, light a LED for 5 seconds, ...
What happens: the LED is lit for 5s, MCU waits 1s, MCU goes to sleep (I can tell that because current drawn goes down to 20 uA @ 5 V) but doesn't wake up.
Thanks in advance,
I'm trying this with a PIC16F722. I wrote the code so the interrupt would happen at falling edge, I enabled pull-up resistors at PORTB, so I think interrupt should happen when shorting RB0 (INT) pin to Ground.
The PIC should do the following: light a LED for 5 seconds (RB7 as output), wait 1 second, go to sleep, wait for interrupt, light a LED for 5 seconds, ...
What happens: the LED is lit for 5s, MCU waits 1s, MCU goes to sleep (I can tell that because current drawn goes down to 20 uA @ 5 V) but doesn't wake up.
Code:
#define XTAL_FREQ 16MHZ /* MCU frequency in MHz */
#include <pic.h>
#include "delay.h"
__CONFIG(BOREN & MCLREN & PWRTEN & BORV25 & WDTDIS & INTIO & PLLEN & UNPROTECT);
__CONFIG(VCAPRA5);
void System_init(void){
if (XTAL_FREQ == 16MHZ)
OSCCON=0b00110000;
else if (XTAL_FREQ == 8MHZ)
OSCCON=0b00100000;
else if (XTAL_FREQ == 4MHZ)
OSCCON=0b00010000;
else if (XTAL_FREQ == 2MHZ)
OSCCON=0b00000000;
[COLOR="Red"]ANSELB=0b11111110;[/COLOR] //code correction
TRISB =0b01111111;
RBPU =0;
INTE=1; //enable interrupt at INT pin - RB0
INTF=0;
PEIE=1;
GIE=1;
INTEDG=0; //interrupt on falling edge
}
static void interrupt isr(void){
if(INTF && INTE){
INTF=0;
INTE=1;
}
}
void main(void){
System_init();
while(1){ //looping
RB7=1;
DelayMs(5000);
RB7=0;
DelayMs(1000);
SLEEP();
}
}
Thanks in advance,
Last edited: