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

interrupt - external(pin b0)

 
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: Tue Sep 09, 2003 6:01 pm     Reply with quote

Here's an example of how you can use INT_EXT with a push-button
switch. I don't have time to integrate it into your Sleep program.
But hopefully it will give you some hints.

#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);

}
colin



Joined: 08 Sep 2003
Posts: 3

View user's profile Send private message

thanks
PostPosted: Tue Sep 09, 2003 6:10 pm     Reply with quote

PCM programmer,
thanks for your advice b4 taking off.

thanks again.
Hope your program helps.
sliders_alpha



Joined: 03 Mar 2008
Posts: 55

View user's profile Send private message

PostPosted: Sun Apr 19, 2009 11:57 am     Reply with quote

i was looking or that, thanks

Code:

#bit INTF_BIT = 0x0B.1


and doing that after each interrupt :

Code:
INTF_BIT = 0;


is still required those day (CCS 4.057)?
_________________
yup, i know, i don't speak english very well

CCS V4.057
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Apr 19, 2009 12:16 pm     Reply with quote

The compiler does not clear a peripheral interrupt flag when you call
the enable_interrupt() function. This applies to old versions of the
compiler and to new versions.

For example, these lines do not clear the INTF flag:
Quote:
enable_interrupts(INT_EXT);
enable_interrupts(GLOBAL);


The modern compiler now has a function to clear the flag,
so you can call it like this:
Quote:
clear_interrupt(INT_EXT);
enable_interrupts(INT_EXT);
enable_interrupts(GLOBAL);
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