Swys
Junior Member level 1
I really hope someone can help me on this. I have to count pulses from an external source. For some reason, only the first pulse is counted. Can someone please have a look at my code to see what I am doing wrong?
I am using the MPLAB C18 compiler with a PIC18F13K50
Here are my interrupt functions:
This is how my PIC is set up:
In my main function, I am just checking the flow_int flag and outputting some text on the UART when the flag is set. Please help, since I don't have much time to solve this?
P.S. I've tried it with PORTCbits.RC0 = 1 and PORTCbits.RC0 = 0
I am using the MPLAB C18 compiler with a PIC18F13K50
Here are my interrupt functions:
Code:
#pragma code high_vector=0x08
void interrupt_at_high_vector(void)
{
_asm
GOTO high_isr
_endasm
}
#pragma code
#pragma interrupt high_isr
void high_isr(void)
{
if ((INTCONbits.INT0IF == 1) & (INTCONbits.INT0IE == 1))
{
//Pulse received
INTCONbits.INT0IF = 0;
flow_int = 1; //Flag indicating when interrupt occurred
//PORTCbits.RC0 = 1;
}
}
This is how my PIC is set up:
Code:
void SetupPIC(void)
{
//Setup ports
TRISA = 0x00;
TRISB = 0x00;
TRISC = 0x00;
PORTA = 0;
PORTB = 0;
PORTC = 0;
//Disable all analog inputs
ANSEL = 0x00;
ANSELH = 0x00;
//Setup USART
TRISBbits.TRISB5 = 1;
TRISBbits.TRISB7 = 1;
//SetupUART();
OpenUSART( USART_TX_INT_OFF &
USART_RX_INT_ON &
USART_ASYNCH_MODE &
USART_EIGHT_BIT &
USART_CONT_RX &
USART_BRGH_HIGH,
129);
PIE1bits.RCIE = 1; //Enable USART receive interrupt
PIR1bits.RCIF = 0; //Clear USART receive interrupt flag
//Setup FRAM
init_FRAM();
//Setup ADC
init_ADC();
TRISCbits.TRISC6 = 0;
//Setup Timers
//Timer0
T0CON = 0b00000111; //Timer stopped;16-bit timer;
//Internal instruction cycle clock;
//Timer0 prescaler assigned;
//1:256 prescale value
INTCONbits.TMR0IE = 1; //Enable Timer0 interrupts
INTCONbits.TMR0IF = 0; //Clear Timer- interrupt flag
//Setup external interrupts INT0 and INT1
INTCONbits.INT0IF = 0; //Clear the interrupt flag
INTCONbits.INT0IE = 1; //Enable external interrupt INT0
INTCON2bits.INTEDG0 = 0;//Interrupt on the falling edge
PORTCbits.RC0 = 1; //Pull HIGH to create falling edge
//on contact
INTCON3bits.INT1IE = 1; //Enable external interrupt INT1
INTCON2bits.INTEDG1 = 0;//Interrupt on the falling edge
INTCON3bits.INT1IF = 0; //Clear the interrupt flag
PORTCbits.RC1 = 1;
INTCONbits.PEIE = 1;
INTCONbits.GIE = 1;
}
P.S. I've tried it with PORTCbits.RC0 = 1 and PORTCbits.RC0 = 0