PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Oct 08, 2003 12:26 pm |
|
|
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);
} |
|
|