View previous topic :: View next topic |
Author |
Message |
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
TRIS Question |
Posted: Fri Jan 11, 2013 3:06 pm |
|
|
Hi All,
I was looking at the CCS manual and something is not quite clear:
Quote: | get_tris_x() : Returns 16bit value of tris Reg.
set_tris_x(value) : where value is an 8 bit int for each bit of the io port. |
where do the additional 8 bits come from? are the special function registers NOT 8 bit?
anyways, i was wondering if someone could confirm if the following is possible:
i have i.e. Pin_B1 with a pullup set low via: Code: | output_low(PIN_B1); |
Can i make the pin high by changing the TRIS bit to an INPUT? without using: Code: | output_high(PIN_B1); |
from my understanding of the Datasheet I/O port diagram this is completely feasable.
this should hold true regardless of a prior statement to output the pin low after the tris bit has been set to input...
right?
G. _________________ CCS PCM 5.078 & CCS PCH 5.093 |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19375
|
|
Posted: Fri Jan 11, 2013 3:20 pm |
|
|
You are reading the PCD manual.
On the PIC24 and up, these registers are 16bit.
On the pcw manual, the line reads:
"value is an 8 bit int with each bit representing a bit of the I/O port."
Possibly you are being caught by the current really annoying feature of the last few compilers, where the manual sometimes incorrectly switches to the one for the wrong chip. I persistently find when you select pcd, it keeps using the pch manual, and vice versa....
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Jan 11, 2013 3:21 pm |
|
|
The June 2012 PCW manual (PDF file) does say "returns int16".
CCS apparently copied and pasted that entry from the PCD manual.
It used to refer to a byte as the return value in older versions of
the PCW manual.
Quote: | Can i make the pin high by changing the TRIS bit to an INPUT ? | You could use
Code: | output_float(PIN_B1); |
That would set the TRIS on pin B1 to be an input. Then it would be
pulled up to a high level by your pull-up resistor. |
|
![](templates/subSilver/images/spacer.gif) |
bkamen
Joined: 07 Jan 2004 Posts: 1611 Location: Central Illinois, USA
|
|
Posted: Fri Jan 11, 2013 4:46 pm |
|
|
Any time you use the "output_xxxx();", it will most likely (if you're NOT using #use FAST_IO) generate code to make a pin an OUTPUT. (driven, not floating with a pull-up/down)
Otherwise, to be consistent, I would never consider "output_xxx" to be a command where I'd want to set up a pin for input purposes. OUTPUT == Driven and not floating.
So as others have already mentioned, make the pin an input (which will probably default to floating, I'd have to check) and THEN also set the pull-up/down's as appropriate.
Honestly, I usually build a structure and then overlay the port-mapping against a LATC register as needed.
Then I have a structure with discrete direction settings that are then applied against the TRIS.
in cases were I want/need pullup/down resistors, I then have another const structure for that as well.
It's a little more work - but lends to the code "documenting itself" which ends up being a benefit in the long run.
-Ben _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Jan 11, 2013 5:09 pm |
|
|
Your objection is to CCS's choice of function names. Perhaps they
should have used names such as:
pin_low()
pin_high()
pin_float() |
|
![](templates/subSilver/images/spacer.gif) |
bkamen
Joined: 07 Jan 2004 Posts: 1611 Location: Central Illinois, USA
|
|
Posted: Fri Jan 11, 2013 5:38 pm |
|
|
PCM programmer wrote: | Your objection is to CCS's choice of function names. Perhaps they
should have used names such as:
pin_low()
pin_high()
pin_float() |
I'm not sure if this email is for me as I don't object at all to CCS's choice of function names.
I find them to be quite clear in their objective.
But if it's for the original poster, I would still assert the CCS choices make code somewhat self documenting.
I just like building those structures because they explicitly fill in how the world is connected to the PIC.
Cheers,
-Ben _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19375
|
|
Posted: Sat Jan 12, 2013 1:44 am |
|
|
PCM programmer wrote: | The June 2012 PCW manual (PDF file) does say "returns int16".
CCS apparently copied and pasted that entry from the PCD manual.
It used to refer to a byte as the return value in older versions of
the PCW manual.
Quote: | Can i make the pin high by changing the TRIS bit to an INPUT ? | You could use
Code: | output_float(PIN_B1); |
That would set the TRIS on pin B1 to be an input. Then it would be
pulled up to a high level by your pull-up resistor. |
Interesting. The internal IDE manual for the compiler if the right chip is selected, still says int8.
CCS, seem to be trying to slowly 'combine' the manuals, presumably intending to add a line like:
"except on the PIC10/10/16/18, where an int8 is returned", but not having yet got round to doing this.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
|
Posted: Sat Jan 12, 2013 9:59 am |
|
|
Hi all, Thanks for your replies.
Seems like indeed there is some issues with the manual...
Related to the tris issue:
What i am trying to accomplish is actually quite simple...
Its a signal between 2 pics... the line is held up by pull up... one pic has control over the line by driving it low... which it then releases by NOT driving it and letting the pull up do its job, which then THE OTHER pic drives low briefly to acknowledge.... no more than that.
Just trying to save a pin on a signal line...
I think i will try the suggestion... seems to confirm what i have in mind...
Thank you all!
G. _________________ CCS PCM 5.078 & CCS PCH 5.093 |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9176 Location: Greensville,Ontario
|
|
Posted: Sat Jan 12, 2013 10:09 am |
|
|
CCS has given an example of that PIC2PIC communication setup!
In the comomon Q&A section...
What is an easy way for two or more PICsĀ® to communicate?
Also they supply the code in the 'examples' folder !!
hth
jay |
|
![](templates/subSilver/images/spacer.gif) |
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
|
Posted: Sat Jan 12, 2013 10:18 am |
|
|
yes but, where is the fun in that? hehehe
g. _________________ CCS PCM 5.078 & CCS PCH 5.093 |
|
![](templates/subSilver/images/spacer.gif) |
|