Re: A/D code on a PIC
- From: Randy Day <randy.day@xxxxxxxx>
- Date: Sun, 17 Sep 2006 15:01:03 GMT
Donkey D... wrote:
"Randy Day" <randy.day@xxxxxxxx> wrote in message
[snip]
MOVLW 0x2F ; make A0-A3,A5 analog in; A4, A6 digital out,
MOVWF TRISA
MOVLW 0x1E ; make B1-B4 analog in, B0,B5-B7 digital out,
MOVWF TRISB
CLRF TRISC ; Make PortC digital out
;======================================
; register, A/D initialization
;======================================
CLRF PORTA
CLRF PORTB
CLRF PORTC
BSF ADCON2,7 ; right justify
BSF ADCON2,4 ; set Tad = 32
BSF ADCON2,2 ; Fosc/4
MOVLW 0x03
MOVWF ADCON1 ; set inputs AN0-AN10, vrefs Vdd/Vss
goto start
ADCREAD
MOVWF ADCON0 ; set A/D to channel defined in WREG
BSF ADCON0,0 ; start conversion
CALL ONE_US
CALL ONE_US
CALL ONE_US ; wait 5us for A/D to settle
CALL ONE_US
CALL ONE_US
BSF ADCON0,1 ; set the GO bit
BTFSC ADCON0,1 ; GO bit will change to zero when the conversion is
complete
goto $-2
MOVFF ADRESH, TEMPHI
MOVFF ADRESL, TEMPLO
BCF ADCON0,0 ; turn off A/D
RETURN
START
MOVLW 0x00 ; set ADC to read AN0
CALL ADCREAD
END
Maybe "goto $-2" should be "goto $-1"
Actually, no. The '2455 is word-addressable.
$-2 takes you back to the prev instruction.
That threw me too when I went from PIC16's
to 18's. :)
.
- Follow-Ups:
- Re: A/D code on a PIC
- From: Donkey D...
- Re: A/D code on a PIC
- References:
- A/D code on a PIC
- From: Randy Day
- Re: A/D code on a PIC
- From: Donkey D...
- A/D code on a PIC
- Prev by Date: Re: A/D code on a PIC
- Next by Date: Re: A/D code on a PIC
- Previous by thread: Re: A/D code on a PIC
- Next by thread: Re: A/D code on a PIC
- Index(es):
Relevant Pages
|