求高手赐教: 想做一个用CPU定时器0的中断,产生一个每隔一秒LED灯闪烁一次的程序
求高手赐教:想做一个用CPU定时器0的中断,产生一个每隔一秒LED灯闪烁一次的程序中断程序:interruptvoidTINT0_ISR(void)//CPU-Timer...
求高手赐教:
想做一个用CPU定时器0的中断,产生一个每隔一秒LED灯闪烁一次的程序
中断程序:
interrupt void TINT0_ISR(void) // CPU-Timer0中断函数
{
CpuTimer0.InterruptCount++;
if( CpuTimer0.InterruptCount==1)
{GpioDataRegs.GPACLEAR.bit.GPIOA0=1;}
if( CpuTimer0.InterruptCount==2)
{GpioDataRegs.GPASET.bit.GPIOA0=1;
CpuTimer0.InterruptCount=0;}
PieCtrl.PIEACK.all=PIEACK_GROUP1 ;
CpuTimer0Regs.TCR.bit.TIF=1;
CpuTimer0Regs.TCR.bit.TRB = 1;
EINT;
}
GPIO设置:
void InitGpio(void)
{
EALLOW;
GpioMuxRegs.GPAMUX.bit.PWM1_GPIOA0=0;
GpioMuxRegs.GPADIR.bit.GPIOA0=1;
GpioDataRegs.GPASET.bit.GPIOA0=1;
EDIS;
}
CPU定时器0设置:
#include "DSP28_Device.h"
struct CPUTIMER_VARS CpuTimer0;
struct CPUTIMER_VARS CpuTimer1;
struct CPUTIMER_VARS CpuTimer2;
void InitCpuTimer0(void)
{CpuTimer0.RegsAddr=&CpuTimer0Regs;
CpuTimer0Regs.PRD.all=0xFFFFFFFF;
CpuTimer0Regs.TPR.all=0;
CpuTimer0Regs.TPRH.all=0;
CpuTimer0Regs.TCR.bit.TSS=0;
CpuTimer0Regs.TCR.bit.TRB=1;
CpuTimer0.InterruptCount=0;}
void ConfigCpuTimer(struct CPUTIMER_VARS *Timer,float Freq,float Period)
{Uint32 temp;
Timer->CPUFreqInMHz=Freq;
Timer->PeriodInUSec=Period;
temp=(long)(Freq*Period);
Timer->RegsAddr->PRD.all=temp;
Timer->RegsAddr->TPR.all=0;
Timer->RegsAddr->TPRH.all=0;
Timer->RegsAddr->TCR.bit.TIF=1;
Timer->RegsAddr->TCR.bit.TSS=0;
Timer->RegsAddr->TCR.bit.TRB=1;
Timer->RegsAddr->TCR.bit.SOFT=1;
Timer->RegsAddr->TCR.bit.FREE=1;
Timer->RegsAddr->TCR.bit.TIE=1;
Timer->InterruptCount=0;}
主函数:
#include "DSP28_Device.h"
/*#include "DSP28_Globalprototypes.h"*/
void main(void)
{
InitSysCtrl(); //初始化系统函数
DINT;
IER = 0x0000; //禁止CPU中断
IFR = 0x0000;
InitPieCtrl(); //初始化PIE控制寄存器
InitPieVectTable(); //初始化PIE中断向量表
InitGpio(); //初始化Gpio口
InitPeripherals();
EALLOW; // This is needed to write to EALLOW protected registers
PieVectTable.TINT0 = &TINT0_ISR;//指定中断服务子程序
EDIS; // This is needed to disable write to EALLOW protected registers
PieCtrl.PIEIER1.bit.INTx7=1;
IER|=M_INT1;
EINT;
ERTM;
ConfigCpuTimer(&CpuTimer0,150,1000000);
StartCpuTimer0();//启动定时器0
for(;;){}
}
可是执行完为什么没有进入中断啊?灯没有反应 展开
想做一个用CPU定时器0的中断,产生一个每隔一秒LED灯闪烁一次的程序
中断程序:
interrupt void TINT0_ISR(void) // CPU-Timer0中断函数
{
CpuTimer0.InterruptCount++;
if( CpuTimer0.InterruptCount==1)
{GpioDataRegs.GPACLEAR.bit.GPIOA0=1;}
if( CpuTimer0.InterruptCount==2)
{GpioDataRegs.GPASET.bit.GPIOA0=1;
CpuTimer0.InterruptCount=0;}
PieCtrl.PIEACK.all=PIEACK_GROUP1 ;
CpuTimer0Regs.TCR.bit.TIF=1;
CpuTimer0Regs.TCR.bit.TRB = 1;
EINT;
}
GPIO设置:
void InitGpio(void)
{
EALLOW;
GpioMuxRegs.GPAMUX.bit.PWM1_GPIOA0=0;
GpioMuxRegs.GPADIR.bit.GPIOA0=1;
GpioDataRegs.GPASET.bit.GPIOA0=1;
EDIS;
}
CPU定时器0设置:
#include "DSP28_Device.h"
struct CPUTIMER_VARS CpuTimer0;
struct CPUTIMER_VARS CpuTimer1;
struct CPUTIMER_VARS CpuTimer2;
void InitCpuTimer0(void)
{CpuTimer0.RegsAddr=&CpuTimer0Regs;
CpuTimer0Regs.PRD.all=0xFFFFFFFF;
CpuTimer0Regs.TPR.all=0;
CpuTimer0Regs.TPRH.all=0;
CpuTimer0Regs.TCR.bit.TSS=0;
CpuTimer0Regs.TCR.bit.TRB=1;
CpuTimer0.InterruptCount=0;}
void ConfigCpuTimer(struct CPUTIMER_VARS *Timer,float Freq,float Period)
{Uint32 temp;
Timer->CPUFreqInMHz=Freq;
Timer->PeriodInUSec=Period;
temp=(long)(Freq*Period);
Timer->RegsAddr->PRD.all=temp;
Timer->RegsAddr->TPR.all=0;
Timer->RegsAddr->TPRH.all=0;
Timer->RegsAddr->TCR.bit.TIF=1;
Timer->RegsAddr->TCR.bit.TSS=0;
Timer->RegsAddr->TCR.bit.TRB=1;
Timer->RegsAddr->TCR.bit.SOFT=1;
Timer->RegsAddr->TCR.bit.FREE=1;
Timer->RegsAddr->TCR.bit.TIE=1;
Timer->InterruptCount=0;}
主函数:
#include "DSP28_Device.h"
/*#include "DSP28_Globalprototypes.h"*/
void main(void)
{
InitSysCtrl(); //初始化系统函数
DINT;
IER = 0x0000; //禁止CPU中断
IFR = 0x0000;
InitPieCtrl(); //初始化PIE控制寄存器
InitPieVectTable(); //初始化PIE中断向量表
InitGpio(); //初始化Gpio口
InitPeripherals();
EALLOW; // This is needed to write to EALLOW protected registers
PieVectTable.TINT0 = &TINT0_ISR;//指定中断服务子程序
EDIS; // This is needed to disable write to EALLOW protected registers
PieCtrl.PIEIER1.bit.INTx7=1;
IER|=M_INT1;
EINT;
ERTM;
ConfigCpuTimer(&CpuTimer0,150,1000000);
StartCpuTimer0();//启动定时器0
for(;;){}
}
可是执行完为什么没有进入中断啊?灯没有反应 展开
4个回答
展开全部
PieCtrl.PIEACK.all=PIEACK_GROUP1 ;
换为PieCtrl.PIEACK.bit.ACK1=1;
换为PieCtrl.PIEACK.bit.ACK1=1;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
我最近也遇到同样的问题,CpuTimer0Regs.TIM在运行的过程中会减一,但是不会进入中断,不知道为什么,求高手指教
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
PieVectTable.XINT13= &ISRTimer1; 加这句话再试一下
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
执行语句循环,没有最终执行语句!
追问
不好意思,我还是不太清楚,想问下到底怎么能执行中断语句?
还有这样设置对吗?
CpuTimer0Regs.TCR.bit.TSS=0;
Timer->RegsAddr->TCR.bit.TSS=0
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询