ad.c

来自「TI 2812 AD转换程序和串口通信程序」· C语言 代码 · 共 84 行

C
84
字号
//2006-06-15调试AD,采样全为0,未加外部信号。
#include "DSP28_Device.h"

float	a1[16];
unsigned int a2=0;
float	adclo=0.0;

// Prototype statements for functions found within this file.
interrupt void ad(void);

void main(void)
{

	InitSysCtrl();

	DINT;
	IER = 0x0000;
	IFR = 0x0000;

	InitPieCtrl();


	InitPieVectTable();	
	
	
	EALLOW;	// This is needed to write to EALLOW protected registers
	PieVectTable.ADCINT=&ad;
	EDIS;   // This is needed to disable write to EALLOW protected registers
    
    InitAdc();

    // Enable INT14 which is connected to CPU-Timer 2:
	IER |= M_INT1;
	//KickDog();
    // Enable global Interrupts and higher priority real-time debug events:
	
	EINT;   // Enable Global interrupt INTM
	ERTM;	// Enable Global realtime interrupt DBGM
	while(AdcRegs.ADC_ST_FLAG.bit.SEQ1_BSY==0)
		{			

			AdcRegs.ADCTRL2.bit.SOC_SEQ1=1;

		}

	for(;;)
	{
			KickDog();
	}
} 	


interrupt void ad(void)
{
	IFR=0x0000;
//	PieCtrl.PIEIFR1.all = 0;
	PieCtrl.PIEACK.all=0xffff;
	a2++;
	a1[0]=((AdcRegs.RESULT0>>4)*3)/4095.0+adclo;
	a1[1]=((AdcRegs.RESULT1>>4)*3)/4095.0+adclo;
	a1[2]=((AdcRegs.RESULT2>>4)*3)/4095.0+adclo;
	a1[3]=((AdcRegs.RESULT3>>4)*3)/4095.0+adclo;
	a1[4]=((AdcRegs.RESULT4>>4)*3)/4095.0+adclo;
	a1[5]=((AdcRegs.RESULT5>>4)*3)/4095.0+adclo;
	a1[6]=((AdcRegs.RESULT6>>4)*3)/4095.0+adclo;
	a1[7]=((AdcRegs.RESULT7>>4)*3)/4095.0+adclo;
	a1[8]=((AdcRegs.RESULT8>>4)*3)/4095.0+adclo;
	a1[9]=((AdcRegs.RESULT9>>4)*3)/4095.0+adclo;
	a1[10]=((AdcRegs.RESULT10>>4)*3)/4095.0+adclo;
	a1[11]=((AdcRegs.RESULT11>>4)*3)/4095.0+adclo;
	a1[12]=((AdcRegs.RESULT12>>4)*3)/4095.0+adclo;
	a1[13]=((AdcRegs.RESULT13>>4)*3)/4095.0+adclo;
	a1[14]=((AdcRegs.RESULT14>>4)*3)/4095.0+adclo;
	a1[15]=((AdcRegs.RESULT15>>4)*3)/4095.0+adclo;
	AdcRegs.ADC_ST_FLAG.bit.INT_SEQ1_CLR=1;
	AdcRegs.ADCTRL2.bit.SOC_SEQ1=1;			//在这里设置断点
	EINT;
	
}

//===========================================================================
// No more.
//===========================================================================

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?