|
#include "p33fj128gp708.h"
// External Oscillator
_FOSCSEL(FNOSC_FRC);
_FOSC(FCKSM_CSECMD & OSCIOFNC_OFF & POSCMD_XT); // Clock Switching is enabled and Fail Safe Clock Monitor is disabled
// OSC2 Pin Function: OSC2 is ClockOutput
// Primary Oscillator Mode: XT Crystal
_FWDT(FWDTEN_OFF); // Watchdog Timer Enabled/disabled by user software
/* Global Variables and Functions */
void INTx_IO_Init(void);
void __attribute__((__interrupt__)) _INT0Interrupt(void); /*Declare external interrupt ISRs*/
void __attribute__((__interrupt__)) _INT1Interrupt(void);
void __attribute__((__interrupt__)) _INT2Interrupt(void);
void __attribute__((__interrupt__)) _INT3Interrupt(void);
void __attribute__((__interrupt__)) _INT4Interrupt(void);
int main (void)
{
// Configure Oscillator to operate the device at 40Mhz
// Fosc= Fin*M/(N1*N2), Fcy=Fosc/2
// Fosc= 8M*40/(2*2)=80Mhz for 8M input clock
PLLFBD=38; // M=40
CLKDIVbits.PLLPOST=0; // N1=2
CLKDIVbits.PLLPRE=0; // N2=2
OSCTUN=0; // Tune FRC oscillator, if FRC is used
// Disable Watch Dog Timer
RCONbits.SWDTEN=0;
// Configure the Analog functional pins as digital
AD1PCFGL=0xFFFF;
AD1PCFGH=0xFFFF;
// Clock switch to incorporate PLL
__builtin_write_OSCCONH(0x03); // Initiate Clock Switch to Primary
// Oscillator with PLL (NOSC=0b011)
__builtin_write_OSCCONL(0x01); // Start clock switching
while (OSCCONbits.COSC != 0b011); // Wait for Clock switch to occur
// Wait for PLL to lock
while(OSCCONbits.LOCK!=1) {};
TRISD = 0x0000; /* LEDs on dsPICDEM 1.1 board are connected to RD0-RD3 */
/* We will configure Port D to be output so we can use */
/* use LEDs as an indicator of the occurrence of external */
/* interrupts */
INTx_IO_Init(); /* Call function to initialize the External Interrupts */
while (1); /* Loop endlessly...anytime an interrupt occurs */
/* the processor will vector to the interrupt and */
/* return back to the while(1) loop */
}
void INTx_IO_Init(void)
{
INTCON2 = 0x001E; /*Setup INT1, INT2, INT3 & INT4 pins to interupt */
/*on falling edge and set up INT0 pin to interupt */
/*on rising edge */
IFS0bits.INT0IF = 0; /*Reset INT0 interrupt flag */
IEC0bits.INT0IE = 1; /*Enable INT0 Interrupt Service Routine */
IFS1bits.INT1IF = 0; /*Reset INT1 interrupt flag */
IEC1bits.INT1IE = 1; /*Enable INT1 Interrupt Service Routine */
IFS1bits.INT2IF = 0; /*Reset INT0 interrupt flag */
IEC1bits.INT2IE = 1; /*Enable INT0 Interrupt Service Routine */
IFS3bits.INT3IF = 0; /*Reset INT1 interrupt flag */
IEC3bits.INT3IE = 1; /*Enable INT1 Interrupt Service Routine */
IFS3bits.INT4IF = 0; /*Reset INT1 interrupt flag */
IEC3bits.INT4IE = 1; /*Enable INT1 Interrupt Service Routine */
}
void __attribute__((interrupt, no_auto_psv)) _INT0Interrupt(void)
{
IFS0bits.INT0IF = 0; //Clear the INT0 interrupt flag or else
//the CPU will keep vectoring back to the ISR
}
void __attribute__((interrupt, no_auto_psv)) _INT1Interrupt(void)
{
LATD=(PORTD ^ 0x01); //Toggle RD0
IFS1bits.INT1IF = 0; //Clear the INT1 interrupt flag or else
//the CPU will keep vectoring back to the ISR
}
void __attribute__((interrupt, no_auto_psv)) _INT2Interrupt(void)
{
LATD=(PORTD ^ 0x02); //Toggle RD1
IFS1bits.INT2IF = 0; //Clear the INT2 interrupt flag or else
//the CPU will keep vectoring back to the ISR
}
void __attribute__((interrupt, no_auto_psv)) _INT3Interrupt(void)
{
LATD=(PORTD ^ 0x04); //Toggle RD2
IFS3bits.INT3IF = 0; //Clear the INT3 interrupt flag or else
//the CPU will keep vectoring back to the ISR
}
void __attribute__((interrupt, no_auto_psv)) _INT4Interrupt(void)
{
LATD=(PORTD ^ 0x08); //Toggle RD3
IFS3bits.INT4IF = 0; //Clear the INT4 interrupt flag or else
//the CPU will keep vectoring back to the ISR
}
这个程序不进中断,各位大侠帮忙看一下啊 |
|