📄 mymain.c
字号:
#include "DSP281x_Device.h" // DSP281x Headerfile Include File
#include "DSP281x_Examples.h" // DSP281x Examples Include File
#include "math.h"
#define POINTMAX 64
int pwmdata[POINTMAX];
int pwmcount=0;
int peak=0x0237;
int spidata;
int datainflag;
//
int spibuf[100];
int spicount;
//
double buffer[100];
int bufcount;
double lpfbuf[100];
int lpfcount;
double temp_bpf[1];
double temp_lpf[1];
int testnum,j;
int txstate;
interrupt void sciarxint_isr(void);
interrupt void spirxint_isr(void);
interrupt void t1ufint_isr(void);
void writeint(int dwdata);
void filterc(double b[],double a[],int n,int ns,double x[],int len,double px[],double py[]);
//
// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the DSP281x_SysCtrl.c file.
void main(void)
{
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();
// Step 3. Clear all interrupts and initialize PIE vector table:
// Disable CPU interrupts
DINT;
// Initialize the 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();
/*设置中断服务程序入口地址*/
EALLOW; // This is needed to write to EALLOW protected registers
PieVectTable.RXAINT = &sciarxint_isr;
PieVectTable.SPIRXINTA=&spirxint_isr;
PieVectTable.T1UFINT=&t1ufint_isr;
EDIS; // This is needed to disable write to EALLOW protected registers
// Step 4. Initialize all the Device Peripherals:
// This function is found in DSP281x_InitPeripherals.c
InitPeripherals();
GpioDataRegs.GPFCLEAR.bit.GPIOF14=1; //SET XF=0;clear for set 0
GpioDataRegs.GPFSET.bit.GPIOF14=1; //SET XF=1;
GpioDataRegs.GPFCLEAR.bit.GPIOF6=1; //cal signal
datainflag=0;
/*开中断*/
IER |= (M_INT9 | M_INT6 | M_INT2);
EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM
// Step 6. IDLE loop. Just sit and loop forever (optional):
EvaRegs.T1CON.bit.TENABLE=1; //启动定时器1
for(;;)
{
for(testnum=-300;testnum<300;testnum++)//for delay
{for(j=-200;j<200;j++);} //for delay
while(!(((txstate=SciaRegs.SCIFFTX.all)&0x1f00)==0))
{;}
writeint(85);
if (GpioDataRegs.GPFDAT.bit.GPIOF14==1)
{
GpioDataRegs.GPFCLEAR.bit.GPIOF14=1;//adcov1(dsp2810)--led is off 2005.10.29
}
else
{
GpioDataRegs.GPFSET.bit.GPIOF14=1; //adcov1(dsp2810)--led is on 2005.10.29
}
}
}
interrupt void spirxint_isr(void)
{
PieCtrlRegs.PIEACK.bit.ACK6=1;
spidata=SpiaRegs.SPIRXBUF;
if(spicount<100)
{
spibuf[spicount]=spidata;
spicount++;
}
datainflag=1;
EINT;
}
interrupt void sciarxint_isr(void)
{
PieCtrlRegs.PIEACK.bit.ACK9=1;
if(SciaRegs.SCIRXST.bit.RXRDY==1)
{
SciaRegs.SCITXBUF=SciaRegs.SCIRXBUF.all;
}
EINT;
}
interrupt void t1ufint_isr(void) // EV-A
{
PieCtrlRegs.PIEACK.bit.ACK2=1;
EvaRegs.CMPR1=pwmdata[pwmcount];
pwmcount++;
if(pwmcount>=POINTMAX)
{
pwmcount=0;
}
// EvaRegs.EVAIMRA.bit.T1UFINT=1;
EvaRegs.EVAIFRA.bit.T1UFINT=1;
EINT;
}
void writeint(int dwdata)
{
//SciaRegs.SCITXBUF=0xFF;
SciaRegs.SCITXBUF=dwdata;
//dwdata=(dwdata>>8);
//SciaRegs.SCITXBUF=dwdata;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -