Maker Pro
Maker Pro

Help using A2D on 12f675

T

The Saccullo's

Any help in understanding how to use the A2D would be welcome. Tried this
without using interrupts but it does not work
;setup for AD
bsf STATUS,RP0 ;bank 1
movlw b'00010001' ;set IO 0 to analog, use /8 clock
movwf ANSEL
bcf STATUS,RP0 ;bank 0
movlw b'00000001' ;turn A/D on,
movwf ADCON0

TurnOnAD
movlw b'00000010' ; turn A/D on, look for input
movwf ADCON0

ADLoop
btfsc ADCON0,1
goto ADLoop

movfw ADRESH ;test value from A/D
sublw .22 ;91 dec left shifted 2
btfsc STATUS,C ;use carry bit for test
goto TurnOnAD ;less than 22 assume zero value

continue
 
N

NewsGroup

movlw b'00000001' ;turn A/D on,
movwf ADCON0
TurnOnAD
movlw b'00000010' ; turn A/D on, look for input
movwf ADCON0

ADLoop
<Snip>

The 2nd movwf ADCON0 resets the enable bit
Try changing the above to

movlw b'00000001' ;turn A/D on,
movwf ADCON0
TurnOnAD
bsf ADCON1,1; set go bit
ADLoop


This will of course only work for AN0. I also assume that you previously set
AN0 to input.

HTH

Mike.
 
N

NewsGroup

movwf ADCON0
TurnOnAD
bsf ADCON1,1; set go bit
ADLoop

Woops, Should have read

movwf ADCON0
TurnOnAD
bsf ADCON0,1; This said ADCON1
ADLoop


Mike.
 
T

The Saccullo's

Thank you. Hate it when the obvious bites. Single I/O for keypad is almost
complete.

Thanks again.
 
T

The Saccullo's

It works... Thanks again for the help. I think I now have the most complex
circuit to turn on an LED using a single I/O.
 
N

NewsGroup

The Saccullo's said:
It works... Thanks again for the help. I think I now have the most complex
circuit to turn on an LED using a single I/O.

Congratulations, I hope it inspires you to play (and learn) more.

Mike.
 
Top