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 support@ccsinfo.com

Correct way to I/O

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



Joined: 28 Jan 2009
Posts: 5

View user's profile Send private message

Correct way to I/O
PostPosted: Wed Apr 08, 2009 5:44 am     Reply with quote

I wish to preserve the state of all but pins 0 - 2 of port J and then write a variable to those pins. I did the following:
Code:
Int8 b;
b = (input_j () & F8);
output_j (b | buffer[2]);

It works but, is it good programming Question
Guest








PostPosted: Wed Apr 08, 2009 6:44 am     Reply with quote

You should mask out the higher bits from buffer[2] to prevent corruption:
Code:

Int8 b;
b = (input_j () & F8);
output_j (b | (buffer[2] & 7));


Good luck
dcclark



Joined: 28 Jan 2009
Posts: 5

View user's profile Send private message

PostPosted: Wed Apr 08, 2009 10:13 am     Reply with quote

Thanks Mr. Guest. That is one of those "Why didn't I think of that?" Smile
asmboy



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

View user's profile Send private message AIM Address

and of course there is ......
PostPosted: Wed Apr 08, 2009 8:24 pm     Reply with quote

output_J( ( input_j()&F8) | ( buffer[2]&7));
dcclark



Joined: 28 Jan 2009
Posts: 5

View user's profile Send private message

Re: and of course there is ......
PostPosted: Thu Apr 09, 2009 5:06 am     Reply with quote

asmboy wrote:
output_J( ( input_j()&F8) | ( buffer[2]&7));


Thanks. By now it should be perfectly obvious to the most casual observer that I am transitioning from BASIC to C.
Thanks again Asmboy, now that is elegant C code. Very Happy
dcclark



Joined: 28 Jan 2009
Posts: 5

View user's profile Send private message

Re Correct I/O
PostPosted: Thu Apr 09, 2009 5:22 am     Reply with quote

And of course my CCS PCWHD compiler complained. The code should be thusly: output_j((input_j() & 0xF8) | (buffer[2] & 0x7));
Thanks again.
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