社区导航

 

搜索
查看: 101|回复: 0

[资料分享] DSP28335的中断配置

[复制链接]

6412

TA的帖子

19

TA的资源

纯净的硅(初级)

Rank: 4

发表于 2020-2-5 21:20 | 显示全部楼层 |阅读模式

外部中断初始化

#include “extint.h”

//按键和外部中断都用了GPIO13,查询和中断不能同时使用
void InitExtInt(void)
{

 EALLOW;
 GpioCtrlRegs.GPAMUX1.bit.GPIO13 = 0;
 GpioCtrlRegs.GPADIR.bit.GPIO13 = 0;           //作为输入IO口

GpioCtrlRegs.GPAQSEL1.bit.GPIO13= 0; //和时钟同步
GpioIntRegs.GPIOXINT1SEL.bit.GPIOSEL = 13; //选择GPIO13为外部输入XINT1输入引脚
XIntruptRegs.XINT1CR.bit.POLARITY= 0; //下降沿触发中断
XIntruptRegs.XINT1CR.bit.ENABLE = 1; //使能XINT1中断
EDIS;
}

//外部中断1服务函数 ,按下按键,进中断,亮灯响鸣
interrupt void ISRExint1(void)
{
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
DELAY_US(1000);
if(GpioDataRegs.GPADAT.bit.GPIO13 == 0)
{
LED4=~LED4;
BUZZ_ON
DELAY_US(100000);
BUZZ_OFF
DELAY_US(100000);
BUZZ_ON
DELAY_US(100000);
BUZZ_OFF
}
}

定时器0,1,2中断初始化

InitCpuTimers();   // For this example, only initialize the Cpu Timers
ConfigCpuTimer(&CpuTimer0, 150, 500000);  // 500us 150MHz CPU Freq, 1 second Period (in uSeconds)
ConfigCpuTimer(&CpuTimer1, 150, 1000000);
ConfigCpuTimer(&CpuTimer2, 150, 3000000);
StartCpuTimer0();
StartCpuTimer1();
StartCpuTimer2();

#include “timer.h”
interrupt void ISRTimer0(void)
{
static u8 timer0_count=0;
// Acknowledge this interrupt to receive more interrupts from group 1
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; //0x0001赋给12组中断ACKnowledge寄存器,对其全部清除,不接受其他中断
CpuTimer0Regs.TCR.bit.TIF=1; // 定时到了指定时间,标志位置位,清除标志
CpuTimer0Regs.TCR.bit.TRB=1; // 重载Timer0的定时数据

timer0_count++;
if(timer0_count==4)  //2000ms =2s
{
timer0_count =0;
LED1=~LED1;
}

}

//1s
interrupt void ISRTimer1(void)
{
static u8 timer1_count=0;
// Acknowledge this interrupt to receive more interrupts from group 1
//PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; //0x0001赋给12组中断ACKnowledge寄存器,对其全部清除,不接受其他中断
CpuTimer1Regs.TCR.bit.TIF=1; // 定时到了指定时间,标志位置位,清除标志
CpuTimer1Regs.TCR.bit.TRB=1; // 重载Timer0的定时数据

timer1_count++;
if(timer1_count==1)
{
timer1_count =0;
LED2=~LED2;
}

}

//3s
interrupt void ISRTimer2(void)
{
static u8 timer2_count=0;
// Acknowledge this interrupt to receive more interrupts from group 1
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; //0x0001赋给12组中断ACKnowledge寄存器,对其全部清除,不接受其他中断
CpuTimer2Regs.TCR.bit.TIF=1; // 定时到了指定时间,标志位置位,清除标志
CpuTimer2Regs.TCR.bit.TRB=1; // 重载Timer0的定时数据

timer2_count++;
if(timer2_count==1)
{
timer2_count =0;
//LED3=~LED3;
}

}

指定中断服务函数地址
EALLOW; // protected registers
PieVectTable.XINT1 = &ISRExint1; //外部中断1服务程序
PieVectTable.TINT0 = &ISRTimer0; //定时器0中断服务
PieVectTable.XINT13 = &ISRTimer1; //定时器1中断服务
PieVectTable.TINT2 = &ISRTimer2; //定时器2中断服务
EDIS; // This is needed to disable write to EALLOW protected registers

开CPU级中断

IER |= M_INT1;    //开启CPU中断 组1
IER |= M_INT13;   //开启CPU中断 13   XINT13 / CPU-Timer1
IER |= M_INT14;   //开启CPU中断 组14 TINT2

PieCtrlRegs.PIEIER1.bit.INTx7= 1;  //CPU定时器 TIMER0中断   组1的第4个中断使能
CpuTimer1Regs.TCR.all = 0x4001; // 使能TIMER1 Use write-only instruction to set TSS bit = 0
CpuTimer2Regs.TCR.all = 0x4001; // 使能TIMER2 Use write-only instruction to set TSS bit = 0

EINT;   //开启全局中断
ERTM;   //开启全局实时中断,调试用DBGM


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

关闭

站长推荐上一条 1/7 下一条

  • 论坛活动 E手掌握

    扫码关注
    EEWORLD 官方微信

  • EE福利  唾手可得

    扫码关注
    EE福利 唾手可得

Archiver|手机版|小黑屋|电子工程世界 ( 京ICP证 060456 )

GMT+8, 2020-5-27 11:26 , Processed in 0.088319 second(s), 20 queries , Gzip On, MemCache On.

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