📄 dac7724_test.c
字号:
#include <stdlib.h>
#include "DSP28_Device.h"
#define _const_length 0x400
#define _econst_length 0x400
interrupt void ISRTimer0(void);
interrupt void ISRTimer1(void);
interrupt void ISRTimer2(void);
interrupt void AD(void);
float a1[16]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
unsigned int a2=0;
float adclo=0.0;
void main(void)
{
/*初始化系统*/
InitSysCtrl();
/*关中断*/
DINT;
IER = 0x0000;
IFR = 0x0000;
/*初始化PIE*/
InitPieCtrl();
PieCtrl.PIEIER1.bit.INTx6=1; ///AD中断使能
PieCtrl.PIEIER1.bit.INTx7=1;
/*初始化PIE中断矢量表*/
InitPieVectTable();
//初始化外设,事件管理器,AD等
InitPeripherals();
EALLOW; // This is needed to write to EALLOW protected registers
PieVectTable.TINT0 = &ISRTimer0;
PieVectTable.XINT13 = &ISRTimer1;
PieVectTable.XINT14 = &ISRTimer2;
PieVectTable.ADCINT = &AD;
EDIS; // This is needed to disable write to EALLOW protected registers
// Reset CPLD
*Clear_Encoder=0x4088;
/*设置CPU时钟*/
ConfigCpuTimer(&CpuTimer0, 150, 100); // 150MHz CPU Freq, 25 uSeconds Period (in uSeconds)
StartCpuTimer1();
ConfigCpuTimer(&CpuTimer1, 150, 100); // 150MHz CPU Freq, 25 uSeconds Period (in uSeconds)
StartCpuTimer1();
ConfigCpuTimer(&CpuTimer2, 150, 100); // 150MHz CPU Freq, 100 uSeconds Period (in uSeconds)
StartCpuTimer2();
*DA_DIRECTION1 = 0;
*DA_DIRECTION2 = 0;
*DA_DIRECTION3 = 0;
*DA_DIRECTION4 = 0;
/* 设置DAC7724 DA通道*/
da_setup(0,3,50,250);
da_setup(1,3,50,500);
da_setup(2,3,50,750);
da_setup(3,3,50,1000);
da_setup(4,3,50,1000);
da_setup(5,3,50,1000);
da_setup(6,3,50,1000);
da_setup(7,3,50,1000);
/*设置IER*/
IER |= ( M_INT1 | M_INT13 | M_INT14 );
/*开中断*/
EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM
for(;;)
{
KickDog();
}
}
interrupt void AD(void)
{
a1[0]=((float)AdcRegs.RESULT0)*3.0/65520.0+adclo;
a1[1]=((float)AdcRegs.RESULT1)*3.0/65520.0+adclo;
a1[2]=((float)AdcRegs.RESULT2)*3.0/65520.0+adclo;
a1[3]=((float)AdcRegs.RESULT3)*3.0/65520.0+adclo;
a1[4]=((float)AdcRegs.RESULT4)*3.0/65520.0+adclo;
a1[5]=((float)AdcRegs.RESULT5)*3.0/65520.0+adclo;
a1[6]=((float)AdcRegs.RESULT6)*3.0/65520.0+adclo;
a1[7]=((float)AdcRegs.RESULT7)*3.0/65520.0+adclo;
a1[8]=((float)AdcRegs.RESULT8)*3.0/65520.0+adclo;
a1[9]=((float)AdcRegs.RESULT9)*3.0/65520.0+adclo;
a1[10]=((float)AdcRegs.RESULT10)*3.0/65520.0+adclo;
a1[11]=((float)AdcRegs.RESULT11)*3.0/65520.0+adclo;
a1[12]=((float)AdcRegs.RESULT12)*3.0/65520.0+adclo;
a1[13]=((float)AdcRegs.RESULT13)*3.0/65520.0+adclo;
a1[14]=((float)AdcRegs.RESULT14)*3.0/65520.0+adclo;
a1[15]=((float)AdcRegs.RESULT15)*3.0/65520.0+adclo;
AdcRegs.ADC_ST_FLAG.bit.INT_SEQ1_CLR=1;
AdcRegs.ADCTRL2.bit.SOC_SEQ1=1;
EINT;
}
interrupt void ISRTimer0(void)
{
#ifdef DAC7724_0_ENABLE
if(tongdao_flag[0] == 1)
{
*DA_PORT0 = xishu1;
}
#endif
}
interrupt void ISRTimer1(void)
{
#ifdef DAC7724_0_ENABLE
if(tongdao_flag[0] == 1)
{
*DA_PORT0 = xishu1;
}
#endif
#ifdef DAC7724_1_ENABLE
if(tongdao_flag[1] == 1)
{
*DA_PORT1 = xishu2;
}
#endif
#ifdef DAC7724_2_ENABLE
if(tongdao_flag[2] == 1)
{
*DA_PORT2 = xishu3;
}
#endif
da_run();
PieCtrl.PIEACK.bit.ACK1 = 1;
EINT;
}
interrupt void ISRTimer2(void)
{
#ifdef DAC7724_0_ENABLE
if(tongdao_flag[0] == 1)
{
*DA_PORT0 = xishu1;
}
#endif
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -