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

Managing multiple digital outputs.....

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



Joined: 24 Apr 2014
Posts: 138

View user's profile Send private message

Managing multiple digital outputs.....
PostPosted: Tue Nov 15, 2016 2:54 pm     Reply with quote

Hi All,

I'm looking for some suggestions on how best to code the following:

I have 8 digital outputs on an 18F24k22 device connected to pins A0 thru A5, and B4 and B5. I need to be able to turn these outputs On and Off both singly and in groups. I plan to use an int8 'OutputCode' that contains the On/Off states of all eight outputs. I can see a 'brute force' method with lots of conditional 'If' statements to translate the OutputCode variable into the individual outputs, but I imagine there is a more 'elegant' strategy.

Can someone point me in the right direction?

Thanks,

Jack
temtronic



Joined: 01 Jul 2010
Posts: 9244
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Nov 15, 2016 3:37 pm     Reply with quote

Check the 'code library' for it ! Either PCM P to Mr. T cut code and posted it.well, pretty sure it was one of them....

Jay
gjs_rsdi



Joined: 06 Feb 2006
Posts: 468
Location: Bali

View user's profile Send private message Send e-mail

PostPosted: Tue Nov 15, 2016 10:21 pm     Reply with quote

Checked the 9 pages of the library but didn't find it. I suppose I miss it somehow.
Can somebody give a more specific direction?

Best wishes
Joe
Ttelmah



Joined: 11 Mar 2010
Posts: 19545

View user's profile Send private message

PostPosted: Wed Nov 16, 2016 1:39 am     Reply with quote

Look at the send_nibble command in PCM_programmers lcd driver. In fact this can be tweaked a little by using bit test, instead of his nibble logic (it was originally posted before bit_test appeared).
gjs_rsdi



Joined: 06 Feb 2006
Posts: 468
Location: Bali

View user's profile Send private message Send e-mail

PostPosted: Thu Nov 17, 2016 2:57 am     Reply with quote

Thanks Ttelmah
JAM2014



Joined: 24 Apr 2014
Posts: 138

View user's profile Send private message

PostPosted: Thu Nov 17, 2016 11:11 am     Reply with quote

Hi All,

For completeness, here is the method I believe that Ttelmah was referring to:

Code:

 output_bit(Out1, bit_test(iOutputCode, 0));
 output_bit(Out2, bit_test(iOutputCode, 1));
 output_bit(Out3, bit_test(iOutputCode, 2));   
 output_bit(Out4, bit_test(iOutputCode, 3));
 output_bit(Out5, bit_test(iOutputCode, 4));
 output_bit(Out6, bit_test(iOutputCode, 5));
 output_bit(Out7, bit_test(iOutputCode, 6));   
 output_bit(Out8, bit_test(iOutputCode, 7)); 


Each digital output is defined as:
Code:

#define Out1 Pin_A0            // Output #1
.
.
.
.
.
#define Out8 Pin_B5            // Output #8


I don't have boards to test this yet, but I believe this will work as intended!

Thanks to Ttelmah for pointing the way, and to PCM programmer for providing the original 'Nibble' function inside the flex_lcd driver!

Jack
gjs_rsdi



Joined: 06 Feb 2006
Posts: 468
Location: Bali

View user's profile Send private message Send e-mail

PostPosted: Thu Nov 17, 2016 7:30 pm     Reply with quote

Thank you JAM2014
Written down like that seems simple Smile
I am in a trip, will be back at home in 10 days, will test and report back

Best wishes
Joe
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