AnalogReference (EXTERNAL) undeclared?

  • Thread starter Thread starter CognitiveNet
  • Start date Start date
CognitiveNet
Messages
50
Reaction score
1
Hi! I'm trying to read the voltage( from ARef I assume) by using analogRead.
I've set analogReference to EXTERNAL, and I'm doing this in main.
Yet, I'm told that EXERNAL is undeclared. What am I doing wrong?

#include<avr/io.h>
#include<teensy_pins.h>
#include<timer0.h>
#include<util/delay.h>
#define CPU_PRESCALE(n)(CLKPR=0x80,CLKPR=(n))
#define CPU_16MHz 0x00

int main(void)
{
CPU_PRESCALE(CPU_16MHz);

// Initialize DDR
DDRC = 0x0e; // Output (Lamp Status) (Sets output to 3 pins)
DDRD = 0x00; // Input (Switch Status)

// Initialize PORT
PORTD = 0xff;
--------------------------------------------------------------------------
int analogInput = 0;
int analogAmount = ;

void setup()
{
analogReference(EXTERNAL); // use AREF for reference voltage
}


while(1)
{

analogAmount = analogRead(analogInput);

//--------------------- D4 ---------------------
if (!(PIND & 0x10))
{
PORTC = 0x0e;
_delay_ms(250);
PORTC = 0x00;
_delay_ms(250);
}
//--------------------- D5 ---------------------
if (!(PIND & 0x20))
{
PORTC = 0x0e;
}
else
{
PORTC = 0x00;
}
//----------------------------------------------
}
}
 
I wrapped your code in [ code ] [ /code ] tags (without the spaces) so that your indentation is preserved. When you post code, you should do that, too.
CognitiveNet said:
Hi! I'm trying to read the voltage( from ARef I assume) by using analogRead.
I've set analogReference to EXTERNAL, and I'm doing this in main.

Yet, I'm told that EXERNAL is undeclared. What am I doing wrong?
Is EXTERNAL a macro with a value, or are you trying to tell the compiler that analogReference is a function that is defined in an external file.

It's possible that you are missing the include file that defines EXTERNAL.
CognitiveNet said:
Code:
#include<avr/io.h>
#include<teensy_pins.h>
#include<timer0.h>
#include<util/delay.h>
#define CPU_PRESCALE(n)(CLKPR=0x80,CLKPR=(n))
#define CPU_16MHz 0x00

int main(void)
{
	CPU_PRESCALE(CPU_16MHz);

	// Initialize DDR
	DDRC = 0x0e; // Output 	(Lamp Status)	(Sets output to 3 pins)
	DDRD = 0x00; // Input	(Switch Status)

	// Initialize PORT
	PORTD = 0xff;
	--------------------------------------------------------------------------
        int analogInput = 0;
	int analogAmount = ;

	void setup()
	{
	analogReference(EXTERNAL); // use AREF for reference voltage
	}
	

	while(1)
	{

		analogAmount = analogRead(analogInput);

		//--------------------- D4 ---------------------
		if (!(PIND & 0x10))
		{
		PORTC = 0x0e;
		_delay_ms(250);
		PORTC = 0x00;
		_delay_ms(250);
		}
		//--------------------- D5 ---------------------
		if (!(PIND & 0x20))
		{
			PORTC = 0x0e;
		}
		else
		{
		PORTC = 0x00;
		}
		//----------------------------------------------
	}
}