problem of using comarator in 16f88

For C and ASSEMBLY users to post questions and code snippets for programming in C and ASSEMBLY. And for any other C or ASM course related questions.

Moderators: Benj, Mods

Post Reply
chenjinghall
Posts: 7
Joined: Fri Nov 26, 2010 6:45 pm
Contact:

problem of using comarator in 16f88

Post 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 ?????????????????????????????? }
}

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: problem of using comarator in 16f88

Post 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;

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: problem of using comarator in 16f88

Post 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.

Khalid
Posts: 5
Joined: Fri Feb 11, 2011 5:14 pm
Has thanked: 2 times
Been thanked: 1 time
Contact:

Re: problem of using comarator in 16f88

Post by Khalid »

Ben.. I am really impressed by your knowledge and help. :shock:

Post Reply