In the MPSIM (or is it only called "Simulator" now?) in MPLAB there is a tool to manually manage external I/O signals. Your code will react accordingly... Jan-Erik. -----Ursprungligt meddelande----- Fr=E5n: piclist-bounces@mit.edu [mailto:piclist-bounces@mit.edu] F=F6r Rich= ard R. Pope Skickat: den 17 september 2015 13:17 Till: Microcontroller discussion list - Public. =C4mne: Re: [PIC]: Troubles with a 16f628a! Bob, I made a duplicate of the PORTA code and changed the names as needed t= o B. I also did prototypes for the two subroutines and then I put two calls t= o the subroutines in the main body of my program. This is one of the calls: decodePortA(); of course I also added a call for PORTB. Well it doesn't work. It compiles but the hardware doesn't respond. I put the program back to the if, elseif statements and the hardware works. :( With input and output bits I don't know how to use the debugger. If there was no I/O I wouldn't have a problem. Thanks, rich! On 9/16/2015 11:00 PM, Bob Blick wrote: > Glad I could help. > > Bob > > On Wed, Sep 16, 2015, at 07:09 PM, Richard R. Pope wrote: >> 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. >> 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=20 >>> arrays to decode the inputs. It would probably be efficient. The=20 >>> second would be to use a switch-case statement. It is more=20 >>> versatile. If you decide to add more features, it'll come in handy.=20 >>> So that's what I'll do here for your Port A question, you can=20 >>> duplicate this for Port B and change it as necessary. >>> >>> void decodePortA(void) >>> { >>> unsigned char portashadow =3D PORTA & 0xC3; // zero out the bits we=20 >>> write 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 por= t >>> // 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=20 >>> doing, and you can do completely different things or additional=20 >>> steps for any case. >>> >>> Hope this helps. I haven't used XC8 but this should be portable. If=20 >>> 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=20 >>>> everything in the XC8 include files. I reinstalled XC8 and that=20 >>>> fixed it. Dumb!! Now I have another problem. The code is running=20 >>>> and most of it works correctly. This is about as simple as it gets.=20 >>>> I am using a series of if and elseif statements to check for the=20 >>>> setting of two input bits and then set four output bits. It is=20 >>>> PortA and B and the input bits are 0 and 1. The two ports control=20 >>>> 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=20 >>>> setting is 0, 1 then bit 2, 4, and 5 are off and bit 3 is on. If=20 >>>> the setting is 1, 0 then bits 2, 3, and 5 are off and bit 4 is on.=20 >>>> If the setting is 1, 1 then bits 2, 3, and 4 are off and bit 5 is=20 >>>> on. That is the way it is supposed to work. So here are three=20 >>>> 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 >>>> ---------------------------------=20 >>>> ---------------------------------- >>>> ---------------------------------- >>>> | Input | Output | >>>> | Input | Output | | Input | Output = | >>>> | Bits | Bits | >>>> | Bits | Bits | | Bits | >>>> Bits | >>>> |-----|-----|-----|-----|-----|-----| >>>> |-----|-----|-----|-----|-----|------| >>>> |-----|-----|-----|-----|-----|------| >>>> | 1 | 0 | 2 | 3 | 4 | 6 | 5 fo= r >>>> 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 | O= K >>>> | 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 | O= K >>>> | 1 | 1 | 0 | 1 | 0 | 0 | Bad >>>> |-----|-----|-----|-----|-----|-----| >>>> |-----|-----|-----|-----|------|-----| >>>> |-----|-----|-----|-----|------|-----| -- http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive View/chang= e your membership options at http://mailman.mit.edu/mailman/listinfo/piclist --=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 .