View previous topic :: View next topic |
Author |
Message |
Stygian
Joined: 26 Apr 2011 Posts: 13
|
PIC16F1938 setup in CCS? |
Posted: Tue Feb 28, 2012 5:30 am |
|
|
Hello All!
I have a PIC16F1938. I want to use the RS232 and the CCP3(as a PWM) "at the same time". How can I diable the CCP3 on port C6 and enable on B5?
Is this possible?
Thanks for the helps,
Stygian |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9172 Location: Greensville,Ontario
|
|
Posted: Tue Feb 28, 2012 6:42 am |
|
|
What does the datasheet say about those peripherals ?? |
|
![](templates/subSilver/images/spacer.gif) |
Stygian
Joined: 26 Apr 2011 Posts: 13
|
|
Posted: Tue Feb 28, 2012 6:54 am |
|
|
The datasheet says:
"Pin functions can be moved using the APFCON register."
How can i use APFCON in CCS? |
|
![](templates/subSilver/images/spacer.gif) |
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
APFCON register |
Posted: Tue Feb 28, 2012 7:40 am |
|
|
You should not have to drive APFCON directly.
All the necessary syntax etc. is supposed to be in the 16F1938.h file.
For a newish chip, CCS may not have got round to it.
In that case, you contact them, if you have a valid licence.
As a work round, you can create a definition which includes the register address so that you can write to it directly.
It's not recommended to write directly to registers as your code is not then very portable. You may also find yourself with conflict issues.
Mike |
|
![](templates/subSilver/images/spacer.gif) |
Stygian
Joined: 26 Apr 2011 Posts: 13
|
|
Posted: Tue Feb 28, 2012 8:04 am |
|
|
Dear Mike!
You mean i can call it from the .h file? Cause I found someting in it:
Code: |
[b]#define CCP3_B5 0x100[/b]
|
So I only have to define it in the main.h?
Thanks,
Stygian |
|
![](templates/subSilver/images/spacer.gif) |
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Tue Feb 28, 2012 9:33 am |
|
|
Sorry, I think we may have got our lines crossed.
When you compile for a PICxxFxxx you do a #include <xxfxxx.h> at the top of your program.
I believe the xxfxxx.h file tells the compiler which instructions are valid for the device you are using.
You can read the .h file with say notepad. When you look at the file you will find ALL the valid options for your chosen processor. It''s all there in plain text. I find that CCS is not entirely consistent with its syntax across all devices. (Underscores etc appear in random places.) The right .h file gives you the exact form for your device.
You originally asked about APFCON
From the data sheet the APFCON is at address 0x11D.
So, you put something like this near the top of your program
#byte APFCON = 0x11d
You can then control APFCON directly as though it were memory.
You may have to play with some other registers to get the result you want. Like I said, you may get some register interaction. The normal CCS method usually looks after such things.
I use MPLAB SIM which allows me to observe what my code has done to the registers.
I don't have a current licence, recent compiler, or 16F1938's so can't help you with specific detail.
I hope I've given you a guide.
Mike |
|
![](templates/subSilver/images/spacer.gif) |
Stygian
Joined: 26 Apr 2011 Posts: 13
|
SLOVED |
Posted: Wed Feb 29, 2012 5:07 am |
|
|
Thank You Mike!
You give Me the guide what I need .
Thank you once again!
For thoes who want someting like this I post it here:
Code: | #byte APFCON = 0x11d //use datasheet for details
void main()
{
APFCON = 0bxxxxxxxx; /* The "x" is 0 or 1 please use the datasheet for configuration. In my case I have to use this config: APFCON = 0b01000000;*/
//Your source code from here or other configuration options...
} |
Best Regards,
Stygian |
|
![](templates/subSilver/images/spacer.gif) |
gpsmikey
Joined: 16 Nov 2010 Posts: 588 Location: Kirkland, WA
|
|
Posted: Wed Feb 29, 2012 9:47 am |
|
|
Be aware of the fact that the .h file may NOT list all the options for a particular processor. I ran into this a while back with the 18F14k22 - the options specified in the data sheet to set the voltage reference for the A/D converter were NOT all listed. I did notify CCS of the problem and they acknowledged my information, but I have no idea if they have fixed it yet (they had not last time I looked and I don't have the current compiler). I ended up setting the configuration register myself (I wanted to use the internal reference in that chip).
mikey _________________ mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3 |
|
![](templates/subSilver/images/spacer.gif) |
|