|
|
View previous topic :: View next topic |
Author |
Message |
apwallace
Joined: 05 Dec 2003 Posts: 2
|
Basic comparator configuration |
Posted: Tue Feb 10, 2004 11:09 am |
|
|
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
|
Problem now fixed. Problem with CCS definition. |
Posted: Tue Feb 10, 2004 11:49 am |
|
|
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);
}
} |
|
|
|
|
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
|