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

Output data simultaneously on a split Input/Output port

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



Joined: 20 Oct 2011
Posts: 15

View user's profile Send private message

Output data simultaneously on a split Input/Output port
PostPosted: Thu Aug 15, 2013 1:54 am     Reply with quote

I have split a 8-bit port into lower 4 bits for input and higher 4 bits for output which will not be changed in the program.
Code:
#use fast_io(d)
...
set_tris_d( 0x0f );

The output_d and and input_d functions are writing/reading the entire byte and hence can not be used (correct ?).
By
Code:
input(PIN_D0);
input(PIN_D1);
input(PIN_D2);
input(PIN_D3);
all lower input bits can be read one after another,

but how to set the upper 4 bits simultaneously, i.e. not using a sequence like
Code:
output_bit(PIN_D4, b[0]);
output_bit(PIN_D5, b[1]);
output_bit(PIN_D6, b[2]);
output_bit(PIN_D7, b[3]);
with b[n] being the bits for output.

Thanks for helping with this basic question !

Regards
Ttelmah



Joined: 11 Mar 2010
Posts: 19552

View user's profile Send private message

PostPosted: Thu Aug 15, 2013 1:58 am     Reply with quote

You can use output_d, and input_d.

The _chip_ only has bitwise, or bytewise operations on the port. So the compiler can't change this....

However if you write to a bit that is set as an 'input', all that happens is that the output_latch is set (which means the bit would appear if you changed TRIS). When you read, you will see the input bits (on the pins set as inputs), and what is being output (on the pins set as outputs).

Best Wishes
berel



Joined: 20 Oct 2011
Posts: 15

View user's profile Send private message

PostPosted: Thu Aug 15, 2013 2:13 am     Reply with quote

Dear Ttelmah,

many thanks for your quick response.

If there is no problem using output_d and input_d as explained, that will make life easier Smile

Regards
RF_Developer



Joined: 07 Feb 2011
Posts: 839

View user's profile Send private message

PostPosted: Thu Aug 15, 2013 2:16 am     Reply with quote

Ttelmah wrote:
You can use output_d, and input_d.


With fast_io(x), you set which bits are inputs and outputs with tris_x. Then you can read or write the entire byte-wide port in one hit with output_x and input_x. Bits that were set as inputs in tris_x will obviously not change when you use output_x, and bits that are set as outputs will read back the state of the pin, which should be the last written state.

You obviously have to mask out the bits you want to use as inputs and construct the output byte from the bits you want to write.

Be careful, some upper-end PICs have 16 bit ports rather than the 8 bit ports seen on most PICs. That means this type of code is not portable to all PICs.
berel



Joined: 20 Oct 2011
Posts: 15

View user's profile Send private message

PostPosted: Thu Aug 15, 2013 2:27 am     Reply with quote

Dear RF_Developer,

many thanks for the additional explanation why it will work.

And thanks for the hint regarding 16-bit ports.
I am currently using a PIC18F.

Regards
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Thu Aug 15, 2013 6:20 am     Reply with quote

Quote:

how to set the upper 4 bits simultaneously


use Fastio and a phantom register variable.
then set tris as you need....

next
declare a VAR like
BYTE myportD;

and manipulate the bits matching the portD bits you wish to update
as a single unit. then output the whole byte to portd

then all the bits will be updated in sync, and the input bits left alone
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