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

📄 main.c

📁 ADI公司的ARM7的功能模块的源码
💻 C
字号:
/*********************************************************************

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

 Date          : Sept. 2005

 File          : main.c

 Hardware      : Applicable to ADuC702x rev H or I silicon
                 Currently targetting ADuC7026.

 Description   : Demonstrates the use of the external RAM
				 on the AduC702x boards. ADC0 is used to
				 take in a signal which is first stored in
				 external RAM, and then sent to the UART
		
*********************************************************************/

#include <ADuC7026.H>					
#define N 0x8000							//Maximum = 65534 samples


void start_conversion(void);				//ADC code sequence
void senddata(short);						//Send ASCII code to serial port
char hex2ascii(char);						//Convert hex to ASCII
void ADCpoweron(int);

int main(){
	ADCpoweron(20000);						//Power on ADC

	ADCCP = 0x00;		  					//Select ADC channel 0
	REFCON = 0x01;							//Internal 2.5V reference. 2.5V on Vref pin
	
	GP1CON = 0x011;							// Setup tx & rx pins on P1.0 and P1.1
	GP0CON = 0x220;							// ext mem mode for BHE & BLE
	GP2CON = 0x22222220;
	GP3CON = 0x22222222;
	GP4CON = 0x22222222;
	
											// configure ext mem port
	XMCFG = 0x1;
	XM0CON = 0x3;							// enable ext mem in 16-bit mode
	XM0PAR = 0x70FF;
 											//Start setting up UART at 9600bps
	COMCON0 = 0x80;							//Setting DLAB
	COMDIV0 = 0x88;							//9600bps		
	COMDIV1 = 0x00;							             
	COMCON0 = 0x07;							//Clearing DLAB

		start_conversion();
	while(1){
	}

}


void start_conversion(void){
	int i;
	unsigned short * data_ptr;				//Conversion information stored here
	data_ptr = (unsigned short *)0x10000000;
	
	ADCCON = 0x6E4;							//Start continuous conversion			

	for(i=0;i<N;i++){
		while(!ADCSTA){}					//Wait for end of conversion
		*data_ptr = (ADCDAT >> 16);			//Store converison in external ram
		data_ptr ++;
	}
	ADCCON = 0x620;							//Stops continuous conversion

	data_ptr = (unsigned short *)0x10000000;
			for(i=0;i<N;i++){
				senddata(*data_ptr);
				data_ptr++;
	}
}


void senddata(short to_send)
{
	while(!(0x020==(COMSTA0 & 0x020))){}
		COMTX = 0x0A;							//Output LF 
	while(!(0x020==(COMSTA0 & 0x020))){}
		COMTX = 0x0D;							//Output CR 
	while(!(0x020==(COMSTA0 & 0x020))){}
		COMTX = hex2ascii ((to_send >> 8) & 0x0F);
	while(!(0x020==(COMSTA0 & 0x020))){}
		COMTX = hex2ascii ((to_send >> 4) & 0x0F);						
	while(!(0x020==(COMSTA0 & 0x020))){}
		COMTX = hex2ascii (to_send & 0x0F);
									
}

char hex2ascii(char toconv)
{
	if (toconv<0x0A)							//If hex digit is greater than 'A'
	{									   		//then add 37h to the hex digit to make
		toconv += 0x30;			  				//an ascii letter
	}									    	//If hex digit is less than 'A'
	else 								    	//then add 30h to it to make
	{									   		//an ascii number
		toconv += 0x37;
	}
	
	return (toconv);
}

void ADCpoweron(int time)
{
	ADCCON = 0x620;	 					// power-on the ADC
	while (time >=0)	  				// wait for ADC to be fully powered on
    time--;
}

⌨️ 快捷键说明

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