Page 1 of 1

Need help:Problem in initiating comparator module (PIC16F88)

Posted: Wed Sep 13, 2006 8:28 pm
by meliasuk
I am able to compile the following C-code but keep getting error during the assembly process. What I am trying to do is to run the comparator in mode 011 (two common voltage reference) and generate output based on the comparator out. Thank you in advance.

Main Program:
// Comparator function try-out
// PIC16F88 chip

// Include external functions
#include <initclock.h>
#include <initports.h>
#include <initcomp.h>

// Main program
void main (void)
{
initclock ();
initcomp ();
initports ();

while (1)
{
// If C1INV is high
if (CMCON & 64)
{
output_low_port_b (1) ;
output_high_port_b (2) ;
}
// If C2INV is high
else if (CMCON & 128)
{
output_low_port_b (2) ;
output_high_port_b (1) ;
}
else
{
output_low_port_b (2) ;
output_low_port_b (1) ;
}
}
}

Sub-program initclock
// PIC16F88
// Initialize internal clock

#define OSCCON 0x8f

void initclock (void)
{
// Select the Register bank 1
set_bit ( STATUS, RP0 );

// Set all of OSCCON (8fh) to use internal RC clock as the system clock
// Frequency: 31.25 kHz
OSCCON = 0x0e ;

// Now use Register bank 0
clear_bit ( STATUS, RP0 );
}

Sub-program initports
// Initialize I/O ports subroutine
// PIC16F88

#define ANSEL 0x9b

void initports (void)
{
int j;

// Select the Register bank 1
set_bit ( STATUS, RP0 );

// Set RA<2:0> for inputs, RA<7:3> for outputs
TRISA = 0x07 ;

// Set RB<7:0> for output
TRISB = 0x00 ;

// Configure analog inputs
// Set AN<2:0>
ANSEL = 0x07 ;

// Select the Register bank 0
clear_bit( STATUS, RP0 );

//Clear output bits
for (j=3;j=7;j++)
{
output_low_port_a (j);
}

for (j=0;j=7;j++)
{
output_low_port_b (j);
}
}

Sub-program initcomp
// Enable comparator
// PIC16F88

#define CMCON 0x9c

void initcomp ()
{
// Select the Register bank 1
set_bit ( STATUS, RP0 );

// Enable comparator CM<2:0> = 011
CMCON = 0x03 ;

// Now use Register bank 0
clear_bit ( STATUS, RP0 );
}

Posted: Thu Sep 14, 2006 9:08 am
by Ian
Do you have the error listing from the Assembly process?
e.g. MyFile.err
If so can you post that as it may help reveal the problem.

Posted: Thu Sep 14, 2006 10:04 am
by meliasuk
Yes I do. Here's what's written in the err file. Thanks.

Error[113] C:\DOCUME~1\MARTIN~1\DESKTOP\INNOVA~1\COMPAR~1\COMPAR~1.ASM 12 : Symbol not previously defined (T0IF)

Posted: Fri Sep 15, 2006 8:58 am
by Ian
This is due to an error in the Compiler.
The T0IF is added in the default interrupt code used by the compiler, but is not defined in the includes.

Check the following post for fixes forthe problem:

http://www.matrixmultimedia.com/mmforum ... c.php?t=53