View previous topic :: View next topic |
Author |
Message |
bmoore
Joined: 11 Feb 2008 Posts: 13
|
how to disable C2OUT on pin RA5 with CCS C code? (PIC16F887) |
Posted: Sun Feb 24, 2008 3:56 pm |
|
|
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
|
|
Posted: Sun Feb 24, 2008 4:01 pm |
|
|
Post your compiler version. (always do this) |
|
|
bmoore
Joined: 11 Feb 2008 Posts: 13
|
|
Posted: Sun Feb 24, 2008 4:05 pm |
|
|
PCM programmer wrote: | Post your compiler version. (always do this) |
PCMDB2k 2.22.01.15 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Feb 24, 2008 4:11 pm |
|
|
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
|
|
Posted: Sun Feb 24, 2008 4:17 pm |
|
|
My bad.
CCS PCM C Compiler, Version 4.020b |
|
|
bmoore
Joined: 11 Feb 2008 Posts: 13
|
|
Posted: Sun Feb 24, 2008 4:46 pm |
|
|
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
|
|
Posted: Sun Feb 24, 2008 4:49 pm |
|
|
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); |
|
|
|
|