kevan
Newbie level 4
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);
}
#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);
}