kevan
Newbie level 4
Hi, I am new in PIC and I am trying hard to figure out how to make the comparator in PIC 16F877a to work.
This is my code
#include <pic.h>
__CONFIG(0x3F32)
void delay(void);
int i;
void main (void)
{
TRISA=0b00001111; //set pin0 to pin3 as input
PORTA=0x00; //clear all
cvrcon=0x00; //voltage reference off
cmcon=0b00001011; //two independent comparators with outputs
if (C2OUT==1) // voltage at pin RA2 is larger than RA1
{
RA5=1; //activate the LED connected at pin RA5
}
end
}
void delay(void)
{for(i=0;i<2000;i++)}
what i should do to make it works? Is it i need to set the Port A as digital?
This is my code
#include <pic.h>
__CONFIG(0x3F32)
void delay(void);
int i;
void main (void)
{
TRISA=0b00001111; //set pin0 to pin3 as input
PORTA=0x00; //clear all
cvrcon=0x00; //voltage reference off
cmcon=0b00001011; //two independent comparators with outputs
if (C2OUT==1) // voltage at pin RA2 is larger than RA1
{
RA5=1; //activate the LED connected at pin RA5
}
end
}
void delay(void)
{for(i=0;i<2000;i++)}
what i should do to make it works? Is it i need to set the Port A as digital?