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 from sleep using INT0

Status
Not open for further replies.

tubos

New Member
The following piece of code should make the pic sleep
and keep on sleep until INT0 edge is detected.
The problem is it immediately wakes up again
from itself after going to sleep.

PIC18F26K22 & MPLAB v8.84 & C18 v3.41


Code:
while(1)
     {
		for(ucb=0;ucb<100;ucb++)  // Just some led displaying stuff
		 {						
			uca +=1; uca &=0x01F;
			BrtData[0]=uca;
			Delay10KTCYx(10 );
		 }
		INTCONbits.GIE=0;		// Should be off just wake from sleep
		LATB=0x00;				// Turn off Leds
		LATA|=0x0F;				// common Anodes off
		Delay10KTCYx(250 );		// Just to check
		TRISB = 0x01;			// Bit 0 input for INT0
		INTCONbits.INT0IF = 0;  // Must be off prior to enable INT0
		INTCON2bits.INTEDG0=1;  // Enable Rising edge
		INTCONbits.INT0IE=1;	// Enable INT0 interrupt
		Sleep();
		Nop();
		TRISB=0;				// Back to normal
		INTCONbits.INT0IE=0;	// Disable INT0 interrupt
		INTCONbits.GIE=1;		// Back on

	 }
 
Last edited:
One possibility: you have a mismatch condition on RB0. Read RB0 before clearing the INT0F flag (INTCONbits.INT0IF = 0).
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top