Hello again. I'm doing a timer interrupt example using the PIC. Right now I have it configured to turn on and off the LED every 500ms. I'm using the PIC18F2420 on a 20Mhz crystal connected to 22pf capacitors. However, it seems like it's either not activating the interrupt or its taking a long time to do so. Here's the code
Rich (BB code):
//===============================================================================================
// Includes, Defines, and Global Variables
//===============================================================================================
/* Includes */
#include <p18F2420.h>
#include <delays.h>
#include <portb.h>
#include <usart.h>
#include <stdio.h>
#include <stdlib.h>
#include <timers.h>
/* PIC Configuratings */
#pragma config OSC = HS
#pragma config WDT = OFF
#pragma config PBADEN = OFF
#pragma config LVP = OFF
#pragma config PWRT = OFF
#pragma config DEBUG= ON
#pragma config BOREN = OFF
int counter=0;
//===============================================================================================
//
//===============================================================================================
//===============================================================================================
// Function Prototypes
//===============================================================================================
void PIC_CONFIG(void);
//===============================================================================================
//
//===============================================================================================
//===============================================================================================
// Interrupt Handler
//===============================================================================================
#pragma interrupt ISR
void ISR (void) // Main Interrupt handler
{
if(INTCONbits.TMR0IF==1)
{
INTCONbits.TMR0IF=0;
PORTCbits.RC4=~(PORTCbits.RC4);
WriteTimer0(0xD9DA);
}
}
#pragma code InterruptVectorHigh = 0x08 // This function simply jumps to the ISR code shown above.
void InterruptVectorHigh (void)
{
_asm
goto ISR //jump to interrupt routine
_endasm
}
#pragma code
//===============================================================================================
//
//===============================================================================================
//===============================================================================================
// Main Loop
//===============================================================================================
void main(void)
{
PIC_CONFIG();
while(1);
}
//===============================================================================================
//
//===============================================================================================
//===============================================================================================
// PIC Configuration
//===============================================================================================
void PIC_CONFIG(void)
{
/* Setting PIC to use interrupts */
RCONbits.IPEN=1; // Enable interrupt priority
// Setup Timer 0 for interrupts
INTCONbits.TMR0IE=1;
INTCONbits.TMR0IF=0;
INTCON2bits.TMR0IP=1;
OpenTimer0(TIMER_INT_ON & T0_16BIT & T0_SOURCE_EXT & T0_EDGE_FALL & T0_PS_1_256);
WriteTimer0(0xD9DA);
INTCONbits.GIE=1; // Enable global interrupts
TRISC=0x00; // Configure all PORTC pins as outputs
PORTC=0x00; // Turns off all PORTC ports
}