Bob, I appreciate this. It is exactly what I am looking for. It is=20 straight forward and simple. Otherwise it fulfills the KISS principle.=20 It compiles with no errors. I still have to do the code for the B port. Thanks, rich! On 9/16/2015 8:52 PM, Bob Blick wrote: > Hi Rich, > > There are a couple of ways you could do this. One would be to use arrays > to decode the inputs. It would probably be efficient. The second would > be to use a switch-case statement. It is more versatile. If you decide > to add more features, it'll come in handy. So that's what I'll do here > for your Port A question, you can duplicate this for Port B and change > it as necessary. > > void decodePortA(void) > { > unsigned char portashadow =3D PORTA & 0xC3; // zero out the bits we writ= e > later > // If you are driving port A during interrupts, disable interrupts > here > switch (PORTA & 0x03) // only working with bits 0 and 1 > { > case 0: > portashadow |=3D 0x24; // output bits 2 and 5 > break; > case 1: > portashadow |=3D 0x08; // output bit 3 > break; > case 2: > portashadow |=3D 0x10; // output bit 4 > break; > case 3: > portashadow |=3D 0x20; // output bit 5 > break; > } > PORTA =3D portashadow; // write the decoded pattern to the port > // If you disabled interrupts earlier, re-enable them here > } > > Sorry if formatting isn't great, using email editor. > > Using switch-case takes more steps, but it's real clear what you are > doing, and you can do completely different things or additional steps > for any case. > > Hope this helps. I haven't used XC8 but this should be portable. If I > made errors, sorry, I'm sleepy :( > > Best regards, Bob > > On Sat, Sep 12, 2015, at 09:49 AM, Richard R. Pope wrote: >> Hello all, >> I solved this problem. Some how I managed to delete everything in >> the XC8 include files. I reinstalled XC8 and that fixed it. Dumb!! Now I >> have another problem. The code is running and most of it works >> correctly. This is about as simple as it gets. I am using a series of if >> and elseif statements to check for the setting of two input bits and >> then set four output bits. It is PortA and B and the input bits are 0 >> and 1. The two ports control two separate devices. If the setting is 0, >> 0 then output bits 2 and 5 are on and bits 3 and 4 are off. If the >> setting is 0, 1 then bit 2, 4, and 5 are off and bit 3 is on. If the >> setting is 1, 0 then bits 2, 3, and 5 are off and bit 4 is on. If the >> setting is 1, 1 then bits 2, 3, and 4 are off and bit 5 is on. That is >> the way it is supposed to work. So here are three tables showing what is >> supposed to happen and what is happening; >> Supposed to be! The way it >> is! Port A The way it is! Port B >> --------------------------------- ---------------------------------- >> ---------------------------------- >> | Input | Output | >> | Input | Output | | Input | Output | >> | Bits | Bits | >> | Bits | Bits | | Bits | >> Bits | >> |-----|-----|-----|-----|-----|-----| >> |-----|-----|-----|-----|-----|------| >> |-----|-----|-----|-----|-----|------| >> | 1 | 0 | 2 | 3 | 4 | 6 | 5 for >> B | 1 | 0 | 2 | 3 | 4 | 6 | | 1 | >> 0 | 2 | 3 | 4 | 5 | >> |-----|-----|-----|-----|-----|-----| >> |-----|-----|-----|-----|-----|------| >> |-----|-----|-----|-----|------|-----| >> | 0 | 0 | 1 | 0 | 0 | 1 | >> | 0 | 0 | 1 | 0 | 0 | 1 | OK >> | 0 | 0 | 1 | 0 | 0 | 1 | OK >> |-----|-----|-----|-----|-----|-----| >> |-----|-----|-----|-----|------|-----| >> |-----|-----|-----|-----|------|-----| >> | 0 | 1 | 0 | 1 | 0 | 0 | >> | 0 | 1 | 0 | 1 | 0 | 0 | OK >> | 0 | 1 | 1* | 0 | 0 | 1*| Bad* >> |-----|-----|-----|-----|-----|-----| >> |-----|-----|-----|-----|------|-----| >> |-----|-----|-----|-----|------|-----| >> | 1 | 0 | 0 | 0 | 1 | 0 | >> | 1 | 0 | 0 | 0 | 1* | 0 | OK* >> | 1 | 0 | 0 | 0 | 1 | 0 | OK >> |-----|-----|-----|-----|-----|-----| >> |-----|-----|-----|-----|------|-----| >> |-----|-----|-----|-----|------|-----| >> | 1 | 1 | 0 | 0 | 0 | 1 | >> | 1 | 1 | 0 | 0 | 0 | 1 | OK >> | 1 | 1 | 0 | 1 | 0 | 0 | Bad >> |-----|-----|-----|-----|-----|-----| >> |-----|-----|-----|-----|------|-----| >> |-----|-----|-----|-----|------|-----| --=20 http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .