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 CCS Technical Support

Using Hardware Interrupt (INT0)

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



Joined: 24 Feb 2004
Posts: 3

View user's profile Send private message ICQ Number

Using Hardware Interrupt (INT0)
PostPosted: Mon Mar 08, 2004 9:41 am     Reply with quote

Hi All

I have written a test program on INT0 but I am not able to test it out on the hardware yet due to unavalibility. Can someone be kind enough to tell me whether the code will works.

A push button is connected to Pin B0 which when pushed will caused the chip to go into SLEEP mode. A second push on the pushbutton will bring the chip active and reset via reset_cpu().


Code:

#include <18F458.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)

// global flag to send processor into sleep mode
short sleep_mode;

// external interrupt when button pushed and released
#INT_EXT
void ext_isr()
{
   if(button_pressed_once)                // if button action and was not
                                                      // pressed
   {
      button_pressed_once=FALSE;    //to activate the next button pressed
                                                     // which is to reset the thing
      sleep();
   }
   else                         
   {
      button_pressed_once=TRUE;   // the button is now up
      reset_cpu();
   }
}

void main()
{

   ext_int_edge(H_TO_L);      // init interrupt triggering for button press
   enable_interrupts(INT_EXT);// turn on interrupts
   enable_interrupts(GLOBAL);

   static short button_pressed_once=TRUE;
}



Thanks
jds-pic



Joined: 17 Sep 2003
Posts: 205

View user's profile Send private message

Re: Using Hardware Interrupt (INT0)
PostPosted: Mon Mar 08, 2004 9:09 pm     Reply with quote

ericzuki wrote:


Code:

#INT_EXT
void ext_isr()
{
   if(button_pressed_once)                // if button action and was not
                                                      // pressed
   {
      button_pressed_once=FALSE;    //to activate the next button pressed
                                                     // which is to reset the thing
      sleep();
   }
   else                         
   {
      button_pressed_once=TRUE;   // the button is now up
      reset_cpu();
   }
}

void main()
{

   ext_int_edge(H_TO_L);      // init interrupt triggering for button press
   enable_interrupts(INT_EXT);// turn on interrupts
   enable_interrupts(GLOBAL);

   static short button_pressed_once=TRUE;
}





it may just be me but i don't like the idea of going to sleep inside an interrupt handler function. i believe that this is asking for debugging troubles and it's just not good programming practice. why not just set a flag in #int_ext and test it in main()? keep your inerrupt handlers simple.

jds-pic
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