Why the comparator in pic 16F877A will loop by itself?

Status
Not open for further replies.

kevan

Newbie level 4
Joined
Mar 18, 2011
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,330
I would like to use the comparator in the pic. But the problem is, I don't want it to be function all the time, I only want it to be on when i need it. The problem i face is, it will loop back itself causing the LED to blink... i wonder why.

#include <pic.h>
__CONFIG(0x3F32);

#define _XTAL_FREQ 4000000
#define LED RA5
//void set (void);
//void off (void);

void main (void)
{
TRISA=0b00001111; //set pin0 to pin3 as input
PORTA=0x00; //clear all
CVRCON=0x00; //voltage reference off
CMCON=0b00000011;// comparator with output

if (C2OUT==1) //if c2V+ bigger than C2V-
{__delay_ms(5000);}
else
{
TRISA=0b00100000;
PORTA=0x00; //clear all
CVRCON=0x00;
CMCON=0b00000111; //off the comparator
__delay_ms(2000);
}
TRISA=0b00100000;
PORTA=0x00; //clear all
CVRCON=0x00;
CMCON=0b00000111;// off the comparator
__delay_ms(1000);
}
 

The exact question is, how am I going to off the comparator until it receives the next command asking it to function again???
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…