⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ad7888.c

📁 AD7888的调试程序,串行模式
💻 C
字号:
#include "DSP28_Device.h"


#define   AD7888_ADO   GpioDataRegs.GPFDAT.bit.GPIOF0
#define   AD7888_ADI   GpioDataRegs.GPFDAT.bit.GPIOF1
#define   AD7888_ACLK  GpioDataRegs.GPFDAT.bit.GPIOF2
#define   AD7888_ACS   GpioDataRegs.GPFDAT.bit.GPIOF3
#define  SPI_CLK   1000000
#define  ADC_SET   0x0400
#define  ADC_MASK  0x7
#define  ADC_LMASK 0xf


#define S0SSEL_LOW()	AD7888_ACS=0
#define S0SSEL_HIGH()	AD7888_ACS=1
#define S0SCK_LOW()		AD7888_ACLK=0
#define S0SCK_HIGH()	AD7888_ACLK=1
#define S0MOSI_LOW()	AD7888_ADI=0
#define S0MOSI_HIGH()	AD7888_ADI=1
#define S0MISO()		AD7888_ADO

Uint16 adc_aux  = 0;
Uint16 adc_line = 0;
Uint16 adc_result[ADC_MASK+1][ADC_LMASK+1]; //adc_result[8][16]

void read_adc(void);
Uint16 filter(Uint16 aux);

void read_adc(void)
{
	Uint32 i;
	Uint16 cmd;
	Uint16 result = 0;
	Uint16 test;
	
	S0SSEL_LOW();
	cmd = (Uint16)(ADC_SET | (((adc_aux+1)&ADC_MASK)<<11));	// 设置下一通道
	for (i=0; i<16; i++)
	{   
	    test=cmd&0x8000;
		if (cmd & 0x8000)  //=1
			S0MOSI_HIGH();
		else   //=0
			S0MOSI_LOW();
		S0SCK_LOW();
		S0SCK_LOW();
		S0SCK_LOW();
		S0SCK_LOW();
		S0SCK_LOW();
		if (cmd & 0x8000) //=1
			S0MOSI_HIGH();
		else              //=0
			S0MOSI_LOW();
		cmd <<= 1;
		result <<= 1;
		S0SCK_HIGH();
		if (S0MISO())
			result |= 0x1;
	}
	S0SSEL_HIGH();
	
	adc_result[adc_aux][adc_line] = (Uint16)(result & 0xfff);		// 读转换数据
	if (++adc_aux > ADC_MASK)
	{
		adc_aux = 0;
		if (++adc_line > ADC_LMASK)
			adc_line = 0;
	}
	
}


// 初始化SPI总线,控制AD7888,时钟1MHz
void spi_init(void)
{
/*	S0SPCCR = Fpclk / SPI_CLK;
	S0SPCR = (1<<2) |	// 16位
			 (1<<3) |	// 
			 (0<<4) |	// 上升沿采样
			 (1<<5) |	// 主模式
			 (0<<6) |	// 高位在前
			 (0<<7) |	// 禁止中断
			 (0<<8);	// 16位数据
//	S0SCK_HIGH();
//	S0SSEL_LOW();
	S0SPDR = ADC_SET;					// 设置0通道
	while ((S0SPSR & (1<<7)) == 0) ;	// 等待发送完成
//	S0SSEL_HIGH();*/
}


// 

/***************************************************
* 函数名称: filter
* 功    能: ADC结果滤波函数
* 参    数: aux - 滤波的通道
* 返 回 值: 滤波结果
* 建立时间: 2008.5.15
* 其它说明: MFB
***************************************************/
Uint16 filter(Uint16 aux)
{
	Uint16 i;
	Uint16 res = 0;
	
	for (i=0; i<=ADC_LMASK; i++)
	{
		res += adc_result[aux][i];///因是12位所以不会溢出(0X0FFF*F=0XEFF1)
	}
	res /= (ADC_LMASK+1);
	
	return res;
}

⌨️ 快捷键说明

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