I'm having difficulty writing a program for a tracking unit that I am building for a school project. I'm writing this in PIC with the 16F877 chip. I want it to take 2 analog inputs (pin ra0 and ra1), convert them to digital, and compare the voltages with each other. If the voltage at pin ra0 is greater than the voltage at pin ra1, I want rb1 to display a high. If the voltage at pin ra1 is greater than the voltage at pin ra0, rb0 should display a high. The following is my program. Any help would be greatly appreciated. Thanks in advance.
; PIC program for the Automatic Tracking Unit
list p=16F877
#include <P16F877.inc>
D_LEFTL equ 20h
D_LEFTH equ 21h
D_RIGHTL equ 22h
D_RIGHTH equ 23h
org 00h
GOTO MAIN
org 10h
MAIN:
BANKSEL TRISA
movlw 07
movwf TRISA
clrf TRISC
BANKSEL ADCON0
;Init_ADC
; Set ADCON0
movlw b'11000001' ;ra0 = left
movwf ADCON0
; Set ADCON1
BANKSEL ADCON1
movlw b'10000101'
movwf ADCON1
BANKSEL ADCON0
;Read_ADC
bsf ADCON0, GO_DONE ;initiate conversion
btfsc ADCON0, GO_DONE
goto $-1 ;wait for ADC to finish
movf ADRESH,W
andlw 0x03
movwf D_LEFTH
BANKSEL ADRESL
movf ADRESL,W
BANKSEL ADRESH
movwf D_LEFTL
BANKSEL ADCON0
;Init_ADC
; Set ADCON0
movlw b'11001001' ;ra1 = right
movwf ADCON0
; Set ADCON1
BANKSEL ADCON1
movlw b'10000101'
movwf ADCON1
BANKSEL ADCON0
;Read_ADC
bsf ADCON0, GO_DONE ;initiate conversion
btfsc ADCON0, GO_DONE
goto $-1 ;wait for ADC to finish
movf ADRESH,W
andlw 0x03
movwf D_RIGHTH
BANKSEL ADRESL
movf ADRESL,W
BANKSEL ADRESH
movwf D_RIGHTL
; RSSI COMPARISON
MOVF D_LEFTH, W
SUBWF D_RIGHTH, W ; W = D_RIGHTH - D_LEFTH
BTFSC STATUS, Z
GOTO EQUAL ; if D_RIGHTH = D_LEFTH
BTFSS STATUS, C
GOTO RUNLEFT ; if D_RIGHTH > D_LEFTH
GOTO RUNRIGHT ; if D_LEFTH > D_RIGHTH
EQUAL: MOVF D_LEFTL, W
SUBWF D_RIGHTL, W ; W = D_RIGHTL - D_LETL
BTFSS STATUS, C
GOTO RUNLEFT ; if D_RIGHTL > D_LEFTL
GOTO RUNRIGHT ; if D_LEFTL > D_RIGHTL
RUNLEFT:
BANKSEL TRISB
clrf TRISB
MOVLW b'00000001'
MOVWF PORTB
RUNRIGHT:
BANKSEL TRISB
clrf TRISB
MOVLW b'00000010'
MOVWF PORTB
GOTO MAIN
end