I'm trying to set and use the comparators in the PIC16F628.
I have been reading the PIC16F628 data sheet for quit a while, and I followed almost exactly all their guidelines but the code doesn't work. Things aren't as straightforward as one expects. I have the feeling one has to figure out and find implicit information though barely implied!
Unfortunatelly Nigel Goodwin's tutorials all turn off the comparators.
Is anybody experienced with them who can help me get them to function?
Here are two versions of the code, both paralysed! Please have a look at them and try to help me generously. I'd appreciate that.
I just opened the first attachment and can't see how your code gets executed, you have org 0 and then nothing. At reset your code is going to execute your ISR and then return to some unidentified location.
Try adding,
Code:
ORG 0x00
[COLOR="blue"]goto Start[/COLOR]
ORG 0x04
movwf W_COPY ;save W register
swapf STATUS, W
movwf S_COPY ;save STATUS register
MOVLW b'11111111'
MOVWF PORTB
CALL Delay
CLRF PORTB
CALL Delay
SWAPF S_COPY, W
MOVWF STATUS ; STATUS BACK
SWAPF W_COPY, F ;
SWAPF W_COPY, W ; W BACK
RETFIE
[COLOR="Blue"]Start[/COLOR]
;comparator initialisation
CLRF FLAG_REG ;initialise flag register
CLRF PORTA ;initialise portA
MOVF CMCON,W ;load comparator bits
See what difference that makes and post the results.