![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
weg22
Joined: 08 Jul 2005 Posts: 91
|
external interrupts (trouble with CCP1) |
Posted: Thu Aug 11, 2005 12:34 pm |
|
|
If I have pin B0 (my ccp pin) grounded, can someone please tell me why A2 is going high?
Thanks
Code: |
#include <16F87.H>
#include <stdlib.h>
#include <math.h>
#define A2 PIN_A2
#define B0 PIN_B0
#define B1 PIN_B1
#define B2 PIN_B2
#fuses HS,NOWDT,NOPROTECT, PUT
#use delay(clock=4000000)
long rise, fall, pulseLength;
#int_ccp1
void isr()
{
pulseLength=0;
set_timer1(0);
while(input(B0));
pulseLength = get_timer1();
}
main()
{
delay_ms(1500);
while(1)
{
setup_ccp1(CCP_CAPTURE_RE); // Configure CCP1 to capture rise
setup_timer_1(T1_INTERNAL); // Start timer 1
enable_interrupts(INT_CCP1); // Setup interrupt on rising edge
enable_interrupts(GLOBAL);
if(pulseLength>1500)
{
output_high(A2);
delay_ms(1000);
output_low(A2);
}
else
output_low(A2);
}
} // end of main
|
|
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Aug 11, 2005 2:09 pm |
|
|
The data sheet says right here,
Quote: | 9.1.3 SOFTWARE INTERRUPT
When the Capture mode is changed, a false capture
interrupt may be generated. The user should keep bit
CCP1IE (PIE1<2>) clear to avoid false interrupts and
should clear the flag bit, CCP1IF, following any such
change in operating mode. |
CCS has the clear_interrupt() function, specifically for this purpose.
You need to clear the INT_CCP1 interrupt before you enable
global interrupts.
Also, anytime a module behaves strangely, it's almost certainly
because of some quirky behavior that will be explained in the
data sheet section on that module. You should read it. |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|