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

Change Pin from input to output

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



Joined: 27 Jan 2004
Posts: 12

View user's profile Send private message

Change Pin from input to output
PostPosted: Tue Nov 19, 2013 2:12 pm     Reply with quote

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
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Tue Nov 19, 2013 3:02 pm     Reply with quote

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
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Nov 19, 2013 3:07 pm     Reply with quote

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
.................... } 
whmeade10



Joined: 27 Jan 2004
Posts: 12

View user's profile Send private message

PostPosted: Thu Nov 21, 2013 9:55 am     Reply with quote

Thanks Gabriel and PCM programmer. I appreciate that you took the time to help me out. Now time to get programming. Very Happy

-Bill
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