Datasheet
ADC LIBRARY
ADC (Analog to Digital Converter) module is available with a number of AVR micros. Library function
ADC_Read is included to provide you comfortable work with the module in single-ended mode.
ADC_Read
Library Example
This example code reads analog value from channel 2 and displays it on PORTB and PORTC.
program ADC_on_LEDs;
var adc_rd : word;
begin
DDRB := 0xFF; // Set PORTB as output
DDRC := 0xFF; // Set PORTC as output
while TRUE do
begin
adc_rd := ADC_Read(2); // get ADC value from 2nd channel
PORTB := adc_rd; // display adc_rd[7..0]
PORTC := Hi(adc_rd); // display adc_rd[9..8]
end;
end.
185
MIKROELEKTRONIKA - SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Libraries
mikroPASCAL PRO for AVR
CHAPTER 6
Prototype
function ADC_Read( channel : byte ) : word;
Returns 10-bit or 12-bit (MCU dependent) unsigned value from the specified channel.
Description
Initializes AVR ’s internal ADC module to work with XTAL frequency prescaled by
128. Clock determines the time period necessary for performing A/D conversion.
Parameter
channel represents the channel from which the analog value is to be
acquired. Refer to the appropriate datasheet for channel-to-pin mapping.
Requires Nothing.
Example
var tmp : word;
...
tmp := ADC_Read(2); // Read analog value from channel 2
Library Example