haihongyuan.com

# 东莞理工学院期末复习DSP程序题

TMS320C54xx中，能否从一种分频方式直接切换到另一种分频方式？ 写出切换步骤。例如希望将TMS320VC5402从2分频方式切换到4分 频方式，写出相应程序。

STM #xxxx xxxx xxxx xx11B, CLKMD

T1: LDM CLKMD , A

AND #01B, A

BC T1, AEQ

STM #F000h, CLKMD

TMS320C5402上编程实现周期为4ms的方波发生器（设时钟为100MHz）

(1)源程序fangbo.c

#define TIM *(int *)0x24

#define PRD *(int *)0x25

#define TCR *(int *)0x26

#define IMR *(int *)0x0

#define IFR *(int *)0x1

#define PMST *(int *)0x1d

void interrupt time(void);

unsigned int nCount,uWork;

main()

{

nCount=uWork=0;

asm(" ssbx INTM"); // 关中断，进行关键设置时不许打扰 // 设置通用定时器

uWork=PMST; // 设置PMST寄存器

PMST =uWork&0xff; // 中断向量表起始地址=80H

TCR = 0x419; // xxxx, x100,0001,1001关闭定时器，预分频系数为9 TIM = 0; // 时钟计数器清0

PRD = 0x04E1F; // 周期寄存器为19999

TCR = 0x429; //复位、启动定时器

IFR = 0x0000; // 清中断标志位

IMR = 0x0008; // 使能TINT0

asm(" rsbx INTM"); // 开中断

while ( 1 )

{

}

}

void interrupt time(void)

{ nCount++;

if (nCount%2= =1)

asm(" rsbx XF");

else

asm(" ssbx XF");

}

（2）中断向量表VECTORS.asm

.sect ".vectors"

.ref _c_int00 ; C entry point

.ref _time

.align 0x80 ; must be aligned on page boundary

RESET: ; reset vector

BD _c_int00 ; branch to C entry point

STM #200,SP ; stack size of 200 nmi: RETE ; enable interrupts and return from one NOP

NOP

NOP

; software interrupts

sint17 .space 4*16

sint18 .space 4*16

sint19 .space 4*16

sint20 .space 4*16

sint21 .space 4*16

sint22 .space 4*16

sint23 .space 4*16

sint24 .space 4*16

sint25 .space 4*16

sint26 .space 4*16

sint27 .space 4*16

sint28 .space 4*16

sint29 .space 4*16

sint30 .space 4*16

int0: RETE

NOP

NOP

NOP

int1: RETE

NOP

NOP

NOP

int2: RETE

NOP

NOP

tint0: B _time

NOP

NOP

NOP

rint0: RETE

NOP

NOP

NOP

xint0: RETE

NOP

NOP

NOP

rint1: RETE

NOP

NOP

NOP

xint1: RETE

NOP

NOP

NOP

int3: RETE

NOP

NOP

NOP

.end

（3）配置命令文件fangbo.CMD -w

-stack 400h

-heap 100

-l rts.lib

MEMORY

{

PAGE 0:

VECT : o=80h,l=80h

PRAM : o=100h,l=1f00h PAGE 1: DRAM : o=2000h,l=1000h }

SECTIONS

{

.text : {}> PRAM PAGE 0 .data : {}> PRAM PAGE 0 .cinit : {}> PRAM PAGE 0

.switch : {}> PRAM PAGE 0 .const : {}> DRAM PAGE 1 .bss : {}> DRAM PAGE 1 .stack : {}> DRAM PAGE 1 .vectors: {}> VECT PAGE 0 } TMS320C5402定时器0定时4ms：可设分频系数9， DSP工作在4MHz ， 定时器可以重复加载。定时器允许中断，设复位中断向量地址为 0x0080。编写定时器及中断初始化程序如下，请填空。 TDDR= 9 IMR=0x8 PRD= 1599 TCR=0x429 初始化程序如下： #define TIM *(int *)0x24 #define PRD *(int *)0x25 #define TCR *(int *)0x26 #define IMR *(int *)0x0 #define IFR *(int *)0x1 #define PMST *(int *)0x1d #define REGISTERCLKMD (*(unsigned int *)0x58) REGISTERCLKMD＝0x0f007 Int uWork1; uWork1= PMST; PMST = uWork1 & 0x00ff ; //设置复位中断向量地址为0x0080,定时器中断向量地址为0x00cc asm( “ ssbx INTM” ); //关可屏蔽中断 IMR = 0x8; //开定时器中断 TCR = 0x419 ; //关定时器 TIM = 0; //计数器清0 PRD = 1599 ; // 频率设置 TCR = 0x429 ; //开定时器，时间常数可以重置 IFR = 0x08 ; //设置中断标志寄存器 asm( “ rsbx INTM” ); //开中断 DSP最小系统板基础上请用汇编语言编程实现FLASH-AM29LV800B在 线整片擦除操作 .global _flash_clean _flash_clean: POPM AR4 POPM AR2 rsbx cpl LD #0H, DP NOP NOP NOP

STL A, 0CH NOP

NOP

NOP

NOP

ST #0AAH, 0BH LD #08555H, A NOP

NOP

NOP

WRITA 0BH ST #055H, 0BH LD #082AAH, A NOP

NOP

NOP

WRITA 0BH ST #080H, 0BH LD #08555H, A NOP

NOP

NOP

WRITA 0BH ST #0AAH, 0BH LD #08555H, A NOP

NOP

NOP

WRITA 0BH ST #055H, 0BH LD #082AAH, A NOP

NOP

NOP

WRITA 0BH MVMD AR2, 0BH LD 0CH, A NOP

NOP

NOP

WRITA 0BH NOP

NOP

NOP

NOP NOP

ssbx cpl PSHM AR2 PSHM AR4 RET