Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Wake-up from sleep using INT pin

Status
Not open for further replies.

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.

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:
I got it to work. Just needed to clear the ANSELB bit corresponding to RB0 pin, so I just added

ANSELB=0b11111110 (note that ANSELB=0b11111111 on Power-On Reset)

before TRISB=0b01111111 instruction

With the corresponding ANSELB bit set, digital buffer was disabled, so pin was configured as analog input, with its digital input function disabled.


Thank you,
 
Last edited:
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top