Page 1 of 1

problem of using comarator in 16f88

Posted: Mon Feb 28, 2011 1:22 pm
by chenjinghall
hello, i have configured the comparator register but i have no ideas of how to read the input and output. my program is below


#include <system.h>
#include "RF transmitter.h"

void setup_hardware (void)
{
/* set all of PORTB for output */
trisb = 0x00 ;

/* bits 0-2 of PORTA for input and bit 3 of portA for output which is C1OUT */
trisa = 0x05;

/* Just A0 and A3 ( comparator voltage reference) in analogue mode */
ansel = 0x05 ;
portb=0x00;
cmcon = 0x46;

}
void main ( void )
{
int v;
setup_hardware () ;

while (1) {
what should be here ?????????????????????????????? }
}

Re: problem of using comarator in 16f88

Posted: Mon Feb 28, 2011 3:19 pm
by Benj
Hello,

To read the output from each comparator module you can use the following C code.

Code:
char compA;
char compB;

compA = (cmcon & 0x40) >> 6;
compB = (cmcon & 0x80) >> 7;

Re: problem of using comarator in 16f88

Posted: Mon Feb 28, 2011 4:51 pm
by Benj
With the way you have setup the comparators it looks like you may also be able to read the comparator output by reading input pins RA3 and RA4.

Re: problem of using comarator in 16f88

Posted: Wed Mar 02, 2011 4:01 pm
by Khalid
Ben.. I am really impressed by your knowledge and help. :shock: