Mikroelektronika MIKROE-350 Datenbogen
![Mikroelektronika](https://files.manualsbrain.com/attachments/e0529b3b58069a916ad7bb89f7e9f5f0eda73421/common/fit/150/50/1b07b99aa3112e022a916b06db07f1f4f211e91d41878452d87c7638b1bf/brand_logo.gif)
ADC LIBRARY
ADC (Analog to Digital Converter) module is available with a number of AVR micros. Library func-
tion
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]
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.
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