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 );
}
Need help:Problem in initiating comparator module (PIC16F88)
-
- Posts: 110
- Joined: Thu Sep 29, 2005 10:53 am
- Location: Matrix Multimedia
- Been thanked: 1 time
- Contact:
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
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