Reply by Anthony Fremont May 2, 20042004-05-02
"Devyn" <devyntt@yahoo.com> wrote

> In the ISR, the code is > > if(RB4==1) > { > GIE=1; > RBIF=0; > } > > Maybe the device is resetting. Even if it is, shouldnt it go back to > sleep, when it encounters the SLEEP instrn.?
Did you read Robert Scott's suggestion? How about section 5.2 of the datasheet? To end the mismatch condition, you have to read the whole port, otherwise it wake right back up due to the previous change. One more thing: enabling GIE in the ISR is likely to cause you major problems unless your ISR is reentrant, especially since the RBIF flag is still set when you enable GIE. RETFIE is the way to set the GIE bit.
Reply by Devyn May 2, 20042004-05-02
valemike@yahoo.com (Mike V.) wrote in message news:<8188616d.0405011919.156614d1@posting.google.com>...
> Are you sure that your PIC is not resetting? It looks like if you have > your watchdog enabled, you don't refresh it in that loop. Then you'll > see what looks like a blink, but you're actually resetting each time.
I have disabled WDT in the configuration
> And why do you need to go to sleep? is it a battery powered > application? It looks like you'll be burning some cpu cycles, and thus > battery life, in your software delay loop. You might want to set up > for a timer interrupt and wake up after a timer interrupt to update > your LED. (THis might not work, since i haven't done PIC sleeps for a > few years.
Yes, my app. is battery powered. Actually, its a lot more complicated than the LED blink. That was just a test code i'd written to present the problem. In reallity, on wake up fro sleep, the app updates a count, does some ADC stuff and some port stuff. I'm not enclosing details, for even the simple LED doesnt blink.. In the ISR, the code is if(RB4==1) { GIE=1; RBIF=0; } Maybe the device is resetting. Even if it is, shouldnt it go back to sleep, when it encounters the SLEEP instrn.? Devyn
Reply by Mike V. May 2, 20042004-05-02
Are you sure that your PIC is not resetting? It looks like if you have
your watchdog enabled, you don't refresh it in that loop. Then you'll
see what looks like a blink, but you're actually resetting each time.

And why do you need to go to sleep? is it a battery powered
application? It looks like you'll be burning some cpu cycles, and thus
battery life, in your software delay loop. You might want to set up
for a timer interrupt and wake up after a timer interrupt to update
your LED. (THis might not work, since i haven't done PIC sleeps for a
few years.



devyntt@yahoo.com (Devyn) wrote in message news:<e2769bfd.0405011355.3a8cfbd5@posting.google.com>...
> Hi All! > > I have a PIC16f877a. I want to work with the device mainly in sleep, > wake on RB change, do some stuff (say led blink) and go back to sleep. > > This code works fine if i put the blink code in the ISR. How do i use > this code in the main program in C? I tried :- > main() > { > // initialization of interrupts etc... > > s1 :asm("SLEEP"); > asm("NOP"); > RE0=0x1; > delay(); a fn. for 1s delay > RE0=0; > goto s1; > } > > The code works one the first run. Then the device doesnt go back to > sleep i.e it keeps blinkin LED after 1st interrupt (it should blink > just once right?) > > Devyn
Reply by Robert Scott May 1, 20042004-05-01
On 1 May 2004 14:55:34 -0700, devyntt@yahoo.com (Devyn) wrote:

>Hi All! > > I have a PIC16f877a. I want to work with the device mainly in sleep, >wake on RB change, do some stuff (say led blink) and go back to sleep. > >This code works fine if i put the blink code in the ISR. How do i use >this code in the main program in C? I tried :- >main() >{ >// initialization of interrupts etc... > >s1 :asm("SLEEP"); >asm("NOP"); >RE0=0x1; >delay(); a fn. for 1s delay >RE0=0; >goto s1; >} > >The code works one the first run. Then the device doesnt go back to >sleep i.e it keeps blinkin LED after 1st interrupt (it should blink >just once right?)
I think you need to cancel the RB change interrupt by reading PORT B in response to the interrupt. -Robert Scott Ypsilanti, Michigan (Reply through this forum, not by direct e-mail to me, as automatic reply address is fake.)
Reply by Devyn May 1, 20042004-05-01
Hi All!

  I have a PIC16f877a. I want to work with the device mainly in sleep,
wake on RB change, do some stuff (say led blink) and go back to sleep.

This code works fine if i put the blink code in the ISR. How do i use
this code in the main program in C? I tried :-
main()
{
// initialization of interrupts etc...

s1 :asm("SLEEP");
asm("NOP");
RE0=0x1;
delay(); a fn. for 1s delay
RE0=0;
goto s1;
}

The code works one the first run. Then the device doesnt go back to
sleep i.e it keeps blinkin LED after 1st interrupt (it should blink
just once right?)

Devyn