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

📄 aduc7020toad53x4.c

📁 有关AN759的代码和资料说明
💻 C
字号:
/********************************************************************

 Author        : ADI - Apps            www.analog.com/MicroConverter

 Date          : Sept. 2004

 File          : ADuC7020toAD53x4.c

 Hardware      : ADuC702x

 Description   : Program outputs 2x 8 bit packets through SPI which
 		configure the AD5304EB to produce a sinewave on Vout-A
				 
********************************************************************/

#include<ADuC7020.h>

void init702x(void);
void spiTx(unsigned char txDat);
void ad53x4out(unsigned short address,unsigned short pdN,unsigned short ldacN,unsigned short dat);

unsigned char txDat1 = 0x00;					// The high byte
unsigned char txDat0 = 0x00;					// The low byte
const static unsigned short TableS[64] = {		// Sine wave table
 	0x07F, 0x08D, 0x099, 0x0A5, 0x0B1, 0x0BC, 0x0C7, 0x0D1,
 	0x0DB, 0x0E3, 0x0EA, 0x0F1, 0x0F6, 0x0FA, 0x0FD, 0x0FF,
 	0x0FF, 0x0FE, 0x0FD, 0x0FA, 0x0F6, 0x0F1, 0x0EA, 0x0E3,
 	0x0DB, 0x0D1, 0x0C7, 0x0BC, 0x0B1, 0x0A5, 0x099, 0x08D,
 	0x07F, 0x073, 0x067, 0x05B, 0x04F, 0x044, 0x039, 0x02F,
 	0x026, 0x01D, 0x016, 0x00F, 0x00A, 0x006, 0x003, 0x001,
 	0x000, 0x001, 0x003, 0x006, 0x00A, 0x00F, 0x016, 0x01D,
 	0x026, 0x02F, 0x039, 0x044, 0x04F, 0x05B, 0x067, 0x073  
	};

int main(void){
	int i = 0;
	REFCON = 0x01;
	init702x();	 								// Initilise the ADuC7026
	while(1){			 						// Repeate forever
		ad53x4out(0,1,0,TableS[i]);			  	// Prepare data with address = 0, /PD = 1, ldac = 0
		ad53x4out(1,1,0,TableS[i]);	
		ad53x4out(2,1,0,TableS[i]);	
		ad53x4out(3,1,0,TableS[i]);	
		i++;
		i &= 0x03f;
	}
	
	return 0;
}


void init702x(void){
	GP1DAT = 0x80800000;						// configure P1.7 as output
												// and Pull /SYNC High
	GP1CON = 0x02020000;						// configure P1.6 and P1.4 in SPI mode
	SPICON = 0x4B;	 							// Configure SPI as Master, clock idles high
											
	SPIDIV = 0x14;							    // Set the DIV to run at 1.05Mhz
}

void spiTx(unsigned char txDat){
	SPITX = txDat;								// Send txDat to the AD5304
	while(!(SPISTA & 0x08));					// Wait of end of transfer
	txDat = SPIRX;								// Read dummy data from SPIRX to prevent overflow
}

void ad53x4out(unsigned short address,
				unsigned short pdN,
				unsigned short ldacN,
				unsigned short dat){

	txDat1 = 0;									// Reset txDat1 to 0
	txDat0 = 0;						   			// Reset txDat0 to 0

	//configure the high byte to be sent
	txDat1 |= (address << 6);	 				// Store the address in the upper 2 bits of txDat1 (8 bit)
	txDat1 |= pdN ? 0x20 : 0x00;				// If pdN is set, copy a logic 1 into the next space, if not copy a logic 0
	txDat1 |= ldacN ? 0x10 : 0x00;	   			// If ldacN is set, copy a 1 into the next space, if not copy a 0
	txDat1 |= (dat >> 4); 						// Copy the first 4 bits of data into the last 4 bits of txDat1

	//configure the low byte to be sent
	txDat0 |= (dat << 4); 						// Copy the last 4 bits of data into the first 4 bits of txDat0
	txDat0 &= 0xf0;					  			// Insure the first 4 bits of data in txDat0 are empty

	//send the data
	GP1CLR = 0x800000;							// Pull /SYNC High
	spiTx(txDat1);								// Send txDat1 to the SPI
	spiTx(txDat0);						   		// Send txDat0 to the SPI
	GP1SET = 0x800000;							// Pull /SYNC Low
}

⌨️ 快捷键说明

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