MikroElektronika PIC Microcontrollers PIC16 Datový list Strana 159

  • Stažení
  • Přidat do mých příruček
  • Tisk
  • Strana
    / 194
  • Tabulka s obsahem
  • ŘEŠENÍ PROBLÉMŮ
  • KNIHY
  • Hodnocené. / 5. Na základě hodnocení zákazníků
Zobrazit stránku 158
Programming PIC Microcontrollers in BASIC - mikroElektronika
' circuit; voltage is measured on RA2 and
' allows the use of AD converter
Delay_ms (500) ' 500 ms pause
eloop:
ADCON0.2 = 1 ' Conversion starts
wait:
' wait for ADC to finish
Delay_ms(5)
if ADCON0.2 = 1 then
goto wait
end if
PORTD = ADRESH ' Set lower 8 bits on port D
Delay_ms(500) ' 500 ms pause
goto eloop ' Repeat all
end. ' End of program.
First, we need to properly initialize registers ADCON1 and ADCON0. After that, we set ADCON0.2 bit which initializes
the conversion and then check ADCON0.2 to determine if conversion is over. If over, the result is stored into ADRESH
and ADRESL where from it can be copied.
Former example could also be carried out via ADC_Read instruction. Our following example uses 10-bit resolution:
program ADC_10
dim AD_Res as word
main:
TRISA = %11111111 ' PORTA is input
TRISD = %00000000 ' PORTD is output
ADCON1 = %1000010 ' PORTA is in analog mode,
' 0 and 5V are referent voltage values,
' and the result is aligned right
eloop:
AD_Res = ADC_read(2) ' Execute conversion and store result
http://www.mikroelektronika.co.yu/english/product/books/picbasicbook/06.htm (5 sur 12)05/11/2004 02:26:25
Zobrazit stránku 158
1 2 ... 154 155 156 157 158 159 160 161 162 163 164 ... 193 194

Komentáře k této Příručce

Žádné komentáře