Datasheet

ADC LIBRARY
ADC (Analog to Digital Converter) module is available with a number of AVR micros. Library func-
tion 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
dim adc_rd as word
main:
DDRB = 0xFF ' Set PORTB as output
DDRC = 0xFF ' Set PORTC as output
while TRUE
temp_res = 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]
wend
end.
170
MIKROELEKTRONIKA - SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Libraries
mikroBasic PRO for AVR
CHAPTER 6
Prototype
sub function ADC_Read(dim channel as byte) as 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 conver-
sion.
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
dim tmp as word
...
tmp = ADC_Read(2) ' Read analog value from channel 2