Re: A/D code on a PIC



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. :)
.



Relevant Pages

  • Re: A/D code on a PIC
    ... config XINST = OFF ... MOVWF TRISA ... BSF ADCON2,2; Fosc/4 ... set A/D to channel defined in WREG ...
    (sci.electronics.basics)
  • Re: A/D code on a PIC
    ... config XINST = OFF ... MOVWF TRISA ... BSF ADCON2,2; Fosc/4 ... set A/D to channel defined in WREG ...
    (sci.electronics.basics)
  • Re: A/D code on a PIC
    ... config XINST = OFF ... MOVWF TRISA ... BSF ADCON2,2; Fosc/4 ... set A/D to channel defined in WREG ...
    (sci.electronics.basics)
  • PIC 18F4550 - EUSART does not generate interrupts
    ... movwf TRISC,ACCESS ... movlw low ... bsf PIE1,RCIE,ACCESS ... that PIC doesn't call the interrupt routine. ...
    (comp.arch.embedded)