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.

how to make PIC16f877a comparator works?

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
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++)}


PIC.jpgPIC.jpg

what i should do to make it works? Is it i need to set the Port A as digital?
 

How about you try with cmcon=0b00000011;

and give some delay before you read out status of C2OUT, to give some time to update itself.
 

I tried but it still can't work.
I wonder do i really need the IF statement is my code or not.
Not supposedly, the C2OUT will give me the high output once it detected C2V+ is larger than C2V-??
Thanks~~
 

problem solved. It is just because i din write CMCON in capital letter. My mistake....arrghhh....never think that it is such sensitive~
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top