View previous topic :: View next topic |
Author |
Message |
JAM2014
Joined: 24 Apr 2014 Posts: 138
|
Managing multiple digital outputs..... |
Posted: Tue Nov 15, 2016 2:54 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9176 Location: Greensville,Ontario
|
|
Posted: Tue Nov 15, 2016 3:37 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
gjs_rsdi
Joined: 06 Feb 2006 Posts: 468 Location: Bali
|
|
Posted: Tue Nov 15, 2016 10:21 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19375
|
|
Posted: Wed Nov 16, 2016 1:39 am |
|
|
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). |
|
![](templates/subSilver/images/spacer.gif) |
gjs_rsdi
Joined: 06 Feb 2006 Posts: 468 Location: Bali
|
|
Posted: Thu Nov 17, 2016 2:57 am |
|
|
Thanks Ttelmah |
|
![](templates/subSilver/images/spacer.gif) |
JAM2014
Joined: 24 Apr 2014 Posts: 138
|
|
Posted: Thu Nov 17, 2016 11:11 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
gjs_rsdi
Joined: 06 Feb 2006 Posts: 468 Location: Bali
|
|
Posted: Thu Nov 17, 2016 7:30 pm |
|
|
Thank you JAM2014
Written down like that seems simple
I am in a trip, will be back at home in 10 days, will test and report back
Best wishes
Joe |
|
![](templates/subSilver/images/spacer.gif) |
|