📄 ramtest.c
字号:
#include "DSP281x_Device.h" // DSP281x Headerfile Include File
#include "DSP281x_Examples.h" // DSP281x Examples Include File
#include "float.h"
#include "math.h"
volatile Uint16 angel_step,*Dataram=(Uint16*)0x100000;//RAM 起始地址为0X100000
volatile float sindata,angel; /*k代表角度*/
//Gpio 初始化
void InitGpio(void)
{
}
//EVA 初始化
void InitEVA(void)
{
}
void main(void)
{
// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the DSP281x_SysCtrl.c file.
InitSysCtrl();
// Step 2. Initalize GPIO:
// This example function is found in the DSP281x_Gpio.c file and
// illustrates how to set the GPIO to it's default state.
InitGpio(); // Skipped for this example
// Step 3. Clear all interrupts and initialize PIE vector table:
// Disable CPU interrupts
DINT;
// Initialize PIE control registers to their default state.
// The default state is all PIE interrupts disabled and flags
// are cleared.
// This function is found in the DSP281x_PieCtrl.c file.
InitPieCtrl();
// Disable CPU interrupts and clear all CPU interrupt flags:
IER = 0x0000;
IFR = 0x0000;
// Initialize the PIE vector table with pointers to the shell Interrupt
// Service Routines (ISR).
// This will populate the entire table, even if the interrupt
// is not used in this example. This is useful for debug purposes.
// The shell ISR routines are found in DSP281x_DefaultIsr.c.
// This function is found in DSP281x_PieVect.c.
InitPieVectTable();
InitEVA();
angel_step=0;
while(1)
{if(Dataram<(Uint16*)0x107a13)//256K
{angel=180.0/31250*angel_step;
angel=3.1415926*angel;
angel=angel/180;/*数据类型优先级,sin弧度计算*/
sindata=sin(angel);
sindata=sindata*1024;
sindata=sindata+1024;
sindata=sindata*32;
if(sindata>=65536)
{*Dataram++=65535;
angel_step++;
}
else
{*Dataram++=sindata;
angel_step++;
}
}
else
asm(" nop");
}
}
*(int *)MCRA=0X0fb; /*PB=I/O PA2(int1)=oka=I/O*/
*(int *)MCRB=0X0fec3; /*PC2,3,4,5=spi to i/o,PD0=okb=I/O*/
*(int *)MCRC=0X000ff; /*PF=I/O PE=FUNC*/
*(int *)PADATDIR=0X0404; /*PA2=oka=Out value=1*/
*(int *)PBDATDIR=0X0ff09; /*PB=Out value=0*/
*(int *)PCDATDIR=0X03420; /*PC3=IN,PC2,4,5=Out PC5value=1,PC4=0*/
*(int *)PDDATDIR=0X0101; /*PD0=okb=Out value=1*/
*(int *)PFDATDIR=0X0f000; /*PF=IN ,value=0*/
asm(" clrc intm");
/*pwm*/
*(int *)GPTCONA=0Xe065; /*B0000,0000,0100,0010*/
*(int *)T1CNT=0x0; /*USE?*/
*(int *)T1PR=2048;
*(int *)ACTRA=0X0555; /*B0000,0101,0101,0101*/
*(int *)CMPR1=1024;
*(int *)CMPR2=0;
*(int *)CMPR3=0;
*(int *)COMCONA=0x04b00; /*B0100,1010,0000,0000*/
*(int *)COMCONA=0X0Cb00; /*B1100,1010,0000,0000*/
*(int *)T1CON=0X1048; /*B0001,0000,0100,1010*/
/*T4 time*/
*(int *)GPTCONB=0X0005; /*B0000,0000,0000,0101*/
*(int *)T4PR=159; /*40000000/640=62500*/
*(int *)T4CNT=0;
*(int *)EVBIFRB=0x0ff;
*(int *)T4CON=0X1042; /*B1001,0111,0100,0000*/
WAITRUN:
dotadd1=0x8000;
dotval1=32768;
periodno=1;
currfreq=50;
currampl=1024;
currdcval=0;
currdcfx=0;
CALVIB:
dotval1=*(int *)dotadd1;
dotval1=dotval1>>5;
if(dotval1<0x400)
dotval1=0x400;
dotval1=dotval1-0x400;
numdiv=currampl*dotval1;
dotval1=numdiv>>10;
if(dotval1>0x3ff)
dotval1=0x3ff;
dotval1=dotval1+0x400;
if(periodno!=1)
{ dotval1=0x800-dotval1;
dotval1++;
}
WAITT4:
*(int *)WDKEY=0X5555;
*(int *)WDKEY=0X0AAAA;
if(!(*(int *)EVBIFRB&0x1))
goto WAITT4;
*(int *)CMPR1=dotval1;
dotadd1=dotadd1+currfreq;
*(int *)EVBIFRB=0x0ff;
*(int *)IMR=0x0;
if(dotadd1>=0x0FA12)
{ dotadd1=dotadd1-31250;
if(periodno==2)
periodno=1;
else
periodno=2;
}
ONEEND:
*(int *)IMR=0x1;
goto CALVIB;
//===========================================================================
// No more.
//=====
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -