CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Basic comparator configuration

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
apwallace



Joined: 05 Dec 2003
Posts: 2

View user's profile Send private message Visit poster's website

Basic comparator configuration
PostPosted: Tue Feb 10, 2004 11:09 am     Reply with quote

Hello,
I am trying to get the most basic comparator program working. I do not require interrupts for this. From reading things, all I should have to do is:

setup_comparator(A0_A2_A1_A2);

And then, I should just be able to use C1OUT and C2OUT as variables in my program. They should toggle to 1 or 0 as appropriate.

However, I'm never getting either to toggle regardless of the different analog voltages I apply on the pins.

I've pasted the relevant section of my code below.

I definitely appreciate your help.
Thanks,
Andy Wallace


Processor 16F87
MPLAB ICD2




#include <16F87.h>
#fuses NOWDT, NOPUT, MCLR, NOBROWNOUT, NOLVP, NOCPD, NOWRT, CCPB3, NOPROTECT, INTRC, NODEBUG
#use delay(clock=4000000)
#device ICD=TRUE

void backlight(int1 blstatus)
{
//backlight status 1=ON, 0=OFF
//ON-->output 0 Volts
//OFF-->output 5 Volts
if (blstatus==1){
output_low (PIN_A6); //A3 and A6 tied together to drive Backlight
output_low (PIN_A3);
}
else {
output_high (PIN_A6);
output_high (PIN_A3);
}
}


void main() {

int lcdadd,cond, seg;
int percentfill, segout, segfill, condition, delay,cnt,pfill_out,delaycnt;
char c;

int1 blstatus; //backlight =1 for ON, 0 for OFF
blstatus=0; //initialization only

setup_oscillator(OSC_INTRC|OSC_4MHZ);
set_tris_a (0b00000111); //Configures all as output
set_tris_b (0b00000001);
port_b_pullups(TRUE);

setup_comparator(A0_A2_A1_A2);
//setup_comparator(NC_NC_A1_A2);

while(1)
{
backlight(1);
delay_ms(1000);
backlight(0);
delay_ms(1000);

while(C1OUT){}

backlight(1);
delay_ms(500);
backlight(0);
delay_ms(500);
backlight(1);
delay_ms(500);
backlight(0);
delay_ms(500);
backlight(1);
delay_ms(500);

}
}
apwallace



Joined: 05 Dec 2003
Posts: 2

View user's profile Send private message Visit poster's website

Problem now fixed. Problem with CCS definition.
PostPosted: Tue Feb 10, 2004 11:49 am     Reply with quote

Upon looking at the LST file. It appears to be simply pointing at the wrong register.

I did the manual configuration below, without using the setup_comparator() function. It now works properly.

Andy


#include <16F87.h>
#device ICD=TRUE

#fuses NOWDT, NOPUT, MCLR, NOBROWNOUT, NOLVP, NOCPD, NOWRT, CCPB3, NOPROTECT, INTRC, NODEBUG
#use delay(clock=4000000)


#byte sfr_cmcon =0x9c
#byte sfr_pie2=0x8d //peripheral interupt enable register
#bit myCMIE =0x8d.6 //comparator enable enable

#bit myC1OUT = 0x9c.6
#bit myC2OUT = 0x9c.7

void backlight(int1 blstatus)
{
//backlight status 1=ON, 0=OFF
//ON-->output 0 Volts
//OFF-->output 5 Volts
if (blstatus==1){
output_low (PIN_A6); //A3 and A6 tied together to drive Backlight
output_low (PIN_A3);
}
else {
output_high (PIN_A6);
output_high (PIN_A3);
}
}


void main() {

int lcdadd,cond, seg;
int percentfill, segout, segfill, condition, delay,cnt,pfill_out,delaycnt;
char c;

int1 blstatus; //backlight =1 for ON, 0 for OFF

myCMIE=0;
sfr_cmcon=03;

blstatus=0; //initialization only
setup_oscillator(OSC_INTRC|OSC_4MHZ);
set_tris_a (0b00000111);
set_tris_b (0b00000001);
port_b_pullups(TRUE);

//setup_comparator(A0_A2_A1_A2);
//setup_comparator(NC_NC_A1_A2);


while(1)
{
backlight(1);
delay_ms(1000);
backlight(0);
delay_ms(1000);

while(myC1OUT){}

backlight(1);
delay_ms(500);
backlight(0);
delay_ms(500);
backlight(1);
delay_ms(500);
backlight(0);
delay_ms(500);
backlight(1);
delay_ms(500);

}
}
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group