📄 dac.c
字号:
#include "DSP28_Device.h"
float ADResult[16];
unsigned int a2=0;
float adclo=0.0;
#define SPI_SEL_REG *(unsigned int*)0x2004
#define DA_SPI 0X03
interrupt void ad(void);
void WriteDAC(unsigned data);
void delay(unsigned int);
void main(void)
{
unsigned char temp;
InitSysCtrl(); //初始化系统
DINT; //关中断
IER = 0x0000;
IFR = 0x0000;
InitPieCtrl(); //初始化PIE控制寄存器
InitPieVectTable(); //初始化PIE参数表
InitSpi();
EALLOW;
PieVectTable.ADCINT=&ad;
EDIS;
SPI_SEL_REG=DA_SPI;
WriteDAC(0x300);
InitAdc(); //初始化ADC
IER |= M_INT1; // Enable INT14 which is connected to CPU-Timer 2:
EINT; // Enable INTM
ERTM; // Enable DBGM
while(AdcRegs.ADC_ST_FLAG.bit.SEQ1_BSY==0)
{
AdcRegs.ADCTRL2.bit.SOC_SEQ1=1;
}
GpioDataRegs.GPASET.all|=0x8000;
temp=46;
for(;;)
{
KickDog();
}
}
void WriteDAC(unsigned data)
{
if(Spi_TxReady() == 1)
SpiaRegs.SPITXBUF = data;
delay(10000);
if(Spi_TxReady() == 1)
SpiaRegs.SPITXBUF = data;
delay(50000);
}
void delay(unsigned int t)
{
while(t>0)
t--;
}
interrupt void ad(void)
{
adclo=5;
IFR=0x0000;
PieCtrl.PIEACK.all=0xffff;
a2++;
ADResult[0]=((AdcRegs.RESULT0>>4)*3)/4095.0+adclo;
ADResult[1]=((AdcRegs.RESULT1>>4)*3)/4095.0+adclo;
ADResult[2]=((AdcRegs.RESULT2>>4)*3)/4095.0+adclo;
ADResult[3]=((AdcRegs.RESULT3>>4)*3)/4095.0+adclo;
ADResult[4]=((AdcRegs.RESULT4>>4)*3)/4095.0+adclo;
ADResult[5]=((AdcRegs.RESULT5>>4)*3)/4095.0+adclo;
ADResult[6]=((AdcRegs.RESULT6>>4)*3)/4095.0+adclo;
ADResult[7]=((AdcRegs.RESULT7>>4)*3)/4095.0+adclo;
ADResult[8]=((AdcRegs.RESULT8>>4)*3)/4095.0+adclo;
ADResult[9]=((AdcRegs.RESULT9>>4)*3)/4095.0+adclo;
ADResult[10]=((AdcRegs.RESULT10>>4)*3)/4095.0+adclo;
ADResult[11]=((AdcRegs.RESULT11>>4)*3)/4095.0+adclo;
ADResult[12]=((AdcRegs.RESULT12>>4)*3)/4095.0+adclo;
ADResult[13]=((AdcRegs.RESULT13>>4)*3)/4095.0+adclo;
ADResult[14]=((AdcRegs.RESULT14>>4)*3)/4095.0+adclo;
ADResult[15]=((AdcRegs.RESULT15>>4)*3)/4095.0+adclo;
AdcRegs.ADC_ST_FLAG.bit.INT_SEQ1_CLR=1;
AdcRegs.ADCTRL2.bit.SOC_SEQ1=1; //在这儿设断点
EINT;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -