Mikroelektronika MIKROE-724 データシート

ページ / 726
246
mikoBasic PRO for dsPIC30/33 and PIC24
MikroElektronika
ADC_Set_Active
Prototype
sub procedure ADC_Set_Active(dim adc_gs as ^TADC_Get_Sample)
Description Sets active ADC module.
Parameters Parameters:
adc_gs
: ADCx_Get_Sample handler. 
Returns
Nothing.
Requires
Routine is available only for MCUs with multiple ADC modules.
Used  ADC  module  must  be  initialized  before  using  this  routine.  See  ADCx_Init  and  ADCx_Init_
Advanced routines.
Example
‘ Activate ADC2 module
ADC_Set_Active(@ADC2_Get_Sample)
Notes
None.
Library Example
This code snippet reads analog value from the channel 1 and sends readings as a text over UART1.
Copy Code To Clipboard 
program ADC_on_LEDs
dim ADCresult as word
    txt as char[6]
main:
  PORTB = 0x0000       ‘ clear PORTB
  TRISB = 0xFFFF       ‘ PORTB is input
  ADC1_Init()          ‘ Enable ADC module
  UART1_Init(9600)     ‘ Initialize UART communication
  while TRUE
    ADCresult = ADC1_Get_Sample(1)   ‘ Acquire ADC sample
    WordToStr(ADCresult, txt)        ‘ convert its value to string
    UART1_Write_Text(txt)            ‘ and send it to UART terminal
    Delay_ms(50)
  wend
end.