DSP TMS320VC5402的定时器0控制LED的亮灭
时间:10-02
整理:3721RD
点击:
板子给的cputimer程序有问题,希望各位大神帮忙参考一下,当DSP单步调试时寄存器CLKMD的值不发生变化,单步运行到while(*CLKMD & 0x01 );报错:寄存器不可读。还有它的软件等待状态寄存器的设置也报错。我怀疑给的程序有问题。程序如下:
#include "cpu_reg.h"
int ms,f;
void main()
{
asm(" STM #0000h,CLKMD ");
while(*CLKMD & 0x01 );
asm(" STM #40C7h,CLKMD "); //设置CPU运行频率=100M
/* 40C7h:5*clkin =100M
30c7h:4*clkin =80M
20c7h:3*clkin =60M
10C7h:2*clkin =40M
*/
asm(" stm #4240h, SWWSR ");
//2 wait except for on-chip program 1
asm(" stm #00a0h, PMST "); //MP/MC = 0, IPTR = 001,ovly=1
asm(" stm #0802h, BSCR ");
asm(" STM #0h,IMR ");
asm(" STM #0010h,TCR "); //关定时器
asm(" STM #0186ah,PRD ");//1ms
asm(" STM #0C2fh,TCR "); //TCR=最后四位
asm(" STM #0008h,IFR ");
asm(" ORM #0008h,*(IMR) ");/*开时间中断*/
asm(" RSBX INTM "); /*开中断*/
f=2;
ms=0;
while(1)
{
while(ms<500/f); //LED_flash
ms=0;
asm(" RSBX XF ");
while(ms<20/f);
ms=0;
asm(" SSBX XF ");
}
}
interrupt void timer0()
{
ms++;
}
#include "cpu_reg.h"
int ms,f;
void main()
{
asm(" STM #0000h,CLKMD ");
while(*CLKMD & 0x01 );
asm(" STM #40C7h,CLKMD "); //设置CPU运行频率=100M
/* 40C7h:5*clkin =100M
30c7h:4*clkin =80M
20c7h:3*clkin =60M
10C7h:2*clkin =40M
*/
asm(" stm #4240h, SWWSR ");
//2 wait except for on-chip program 1
asm(" stm #00a0h, PMST "); //MP/MC = 0, IPTR = 001,ovly=1
asm(" stm #0802h, BSCR ");
asm(" STM #0h,IMR ");
asm(" STM #0010h,TCR "); //关定时器
asm(" STM #0186ah,PRD ");//1ms
asm(" STM #0C2fh,TCR "); //TCR=最后四位
asm(" STM #0008h,IFR ");
asm(" ORM #0008h,*(IMR) ");/*开时间中断*/
asm(" RSBX INTM "); /*开中断*/
f=2;
ms=0;
while(1)
{
while(ms<500/f); //LED_flash
ms=0;
asm(" RSBX XF ");
while(ms<20/f);
ms=0;
asm(" SSBX XF ");
}
}
interrupt void timer0()
{
ms++;
}