Help with useing interrupt on portB to wake from sleep
Posted: Wed Aug 29, 2001 11:24 am
My program is very simple, I have two switch inputs (RB1 & RB2) tied high, switch takes it low, with two outputs to drive a motor (RB4) and buzzer (RB5). I am using a F873. I have a proto circuit made an now my client wants the device to go to sleep to conserve battery energy. So I would like to use the sleep() command and use the change_RB or INT_RB to create an interrupt to wake from sleep.
I would like to do this by tying RB1 to RB6 and tie RB2 to RB7. This would allow me to wake from sleep and go to the correct portion of the program (I believe). I am not sure how to set things up to do this. I am not sure how or what to use as the RB_isr() in my program and what other things I should have set up. I do disable the WDT when I program the part.
Here is the code that I am using now and I am not getting it to work correctly. Does anyone have any suggestion? Thank you for any help that you can give.
while(1)
{
//sleep();
delay_ms(25);
//restart_wdt();
if ((input(N_SW)==0) || (input(TM_SW)==0))
{
if (input(N_SW)==0)
{
output_high(MOTOR);
delay_ms(200);
output_low(MOTOR);
delay_ms(500);
restart_wdt();
delay_ms(500);
restart_wdt();
delay_ms(500);
restart_wdt();
delay_ms(500);
restart_wdt();
while(input(N_SW)==0)
{
delay_ms(500);
restart_wdt();
}
sleep();
}
if (input(TM_SW)==0)
{
delay_ms(1000);
restart_wdt();
if (input(TM_SW)==0)
{
output_high(BUZZER);
delay_ms(500);
output_low(BUZZER);
delay_ms(1000);
restart_wdt();
delay_ms(1000);
restart_wdt();
delay_ms(1000);
restart_wdt();
delay_ms(1000);
restart_wdt();
delay_ms(1000);
restart_wdt();
delay_ms(1000);
restart_wdt();
output_high(BUZZER);
delay_ms(1000);
restart_wdt();
output_low(BUZZER);
delay_ms(1000);
restart_wdt();
output_high(BUZZER);
delay_ms(1000);
output_low(BUZZER);
restart_wdt();
delay_ms(1000);
restart_wdt();
output_high(MOTOR);
delay_ms(200);
output_low(MOTOR);
delay_ms(1000);
restart_wdt();
delay_ms(1000);
restart_wdt();
while(input(TM_SW)==0)
{
delay_ms(500);
restart_wdt();
}
}
sleep();
}
delay_ms(100);
restart_wdt();
}
}
}
___________________________
This message was ported from CCS's old forum
Original Post ID: 89
Neutone
Joined: 08 Sep 2003 Posts: 839 Location: Houston
to wake from sleep
Posted: Thu Aug 30, 2001 2:45 pm
enable_interrupts(INT_EXT); // enable interupt on B0
ext_int_edge( H_TO_L ); // trigger on falling edge to wake up
sleep(); // Excecute sleep
#asm
BCF 11,1 // Clear B0 interupt
#endasm
Because there is no interupt routine the code picks up where it left off. Clear the interupt to you can put it to sleep. It will not sleep unless the interupt has been cleared.
___________________________
This message was ported from CCS's old forum
Original Post ID: 109
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum