[Csharp]
/*************************************** **************************
** Program name: Mega_ADK ADC
** Parameter count: None
** Function: Send the voltage value (mv) collected by AD through the serial port)
** Note: The target board is Maga adk and the mcu is ATmega 2560.
** Author: Zhao Lulu
** Version: v1.0
** Modification time: 2012.8.17
**************************************** **************************/
# Define adPin A0
Void setup ()
{
Serial. begin (115200); <span style = "white-space: pre"> </span> // set the baud rate
}
Void loop ()
{
Int n = analogRead (adPin); <span style = "white-space: pre"> </span> // read the value of the simulation port, because the accuracy of ATmega 2560 AD is 10 bits, the returned value range is 0 ~ 1023
N = n * 4.888; <span style = "white-space: pre"> </span> // converts the returned value to A millivolt value.
Serial. print ("The Voltage Value is (mv ):");
Serial. println (n, DEC); <span style = "white-space: pre"> </span> // DEC sets the output data format here, which can be omitted here, see http://kb.open.eefocus.com/index.php for details? Title = Serial
Delay (100 );
}
Note: Because the accuracy of ATmega 2560 AD is 10 bits, the returned value range is 0 ~ 1023, corresponding to 0 ~ 5 V, calculate the actual voltage based on the collection value, 5000 Gb/s 1024 ≈ 4.888, So multiply the acquisition value by 4.888 to get the actual voltage value (ml V ).
If you are a newbie, please correct me.