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

Interrupt handling in general

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



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Oct 08, 2003 12:26 pm     Reply with quote

And the references I have found in the form, like http://www.pic-c.com/forum/general/posts/2138.html do not exist. I'm not impressed.
------------------------------------------------------------------------------
That's a bad link because all the posts from the previous CCS forum
were appended to this new forum, but the links were not updated to
point to the new forum. So here's a repost of the INT_EXT example.

If you have a specific design problem, then tell us what you're trying
to do, and we'll help you to solve it.


Code:
#include "16F877.h"
#fuses HS, NOWDT, NOPROTECT, PUT, BROWNOUT, NOLVP 
#use Delay(Clock=8000000)                   
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7) 
#zero_ram     

//-------------------------------
// GLOBALS

char got_interrupt;
char interrupt_count;

#bit INTF_BIT = 0x0B.1

//-----------------------------
// FUNCTION PROTOTYPES

#int_ext
void int_ext_isr(void);


//=============================
void main(void)
{

// Make pin B0 into an input.
output_float(PIN_B0);

// Enable pullups on all port B pins.
port_b_pullups(TRUE);

// Wait for them to pull up.
delay_us(10);

// Initialize the variables used by the interrupt routine,
// before enabling interrupts.
interrupt_count = 0;
got_interrupt = FALSE;

// Since we have port B pullups enabled, the normal state
// of Pin B0 is a high level.  Let's set up the external
// interrupt to occur whenever we get a change from
// a high to a low level.
// We will connect a Normally-open push-button switch to Pin B0.
// The "common" pin of the switch goes to Ground.
// When we press the button, Pin B0 will go to logic low level.
ext_int_edge(H_TO_L);


// Make sure the external interrupt flag bit is cleared
// before enabling external interrupts.
INTF_BIT = 0; 

enable_interrupts(INT_EXT);
enable_interrupts(GLOBAL); 


// Wait in this loop.  Check the got_interrupt flag to see
// if an interrupt occurred.  If so, display the count.
// Then clear the flag, wait 50 ms to avoid any "bounce"
// (multiple interrupts) when we press the pushbutton switch,
// which puts Ground on pin B0.  Then re-enable interrupts.

while(1)
{

if(got_interrupt == TRUE)
  {
   printf("%d\n\r", interrupt_count);

   // Clear the global flag which was set in the interrupt routine.
   got_interrupt = FALSE;

   // Wait for debounce period.  This allows time for the switch contacts
   // to quit bouncing.
   delay_ms(50);   

   // Clear any interrupt which might have occurred during the debounce period.
   INTF_BIT = 0;   
   
   // Then re-enable interrupts.
   enable_interrupts(INT_EXT);
  }

}


}
//========================

#int_ext
void int_ext_isr(void)
{

got_interrupt = TRUE;
interrupt_count++;


disable_interrupts(INT_EXT);

}
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