aljamri
Member
Hi,
I'm doing 12F675 from this link:
Using the built in 12F675 Comparator.
Following, is the code:
The code works fine using the provided circuit. Then I've replaced the comparator Potentiometer VR1 with a 10k resistor in series with LDR. The circuit still works fine, The output LED D1 stays OFF, and when LDR covered, It turns ON.
I have few questions regarding the comparator and the code and here is the first:
Trying to measure my understanding, I've tried to reverse the D1 ON/OFF status by , changing CMCON command from 0x01 to ox81 ( changed Bit6 COUT from 0 to 1 ).
When programmed the PIC, the operation does not changed. What do you think is wrong?
I'm doing 12F675 from this link:
Using the built in 12F675 Comparator.
Following, is the code:
Code:
// Definitions
#define COMPARATOR_OP 2
#define LED 4
///////////////////////////////////////////////////////
void init_ports(void) {
//GP0 & GP1 are inputs
TRISIO = 0 | (1<<GP0) | (1<<GP1); // 0 - op, 1 - ip
ANSEL = (1<<GP0) | (1<<GP1); ; // Ana. ip on GP0 GP1
}
///////////////////////////////////////////////////////
void init_comparator(void) {
// Comparator with external input and output.
// Cout = 0 (comparator output), Cinv =0 (inversion)
[COLOR="#ff0000"][B]CMCON = 0x01;[/B][/COLOR]
}
///////////////////////////////////////////////////////
// Start here
void main() {
int i;
init_ports();
// Show device is active on power up.
for (i=0;i<5;i++) {
GPIO |= (1<<COMPARATOR_OP);
delay_ms(100);
GPIO &= ~(1<<COMPARATOR_OP);
delay_ms(100);
}
init_comparator();
while(1) {;
GPIO |= (1<<LED);
delay_ms(100);
GPIO &= ~(1<<LED);
delay_ms(100);
}
}
The code works fine using the provided circuit. Then I've replaced the comparator Potentiometer VR1 with a 10k resistor in series with LDR. The circuit still works fine, The output LED D1 stays OFF, and when LDR covered, It turns ON.
I have few questions regarding the comparator and the code and here is the first:
Trying to measure my understanding, I've tried to reverse the D1 ON/OFF status by , changing CMCON command from 0x01 to ox81 ( changed Bit6 COUT from 0 to 1 ).
When programmed the PIC, the operation does not changed. What do you think is wrong?