While studying I ended up finding this question.
Write the value (in hex) of the P1 after the execution of the code below.
unsigned char var; P1 = 0xff; var = P1; var = ~var; P1 = var; P1_0 = 1; P1_4 = 0;
Consider P1 as Open Drain with Weak Pullups.
I tried to answer the question, but I'm not sure of my answer. Can anyone help me?
My approach to solve the question.
First I analyzed the code and I saw that the P1 output would be 0x01.
And then I analyzed the hardware.
P1.0 is High. P1.1 is Low. P1.2 is High. P1.3 is High. P1.4 is Low P1.5 is High P1.6 is Low P1.7 is Low.
It would lead to a output of 0x2D (0b0010 1101).
My doubt is.
In the code P1.0 is set to 1, and in the hardware is connect to 1 (High). I believe that P1.0 is going to be 1. Therefore the answer is 0x2D.
But what if we have something like, by code PX is set to 1 but it's hard-wired to GND. I learned that open-drain port configuration work as a di-directional port, working as an output and an input, but I didn't get what happens when he have a mismatch (trying to set a ouput, where would be a input).