View previous topic :: View next topic |
Author |
Message |
whmeade10
Joined: 27 Jan 2004 Posts: 12
|
Change Pin from input to output |
Posted: Tue Nov 19, 2013 2:12 pm |
|
|
I am using a 18F1320 connected to a AD7710 analog chip and need to be able to change PIN B4 between input and output depending on whether I am sending or receiving data from the analog chip. I have been reading about setting the TRIS for the pin but maybe need a little help. Is this correct:
Code: |
#define SDATA PIN_B4
#bit TRIS_SDATA = 0x87.5 |
In program
Code: |
//Make SDATA an output
TRIS_SDATA = 0;
//Make SDATA an input
TRIS_SDATA = 1; |
Thanks,
Bill |
|
![](templates/subSilver/images/spacer.gif) |
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
|
Posted: Tue Nov 19, 2013 3:02 pm |
|
|
unless you are using Fast_IO, you best leave the tris setting to the compilier..
just use Input() & Output_low/high/toggle() as required.
G. _________________ CCS PCM 5.078 & CCS PCH 5.093 |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Nov 19, 2013 3:07 pm |
|
|
If you want to only change the TRIS, and not change the value
(previously) written to the output latch, you can do it with CCS functions:
Code: |
#include <18F1320.h>
#fuses INTRC_IO,NOWDT,PUT,BROWNOUT,NOLVP
#use delay(clock=4M)
#define SDATA PIN_B4
//======================================
void main()
{
output_float(SDATA); // Make it be an input
output_drive(SDATA); // Change it to an output
while(1);
}
|
Here's part of the .LST file. Notice how it changes only the TRIS bit:
Code: |
.................... {
.................... output_float(SDATA); // Make it be an input
001A: BSF TRISB.4
....................
.................... output_drive(SDATA); // Change it to an output
001C: BCF TRISB.4
....................
.................... while(1);
001E: BRA 001E
.................... } |
|
|
![](templates/subSilver/images/spacer.gif) |
whmeade10
Joined: 27 Jan 2004 Posts: 12
|
|
Posted: Thu Nov 21, 2013 9:55 am |
|
|
Thanks Gabriel and PCM programmer. I appreciate that you took the time to help me out. Now time to get programming.
-Bill |
|
![](templates/subSilver/images/spacer.gif) |
|