pic comparator

Status
Not open for further replies.

Joe G

Member
I've been trying to figure this chips comparator out for a LDR day/nite detector. I've used the comparator on 16f628 chips awhile ago, but I noticed some of the registors are differant. I can't get the VRCON to output a ref voltage or get the comparators to even switch. I have a LDR and a resistor divider into pin A0 and still did not work. could someone check this piece of code to see if I set it up correctly.

#include <p16F690.inc>

__config (_INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _BOR_OFF & _IESO_OFF & _FCMEN_OFF )
;---------------------------------------------------------------------------------------
org 0
goto Start
org 0x0004
;------------------------------------------------------------------------------------------
ISR:
movwf W_Save
movf STATUS,w
movwf STATUS_Save

btfss PIR2, 5
goto ExitISR
BANKSEL CM1CON0
btfss CM1CON0, 6
goto nite
BANKSEL PORTA
bsf PORTC, 5 ;led
bsf day_nite, 1
goto ExitISR
nite:
BANKSEL PORTA
bcf day_nite, 1
bcf PORTC, 5 ;led

ExitISR:
bcf PIR2, 5
movf PORTA, f ;read before we can clear the flag
bcf INTCON, 0
movf STATUS_Save,w
movwf STATUS
swapf W_Save,f
swapf W_Save,w
retfie

;====================
Start:
clrf ADCON0
clrf PORTC
clrf PORTB
clrf T1CON
BANKSEL CM1CON0
movlw b'10000000'
movwf CM1CON0
movwf CM2CON0
clrf CM2CON1
movlw b'10001000' ;
movwf VRCON ;HIGH RANGE, 1/2 VDD= 2.5/2=1.25v
movlw b'01110111'
movwf ANSEL ;0,1,2= comparitor,,,,,4,5,6 for A2d conv
clrf ANSELH
BANKSEL TRISA
movlw b'11111111'
movwf TRISA ; Make PortA all input
clrf TRISB
movlw B'10000111'
movwf TRISC ;bits 0,1,2 =AN4 thru AN6, bit7= limit switch
bsf PIE2, 5 ;cm1con int-en
movlw B'00001111' ;set for WDT prescaler
movwf OPTION_REG
call Delay201us

BANKSEL PORTC
movlw B'11000000' ; enable Timer 0 and global interrupts 3=ioca en
movwf INTCON
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…