搜索
bottom↓
回复: 10

dsPIC33F 中断

[复制链接]

出0入0汤圆

发表于 2010-7-22 11:26:20 | 显示全部楼层 |阅读模式
#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
}




这个程序不进中断,各位大侠帮忙看一下啊

出0入0汤圆

发表于 2010-7-22 12:37:31 | 显示全部楼层
程序运行了?
INTCON2 = 0x001E;              /*Setup INT1, INT2, INT3 & INT4 pins to interupt */
                                /*on falling edge and set up INT0 pin to interupt */
                                /*on rising edge */

上升?下降?中断?

出0入0汤圆

 楼主| 发表于 2010-7-22 13:09:30 | 显示全部楼层
INTCON2=0x001E;是设定外部中断有下降沿触发

IECx是控制中断使能的

硬件运行过,MPLAB SIM 仿真过,都不进中断。不知为何

出0入0汤圆

发表于 2010-7-22 15:02:19 | 显示全部楼层
TRISD = 0x0000;
改成
TRISD = 0xffff;

出0入0汤圆

 楼主| 发表于 2010-7-22 16:37:59 | 显示全部楼层
要将RD口设置为输入吗?RD口是用来驱动LED的

出0入0汤圆

发表于 2010-7-22 16:52:03 | 显示全部楼层
哦? 那你作为INT的口是什么口?我怎么没看到对TRIS的设置?抱歉,我没下载你使用的芯片的文档。 至少作为INT的口应该TRISx该设为输入口
我使用dspic30f4011仿真了你的程序,可以进入中断。

出0入0汤圆

 楼主| 发表于 2010-7-22 17:17:13 | 显示全部楼层
INT用的是RA口,dsPIC30F是可以进中断,但是我用dsPIC33fj128gp708,软硬兼施,都不进中断。

现在准备整一个KIT3做一下硬件仿真,看看问题到底出在哪里

出0入0汤圆

发表于 2010-7-22 17:28:43 | 显示全部楼层
那你设置Trisa等于0xffff了吗?

出0入0汤圆

 楼主| 发表于 2010-7-22 17:35:24 | 显示全部楼层
有试过,但是没有起作用

出0入0汤圆

发表于 2010-7-23 12:32:57 | 显示全部楼层
回复【楼主位】gghhz
-----------------------------------------------------------------------

不知道你解决了没有,外部中断没有什么特殊的设置啊,

TRISX = 0xxxxx;   //外部中断引脚配置位输入。
_INTxEP = 1/0;        // = 1;下降沿中断
_INTxIF        = 0;
_INTxIE        = 1;
void
__attribute__((interrupt,no_auto_psv)) _INTxInterrupt(void)
{
        _INTxIF        = 0;
}
没太仔细看你的程序!祝你好运。

出0入0汤圆

发表于 2010-8-26 12:59:53 | 显示全部楼层
楼主,p33fj128gp708.h里面并没有void
_INTxInterrupt(void)的信息,请问你做过别的处理没有。
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-5-8 15:01

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表