I am trying to do something with an Encore V MCU (7C64343). The problem I am facing has been described many times yet I have been unable to make it work for me at this stage: On port 1 I have a few digital inputs and one output controlled by an interrupt function. My problem is that I can never read the actual status of the inputs, they are always 0. What I am doing is this:
The relevant bits P1.2, P1.3 and P1.4 are configured as StdCPUInput and drive Analog High Z in the PD
unsigned char P1;
and then in the interrupt function (executed around 100 times per second):
P1=PRT1DR; // supposedly reads the actual input states P1^=0x20; // swinging the output pin PRT1DR=P1; // update the output
Everywhere else in the code I only use P1 as read from the code above. Where is my problem here?
If you are using P1 as a shadow register, then you should not be updating it with the PRT1DR value. You should only write values that you need to reflect on your output pins and then update the PRT1DR with P1 value.
Check out the below Blog article that explains the concept of shadow register.