PIC16F88 sleep

Status
Not open for further replies.

bananasiong

New Member
Hi all,
I'm using PIC16F88 to drive a LCD text module. When no button is pressed within 30 seconds, the device will sleep and the LCD will be turned off. I use RB0/INT external interrupt to wake the device up and re-initialize the LCD.

I have no problem with the LCD and the counter part, I use timer 2 for counting the time.

This is the routine when no button is pressed in 30 seconds:

Code:
	bcf		INTCON,	GIE   ;disable global interrupt
	bsf		INTCON,	INTE
	call	LCD_clr
	bcf		PORTB,	4			;turn off LCD
	sleep
	nop
	bcf		INTCON,	INTE
	bsf		PORTB,	4			;turn on LCD
	call	Delay100
	call	LCD_Ini
	bsf		INTCON,	GIE   ;enable global interrupt

When the global interrupt is disabled, the device should wakeup from where it slept and continue executing the next instruction; when the global interrupt is enabled, the device should wakeup and go to the interrupt vector.

Before going to sleep, I've disabled the global interrupt, but the device sleep and wakeup immediately itself.
If I enable the global interrupt before the sleep instruction, everything works fine, wakeup when RB0 is pressed.

I use internal pullup and rise transition at RB0 for the interrupt.
 
Last edited:
Before entering this routine, RB0 is used as input pin. In this routine, RB0 interrupt is enabled.
If RB0 is pressed before this routine, the device will sleep and wake up itself, when GIE is disabled, but everything runs fine when GIE is enabled.

Any idea?

Thanks
 
Have you tried clearing INT0IF before going to sleep? In fact, clear all interrupt flags prior to sleep.

Mike.
 
Last edited:
Forgotten
Maybe I have. Because I've tried a lot of method. But one thing I'm sure is, after the PIC is woke up, INTF is cleared before the GIE is set back (after LCD initialize).

*EDIT: Just tried clearing INTF before and after the sleep instruction, it works now :| Guess I didn't tried that previously, but if I clear the INTF ONLY after the sleep, it wouldn't work if RB0 is pressed before the sleep routine, it will only sleep and wakeup itself.
 
Last edited:
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…