- #1
Mathslova
- 7
- 0
I am new to interrupts, so i have made a simple program using a timer interrupt to cause a delay of about 1 sec in displaying the binary numbers. However I have failed to achieve this.
Anyone knows the problem with my program?
any assitance will be highly appreciated.
#include <p24FJ128GA010.h>
_CONFIG2( FNOSC_FRCPLL & OSCIOFNC_OFF ); // Internal oscillator - 4xPLL giving 16 MIPS
// pin RC15 has the oscillator
int main()
{
//Configure the device to use the internal oscillator
OSCCONbits.COSC = 1u; // Internal oscillator with PLL
CLKDIVbits.RCDIV = 0u; //Internal oscillator not divided (8MHz)
CLKDIVbits.DOZEN =0; //No post scaling
CLKDIVbits.DOZE =0; //
//Set the LSB of port A to be outputs
TRISA = 0xFF00;
//TIMER1 Configuration Register
T1CON = 0;
T1CONbits.TCKPS = 0b11; //Prescale = 256
T1CONbits.TON = 1; //Timer on
TMR1 = 0; //Timer = 0
//Configure TIMER1 interrupt
_T1IP = 4; //Interrupt priority = 4
PR1 = 62500-1; //Period Register
_T1IF = 0; //Clear timer interrupt flag
_T1IE = 1; //Switch on timer 1 interrupt enable
TMR1 = 0;
while(1)
{
Idle();
asm("nop");
PORTA = 0b11111111;
PORTA = 0b00000000;
}//end while loop
}//end main loop
//TIMER1 Interrupt
void __attribute__((interrupt, no_auto_psv)) _T1Interrupt()
{
_T1IF = 0; //Clear interrrupt flag before returning
}
Anyone knows the problem with my program?
any assitance will be highly appreciated.
#include <p24FJ128GA010.h>
_CONFIG2( FNOSC_FRCPLL & OSCIOFNC_OFF ); // Internal oscillator - 4xPLL giving 16 MIPS
// pin RC15 has the oscillator
int main()
{
//Configure the device to use the internal oscillator
OSCCONbits.COSC = 1u; // Internal oscillator with PLL
CLKDIVbits.RCDIV = 0u; //Internal oscillator not divided (8MHz)
CLKDIVbits.DOZEN =0; //No post scaling
CLKDIVbits.DOZE =0; //
//Set the LSB of port A to be outputs
TRISA = 0xFF00;
//TIMER1 Configuration Register
T1CON = 0;
T1CONbits.TCKPS = 0b11; //Prescale = 256
T1CONbits.TON = 1; //Timer on
TMR1 = 0; //Timer = 0
//Configure TIMER1 interrupt
_T1IP = 4; //Interrupt priority = 4
PR1 = 62500-1; //Period Register
_T1IF = 0; //Clear timer interrupt flag
_T1IE = 1; //Switch on timer 1 interrupt enable
TMR1 = 0;
while(1)
{
Idle();
asm("nop");
PORTA = 0b11111111;
PORTA = 0b00000000;
}//end while loop
}//end main loop
//TIMER1 Interrupt
void __attribute__((interrupt, no_auto_psv)) _T1Interrupt()
{
_T1IF = 0; //Clear interrrupt flag before returning
}