Fork Me on GitHub

源码开放学ARM

LASO - Learn ARM with Source Open

首页         目录索引         资料下载         代码下载         联系作者        
下载PDF打印版本

ADC 驱动代码实现

int adc_read_xy(int * x, int * y)

{

	int data;



	// SEL_MUX [5:3] Analog input channel select 

	//	000 = AIN 0 

	//	001 = AIN 1 

	//	010 = AIN 2 

	//	011 = AIN 3 

	//	100 = YM 

	//	101 = YP

	//	110 = XM 

	//	111 = XP 	

	// TS_XP	Xadc_AIN7 AC3

	// TS_YM	Xadc_AIN4 AE3

	// TS_YP	Xadc_AIN5 AD4

	// TS_XM	Xadc_AIN6 AE4

	ADCCON = (1<<14) | (49<<6) | (5<<3); 

	

	//ADCDLY = 100000;



	// AUTO_PST [2] Automatic sequencing conversion of X-Position and Y-Position  

	//	0 = Normal ADC conversion. 

	ADCTSC &= ~(1<<2);

	

	// begin X

	// XY_PST [1:0]		01 = X-position measurement  

	//			10 = Y-position measurement

	ADCTSC |= (1<<0);

	ADCTSC &= ~(1<<1);

	

	//ADCTSC |= (1<<2);

	//ADCTSC = 0xC;

	

	ADCCON |= 0x1;

	

	// µ±A/D◊™ªª’Ê’˝ø™ º ±£¨Œª[0]ª·◊‘∂Ø«Â0

	while (ADCCON & (1<<0))

		;

	

	while(!(ADCCON & (1<<15)))

		; 				//µ»¥˝A/D◊™ªªµƒΩ· ¯

	

	*x = ( (int)ADCDAT0 & 0x3ff );		//∂¡»°A/D◊™ªªµƒ ˝æ›

	

	// begin Y

	// XY_PST [1:0]		01 = X-position measurement  

	//			10 = Y-position measurement

	ADCTSC |= (1<<1);

	ADCTSC &= ~(1<<0);

	

	ADCCON |= 0x1;

	

	// µ±A/D◊™ªª’Ê’˝ø™ º ±£¨Œª[0]ª·◊‘∂Ø«Â0

	while (ADCCON & (1<<0))

		;

	

	while(!(ADCCON & (1<<15)))

		; 				//µ»¥˝A/D◊™ªªµƒΩ· ¯

	

	*y = ( (int)ADCDAT1 & 0x3ff );		//∂¡»°A/D◊™ªªµƒ ˝æ›

	

	return data;

}

上一节 | 目录索引 | 下一节

blog comments powered by Disqus