microchip 官网上下载了外部中断和定时器中断的示例代码。
在没有做任何修改的情况下,编译通过,烧录后无动作
后作了一些小小的修改,依然无动作,用SIM软件仿真,但是不知道
中断如何仿真,IO激励不知道如何使用,E文比较的不好,请大虾们指导一下。
附件中为源代码
external_interrupts.rar
(2.97 KB)
以下是修改后的代码:
#include "p33fxxxx.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 Clock Output
// 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__)) _INT1Interrupt(void);
void delay(void)
{
int i,j;
for(i=6000;i>0;i--)
for(j=100;j>0;j--);
//_amp_(nop);
}
int main (void)
{
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;
TRISD = 0x0000; // LEDs on dsPICDEM 1.1 board are connected to RD0-RD3
TRISA = 0XFFFF;
INTx_IO_Init(); /* Call function to initialize the External Interrupts */
while (1) /* Loop endlessly...anytime an interrupt occurs */
{
if(IFS1bits.INT1IF==1)
LATDbits.LATD5=1;
else
LATDbits.LATD6=1;
if(PORTAbits.RA12)
LATDbits.LATD4=1;
}
/* the processor will vector to the interrupt and */
/* return back to the while(1) loop */
}
void INTx_IO_Init(void)
{
INTCON1bits.NSTDIS=0;
SRbits.IPL0=1;
SRbits.IPL1=0;
SRbits.IPL1=0;
INTCON2 = 0x001F;
IEC1bits.INT1IE =1; /*Enable INT1 Interrupt Service Routine */
IPC5bits.INT1IP=5;
}
void __attribute__((interrupt, no_auto_psv)) _INT1Interrupt(void)
{
LATDbits.LATD1=1; //Toggle RD0
delay();
IFS1bits.INT1IF = 0; //Clear the INT1 interrupt flag or else
//the CPU will keep vectoring back to the ISR
} |