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 CCS Technical Support

PIC16F88 Comparator Code

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








PIC16F88 Comparator Code
PostPosted: Wed Jan 20, 2010 2:25 pm     Reply with quote

Hey, I've wrote some code for a PIC16F88 that I won't be able to physically test for a few days. Just wondering if anyone could point out any errors in my code.
Basically I want to assign the result of a comparison (involving an input on RA1 and an internal vref) onto PIN B4. Conversely, if the result of the comparison is low but a switch at A4 is pressed then I want to set B4 high.
Code:

#include "16F88.h"
#fuses HS NOWDT PUT NOPROTECT NOCPD NOBROWNOUT NOIESO NOLVP NOWRT
#use delay (clock=8000000)
#byte CVRCON = 0x9D
#byte CMCON = 0x9C 

void init()
{   
set_tris_a(0x12);
set_tris_b(0x00);
setup_oscillator(OSC_8MHZ|OSC_INTRC);
setup_comparator(A0_VR_A1_VR);
cvrcon=0xC4;
cmcon=0x2;
delay_ms(5);
}

void main()
{
init();

while(1);
 {
  output_bit(PIN_B4,C2OUT);
   if(C2OUT == 0 && input(PIN_A4))
    {
     output_high(PIN_B4);
     delay_ms(5);
    }
 }
}

Any feedback is appreciated, thanks.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jan 20, 2010 3:59 pm     Reply with quote

This thread has a working demo program for the 16F88 comparator.
You can study it:
http://www.ccsinfo.com/forum/viewtopic.php?t=22955
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