mnyama
Newbie level 4
- Joined
- Feb 23, 2013
- Messages
- 5
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,333
hellow folks out there,sory for my bad english, i'm hving problem with ccp interrupt flag bit, my aim was just to demonstrate the ccp capture interrupt service routine by complimenting the leds being connected at portd, once the flag bit is set, i am using two intterruptys in mikroc, one for timer1 overflow interrupt flag bit, and other for ccp capture flag bit, the interrupt for timer1 overflow works fine,since once the flag bit is set, the leds D1(PORTD.F0) toggles, but the other intterupt (CCp capture interrupt), seems to have problem, it seems like ccp flag bit is not working, could anybody having an idea, i will be very happy, here is the snippet code :--(, attached here is a snippet code + image of simulated circuit
Code:
unsigned char cnt=0;
unsigned char cpf=0;
void interrupt()
{
if(PIR1.CCP1IF==1)
{
cpf++;
PIR1.CCP1IF=0;
CCPR1H=0;
CCPR1L=0;
}
else if(PIR1.TMR1IF==1)
{
cnt++; //increment cnt
PIR1.TMR1IF=0; //clear flag bit
TMR1H=0;
TMR1L=0;
}
}
void main() { a
ANSELH =0; //all pins configured as digital
ANSEL=0;
C1ON_bit=0; //switch off all comparators
C2ON_bit=0;
PORTC.F2=1; //ccp1 pin configured as input
TRISD =0; //port c initialize as the output
INTCON = 0b11000000; // Enable interrupt (bits GIE and PEIE)
PIE1=0b00000101; //except for the TMR1IE&CCP1IE bits
//PIR1=0x00; //clear the IF bit to zero
T1CON=0b0000001; // timer ON, prescaler 1:4, not syschronized
CCP1CON=0b00000101; //capture everyrising edge
PORTD.F0=1;
PORTD.F2=1;
cnt = 0; // Reset variable cnt
cpf=0; //ccp variable
while(1){
if(cnt==10)
{
cnt=0; //clear cnt count
PORTD.F0=~PORTD.F0;
}
if(cpf==65)
{
cpf=0;
PORTD.F2=~PORTD.F2;
}
}
}