Flowcode is a great program for people like me that want to play with PIC's but don't like the code.
Times like these when I want to use the comparator brings me back on my feet.
PIC's are much complex than what you see using Flowcode.
I was looking at the datasheet for the 16F628A
Code: Select all
FLAG_REG EQU 0X20
CLRF FLAG_REG ;Init flag register
CLRF PORTA ;Init PORTA
MOVF CMCON, W ;Load comparator bits
ANDLW 0xC0 ;Mask comparator bits
IORWF FLAG_REG,F ;Store bits in flag register
MOVLW 0x03 ;Init comparator mode
MOVWF CMCON ;CM<2:0> = 011
BSF STATUS,RP0 ;Select Bank1
MOVLW 0x07 ;Initialize data direction
MOVWF TRISA ;Set RA<2:0> as inputs
;RA<4:3> as outputs
;TRISA<7:5> always read β€0’
BCF STATUS,RP0 ;Select Bank 0
CALL DELAY10 ;10ΞΌs delay
MOVF CMCON,F ;Read CMCON to end change
;condition
BCF PIR1,CMIF ;Clear pending interrupts
BSF STATUS,RP0 ;Select Bank 1
BSF PIE1,CMIE ;Enable comparator interrupts
BCF STATUS,RP0 ;Select Bank 0
BSF INTCON,PEIE ;Enable peripheral interrupts
BSF INTCON,GIE ;Global interrupt enable
What should I use from this code to make the comparator change a variable whenever the voltage on the input is <> than the reference voltage (Vref) on a pin?
Correct me if i'm wrong, but when I want to use "Two Common Reference Comparators" I need to use this: CM<2:0> = 011
This is the configuration for two comparators with a common input.
What I can make of this code is that it generates a byte with several possibilities.
CMCON is a register where the result of the comparator is being stored?
So if I can use the value of this register I can make decisions and use it as a variable?
Is it possible to alter the code above to use in Flowcode, so I can use it in my project?
An Flowcode example would be great to start me up. With a little explanation, this would be great for everyone that want to use this feature of PIC's...
Thanks!