Get Vcc voltage without AnalogIn-pin?

Is there a way to do an "AnalogRead" on the Vcc? Effectively saving one AnalogInput port for other tasks?

Motivation:
I want to have a "clean shutdown" procedure of my program in case the battery voltage Vcc drops under a certain value. I setup up a voltage divider and connected it to one of the AnalogIn pins. When the measured value is below a certain threshold I save some data to the connected SD / EEPROM.

But why waste one of the I/O pins? Is there some way to compare Vcc directly with the internal reference voltage?

Or is there even some other way of executing code when the brown-out detection gets active?

Sweet, just what I needed. Thank you!

On a second thought:
The code from the link above (http://www.instructables.com/id/Secret-Arduino-Voltmeter/, and copied below) changes what voltage is used as reference.
Is this only temporary or would a call of "AnalogRead" also be affected?

long readVcc() {
  // Read 1.1V reference against AVcc
  // set the reference to Vcc and the measurement to the internal 1.1V reference
  #if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
    ADMUX = _BV(REFS0) | _BV(MUX4) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
  #elif defined (__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)
     ADMUX = _BV(MUX5) | _BV(MUX0) ;
  #else
    ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
  #endif  
 
  delay(2); // Wait for Vref to settle
  ADCSRA |= _BV(ADSC); // Start conversion
  while (bit_is_set(ADCSRA,ADSC)); // measuring
 
  uint8_t low  = ADCL; // must read ADCL first - it then locks ADCH  
  uint8_t high = ADCH; // unlocks both
 
  long result = (high<<8) | low;
 
  result = 1125300L / result; // Calculate Vcc (in mV); 1125300 = 1.1*1023*1000
  return result; // Vcc in millivolts
}

On a second thought:
The code from the link above (http://www.instructables.com/id/Secret-Arduino-Voltmeter/, and copied below) changes what voltage is used as reference.
Is this only temporary or would a call of "AnalogRead" also be affected?

A call to the function long readVcc() just gets a return of of a number like 4090 or 5096. It is a measurment, and does not change anything. How you use this more precise measurment of Vcc, instead of the standard value of 5000 for Vcc, is up to you.

I have used it to improve the accuracy of a TMP36 temperature sensor with

(analogRead(pin) * (readVcc()/1024000.0))

When the measured value is below a certain threshold I save some data to the connected SD / EEPROM.

If you presently have a routine which does this for you, you should be able to test if readVcc() will work in the same manner.

Of course readVcc() returns just a number. But I don't understand what these commands do.

ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
ADCSRA |= _BV(ADSC); // Start conversion

In particular, do they conflict with this one where the reference voltage for AnalogRead measurements can be chosen:

analogReference(INTERNAL); // or DEFAULT or EXTERNAL

So would a program
analogRead on Pin x --> returns some value A
readVcc --> returns Vcc
analogRead on Pin x --> returns value B

give out identical values for A and B? Assuming of course, that the input voltage did not change.

ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
ADCSRA |= _BV(ADSC); // Start conversion

Here's my understanding of this code.
_BV(REFS0) tell the processor to use Vcc as the top end reference voltage for the 0-1023 ADC counts. This is equivalent to analogReference(DEFAULT).

Thus, readVcc() will not be using the external Aref or the internal 1.1 v reference, If you need to use either of these in your sketch you will have to reset the reference with

analogReference(XX) INTERNAL or EXTERNAL

Setting the three analog channel selection MUX1/2/3 bits are the magic instructions which tell the processor to read the internal bandgap reference voltage 1.1v

The start conversion tell the process to read and convert the 1.1 band gap voltage to a number between 0-1023. You should get a number close to 225. The rest of the math in the sketch just references the observed number to what it would be if 1.1v were 1023 and corrects Vcc to that factor.

So would a program
analogRead on Pin x --> returns some value A
readVcc --> returns Vcc
analogRead on Pin x --> returns value B

give out identical values for A and B? Assuming of course, that the input voltage did not change.

The answer to your question is dependent upon the reference for analogRead. If you are using Vcc (DEFAULT) analogRead() will not change. If you want to use EXTERNAL or INTERNAL as the reference I think you will have to explicitly set them after using readVcc().

This may help...
http://forum.arduino.cc/index.php?topic=38119.0