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

how to disable C2OUT on pin RA5 with CCS C code? (PIC16F887)

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



Joined: 11 Feb 2008
Posts: 13

View user's profile Send private message

how to disable C2OUT on pin RA5 with CCS C code? (PIC16F887)
PostPosted: Sun Feb 24, 2008 3:56 pm     Reply with quote

On a PIC16F887 I want to use RA5 as an output, but I can't figure out how to either disable Comparator 2 or stop the routing of C2OUT to the same pin as RA5. I know I need to to set C2OE to zero in the CM2CON0 register so that C2OUT is not put onto the RA5 pin (and maybe set C2ON to zero as well to disable the comparator), and running the MPLAB SIM debug I can see that they are both set to one. Not sure how to accomplish this in C code with the CCS PCM compiler, however.

Here's my sample code:

Code:
#include <16F887.h>     
 
#FUSES INTRC_IO,NOWDT,NOPUT,NOMCLR,NOPROTECT,NOCPD,NOBROWNOUT,NOIESO,NOFCMEN,NOLVP

int16 ms;
int8  out_a=0xFF;

#INT_TIMER0
void TIMER0_ISR(void)
{
   SET_TIMER0(131);

   ms++;
   
   if (ms>=1000)
   {
      ms=0;
      out_a^=0xFF;
      OUTPUT_A(out_a);
   }
}



void main()
{
   SETUP_OSCILLATOR(OSC_8MHZ);
   SETUP_TIMER_0(RTCC_INTERNAL|RTCC_DIV_16);
   ENABLE_INTERRUPTS(INT_TIMER0);
   ENABLE_INTERRUPTS(GLOBAL);
   SET_TRIS_A(0x00);

   ms=0;   
   OUTPUT_A(out_a);

   while(1);
}   
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Feb 24, 2008 4:01 pm     Reply with quote

Post your compiler version. (always do this)
bmoore



Joined: 11 Feb 2008
Posts: 13

View user's profile Send private message

PostPosted: Sun Feb 24, 2008 4:05 pm     Reply with quote

PCM programmer wrote:
Post your compiler version. (always do this)


PCMDB2k 2.22.01.15
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Feb 24, 2008 4:11 pm     Reply with quote

That's not a version. Version numbers are in this format: x.xxx
See the CCS versions page for examples.
http://www.ccsinfo.com/devices.php?page=versioninfo

You can find the version by looking at the top of the .LST file for your
project. You can find that file in your project directory.
bmoore



Joined: 11 Feb 2008
Posts: 13

View user's profile Send private message

PostPosted: Sun Feb 24, 2008 4:17 pm     Reply with quote

My bad.

CCS PCM C Compiler, Version 4.020b
bmoore



Joined: 11 Feb 2008
Posts: 13

View user's profile Send private message

PostPosted: Sun Feb 24, 2008 4:46 pm     Reply with quote

I used

#BYTE CM2CON0=0x108

and

CM2CON0 &= 0x11011111;

to set C2OE low, and pin RA5 now works fine as an output. I'm still left wondering why direct manipulation of the CM2CON0 register was necessary, however.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Feb 24, 2008 4:49 pm     Reply with quote

The start-up code in your version of the compiler is incorrect with
regard to the comparator initialization. You can fix this by inserting
this line of code before you enable interrupts. This function works
correctly in your version.
Code:
setup_comparator(NC_NC_NC_NC);
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