Hello,
I have been trying for days now to understand the interrupts but with no luck. I have been looking for sample code on the net but I didn't find anything useful. What seems to be working for others is not working for me. For example, I found this code:
I changed the header file for my microcontroller (18F4620) and tried to build the code but I got this error: section 'high_vector' can not fit the absolute section. Section 'high_vector' start=0x00000008, length=0x0000004a
I am not quite sure if I really understand what that means. So could you explain to me what I am doing wrong.
Could you provide some other links to any sample code about interrupts on timer?
I am using MPLAB IDE with C18
Thanks
I have been trying for days now to understand the interrupts but with no luck. I have been looking for sample code on the net but I didn't find anything useful. What seems to be working for others is not working for me. For example, I found this code:
Rich (BB code):
#include <p18f14k50.h>
//pragma codes
#pragma code high_vector=0x08
#pragma config FOSC = IRC //enable the internal oscillator
//function prototypes
void oscillator(void);
void timer(void);
void high_isr(void);
void interrupt_at_high_vector(void)
{
_asm goto high_isr _endasm
}
/*******Oscillator function - This function will set the oscillator to 31 kHz***********/
void oscillator(void)
{
//Set oscillator to 31 kHz
OSCCONbits.IRCF2 = 0;
OSCCONbits.IRCF1 = 0;
OSCCONbits.IRCF0 = 0;
//Device clock derived directly from the LFINTOSC internal oscillator
OSCTUNEbits.INTSRC = 0;
}
/*******End Oscillator Function********************************************************/
/*******Timer function - Will start the timer and set pre-scalar to 1:128**********/
void timer(void)
{
//Pre-scalar value of 1:128. This should give about 4 seconds for the timer0 interrupt flag to go high
T0CONbits.T0PS2 = 1;
T0CONbits.T0PS1 = 1;
T0CONbits.T0PS0 = 0;
T0CONbits.TMR0ON = 1; //Enables Timer0
}
/*******End Timer Function********************************************************/
void main(void)
{
INTCONbits.GIE = 1; //enable high priority global interrupts
RCONbits.IPEN = 1; //enable priority levels on interrupts
INTCONbits.TMR0IF = 0; //clears timer interrupt flag
INTCONbits.TMR0IE = 1; //enable Timer0 interrupt bit
T0CONbits.T08BIT = 1; //Set Timer0 as an 8-bit timer
INTCON2bits.TMR0IP = 1; //Timer0 Interrupt bit set to high priority
TRISC = 0x00; //set all PORTC bits as an output
oscillator();
timer();
}
//High Interrupt Vector function
#pragma interrupt high_isr // declare function as high priority isr
void high_isr(void)
{
if(INTCONbits.TMR0IF = 1)
{
LATCbits.LATC0=1 //Turn on LED at RC0
}
}
I am not quite sure if I really understand what that means. So could you explain to me what I am doing wrong.
Could you provide some other links to any sample code about interrupts on timer?
I am using MPLAB IDE with C18
Thanks