Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

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);
} compp.jpg
 

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

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top