CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

to wake from sleep

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
nathan
Guest







Help with useing interrupt on portB to wake from sleep
PostPosted: Wed Aug 29, 2001 11:24 am     Reply with quote

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.

//////////////////////////////////////////////////
// Program: camera_rx.c
// Date: 08-04-2001
// Rev. 03
//////////////////////////////////////////////////
#case
#include "16f873.h"
#use Delay(clock=4000000)
#use fast_io(B)

#define BUZZER PIN_B5
#define MOTOR PIN_B4
#define N_SW PIN_B2
#define TM_SW PIN_B1

#INT_RB


/////////////////////////////////////////////////////////////
main()
{
disable_interrupts(GLOBAL);
//enable_interrupts(RB_CHANGE);
enable_interrupts(INT_RB);
enable_interrupts(GLOBAL);
//setup_counters(RTCC_INTERNAL, WDT_2304MS);
//ext_int_edge(H_TO_L);
//port_b_pullups(FALSE);

set_tris_b(0b11001110);

output_low(MOTOR);
output_low(BUZZER);

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

View user's profile Send private message

to wake from sleep
PostPosted: Thu Aug 30, 2001 2:45 pm     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2005 phpBB Group