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

How do I set APFCON register to change pin function w/ CCS?

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



Joined: 01 Mar 2010
Posts: 73

View user's profile Send private message

How do I set APFCON register to change pin function w/ CCS?
PostPosted: Mon Jun 21, 2010 2:48 pm     Reply with quote

I see in the Microchip datasheets where it says "Pin function is selectable via the APFCON register."

I'd like to be able to use this option with some of the CCP options and I notice there are several pins where, for example, CCP3 is listed on the PIC16F1933. It's listed under pin RB5 and pin RC6. How do I access the APFCON register in order to make this selection?

Thanks!!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jun 21, 2010 2:51 pm     Reply with quote

Use the forum's search page to find the answer in the archives.
http://www.ccsinfo.com/forum/search.php

Search for APFCON. Example of result:
http://www.ccsinfo.com/forum/viewtopic.php?t=39698&highlight=apfcon
picj1984



Joined: 01 Mar 2010
Posts: 73

View user's profile Send private message

PostPosted: Thu Jul 01, 2010 4:26 pm     Reply with quote

Thanks for the response. I've looked at that post in detail and I'm still having a little bit of trouble trying to figure this all out.

First, I should see if what I want to do is even possible.

I'm wanting to use the UART but ONLY the Rx pin. Not the Tx pin. I'd like to use that pin (Pin 17 on the PIC16F1933) as CCP3 instead.

Is this even possible?

I was hoping CCS could figure out what I wanted to do on it's own. Here's what I got at the header

Code:


#include <16f1933.h>
#fuses HS,NOLVP,NOWDT,NOPROTECT
#device ICD=TRUE
#include<stdlib.h>
#use delay(clock=16000000, int)
#use rs232(baud=31250,parity=N,stop=1,rcv=PIN_C7,bits=8)




Notice that I didn't include the xmit option since I don't want to use that pin as such

In the main() routine I got this going on

Code:


setup_timer_0(T0_INTERNAL|T0_DIV_16);
//setup_timer_1(5|0);
//setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
setup_timer_2(T2_DIV_BY_1,175,1);
enable_interrupts(GLOBAL);
enable_interrupts(INT_TIMER0);
//enable_interrupts(INT_TIMER1);
//enable_interrupts(INT_CCP1);
//enable_interrupts(INT_CCP2);

//setup_ccp2(CCP_COMPARE_INT);
setup_ccp3(CCP_PWM);
setup_ccp4(CCP_PWM);
//setup_ccp5(CCP_PWM);



This worked fine before I added in the UART stuff.


Interestingly enough, when I first added in the UART stuff I forgot to take otu the rcv option, and the UART worked fine, but obviously CCP3 wasn't working at all.

After I took the rcv option, CCP3 started working, but the UART only seems to work sporadically.

So... I'm thinking I have to do something manually in the APFCON register, but I can't figure out exactly how to do it. I know you alluded to how to do it in that last post, but I think I need more of a concrete example (as in the actual code since I'm still a bit of a newb).

Thanks so much!!

Joel
picj1984



Joined: 01 Mar 2010
Posts: 73

View user's profile Send private message

PostPosted: Thu Jul 01, 2010 4:41 pm     Reply with quote

Hmm... I'm thinking this is not possible.

I just read this on page 294 of the datasheet in the EUSART section
Quote:

Note 1:
When the SPEN bit is set the TX/CK I/O
pin is automatically configured as an
output, regardless of the state of the
corresponding TRIS bit and whether or not
the EUSART transmitter is enabled. The
PORT latch is disconnected from the
output driver so it is not possible to use the
TX/CK pin as a general purpose output.
2: If the RX/DT function is on an analog pin,
the corresponding ANSEL bit must be
cleared for the receiver to function.

So it sounds like what I'm trying to do is impossible?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jul 01, 2010 5:05 pm     Reply with quote

Quote:
#use rs232(baud=31250,parity=N,stop=1,rcv=PIN_C7,bits=8)

This is not going to create code for a hardware UART. You have to
specify both Tx and Rx to get the hardware UART code.

See this thread. Ttlemah explains how to use the Tx pin for normal i/o
while still using the Rx as a hardware UART pin:
http://www.ccsinfo.com/forum/viewtopic.php?t=35139

Another perhaps better thread by Ttelmah on this topic:
http://www.ccsinfo.com/forum/viewtopic.php?t=33676
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