Demo entry 6735816

ADC code

   

Submitted by Abhijeet Ajit on Apr 25, 2018 at 18:43
Language: C. Code size: 1.0 kB.

sbit ADC09_MUX_A = P3^5;
sbit ADC09_MUX_B = P3^4;
sbit ADC09_START = P3^3;
unsigned int ADC_Final=0;
unsigned char ADC_Data_Arr[10];
unsigned int Voltage, Volt_Temp;
unsigned int ADC09_Start( bit Mux_Addr_B, bit Mux_Addr_A );
unsigned int ADC09_Start( bit Mux_Addr_B, bit Mux_Addr_A )
{
	unsigned char i=0;
	Voltage=0;

// Selection of ADC09 input channels based on arguments
	ADC09_MUX_A = Mux_Addr_A;					
	ADC09_MUX_B = Mux_Addr_B;
//	ADC09_MUX_C = Mux_Addr_C;

	ADC_Final = 0;
	ADC_Data_Arr[2] = 0;
// Increase the loop cycle for more accuracy.
	for( i=0; i<2; i++ )
	{

		ADC09_START = 1;
		MSDelay(1);									// 1 msec delay
		ADC09_START = 0;
		MSDelay( 100 );								// 1 msec delay
	ADC_Data_Arr[i]=P0;
// P3 = ADC_Data_Arr[i];								// Testing
		ADC_Final = ADC_Final + ADC_Data_Arr[i];
	}

	ADC_Final = ADC_Final / 2;						// Do average based the loop cycles

// Following code is for Temperature Sensor LM35
	Voltage =(unsigned int)((( ADC_Final * 100.0 ) / 255.0 )*5.0);


	return Voltage;
}

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).