|
PIC16F526 Datasheet, PDF (62/122 Pages) Microchip Technology – 14-Pin, 8-Bit Flash Microcontroller | |||
|
◁ |
PIC16F526
REGISTER 9-2: ADRES: A/D CONVERSION RESULTS REGISTER
R/W-X
ADRES7
bit 7
R/W-X
ADRES6
R/W-X
ADRES5
R/W-X
ADRES4
R/W-X
ADRES3
R/W-X
ADRES2
R/W-X
ADRES1
R/W-X
ADRES0
bit 0
Legend:
R = Readable bit
-n = Value at POR
W = Writable bit
â1â = Bit is set
U = Unimplemented bit, read as â0â
â0â = Bit is cleared
x = Bit is unknown
EXAMPLE 9-1:
PERFORMING AN
ANALOG-TO-DIGITAL
CONVERSION
;Sample code operates out of BANK0
loop0
MOVLW 0xF1
;configure A/D
MOVWF ADCON0
BSF ADCON0, 1 ;start conversion
BTFSC ADCON0, 1;wait for âDONEâ
GOTO loop0
MOVF ADRES, W ;read result
MOVWF result0 ;save result
loop1
BSF ADCON0, 2 ;setup for read of
;channel 1
BSF ADCON0, 1 ;start conversion
BTFSC ADCON0, 1;wait for âDONEâ
GOTO loop1
MOVF ADRES, W ;read result
MOVWF result1 ;save result
loop2
BSF ADCON0, 3 ;setup for read of
BCF ADCON0, 2 ;channel 2
BSF ADCON0, 1 ;start conversion
BTFSC ADCON0, 1;wait for âDONEâ
GOTO loop2
MOVF ADRES, W ;read result
MOVWF result2 ;save result
EXAMPLE 9-2:
CHANNEL SELECTION
CHANGE DURING
CONVERSION
loop0
MOVLW 0xF1
;configure A/D
MOVWF ADCON0
BSF ADCON0, 1 ;start conversion
BSF ADCON0, 2 ;setup for read of
;channel 1
BTFSC ADCON0, 1;wait for âDONEâ
GOTO loop0
MOVF ADRES, W ;read result
MOVWF result0 ;save result
loop1
BSF ADCON0, 1 ;start conversion
BSF ADCON0, 3 ;setup for read of
BCF ADCON0, 2 ;channel 2
BTFSC ADCON0, 1;wait for âDONEâ
GOTO loop1
MOVF ADRES, W ;read result
MOVWF result1 ;save result
loop2
BSF ADCON0, 1 ;start conversion
BTFSC ADCON0, 1;wait for âDONEâ
GOTO loop2
MOVF ADRES, W ;read result
MOVWF result2 ;save result
CLRF ADCON0 ;optional: returns
;pins to Digital mode and turns off
;the ADC module
DS41326D-page 62
ï£ 2010 Microchip Technology Inc.
|
▷ |