I need to use all 8 bits of parallel port B. So far, I am tripping over bit 0, which is always high, regardless of my interface. I need to have bit 0 as an input, and all others as outputs. As I understand the setup for the usage of the port, the following code should give me what I need:
// tell the hardware that parallel port B bit 0 is an input
// all others are outputs
WrPortI(PBDDR, &PBDDRShadow, 0xFE);
result = RdPortI(PBDDR);
if (!result == 0xFE)
printf(“PBDDR was not set correctly. it is currently: %#x”, result);
// clear all data
WrPortI(PBDR, &PBDRShadow, 0x00);
result = RdPortI(PBDR);
printf(“PBDR is currently: %#x”, result);
This sets up the PBBDR to configure the port, and then I clear the port, followed by a read.
As stated above, the problem is that when I read the port, bit 0 is always high. I have been able to rule out my hardware by virtue of the fact that when I remove my interface, the input continues to remain high.
I am currently working around the problem by using bit 4 for the input, and eliminating bit 0. Everything on my side works as expected, by setting the DDR to 0xEF.
After combing through the documentation over and over, it appears that the root cause may be SPCR, but for the life of me, I cannot figure out what to set it to.
Note that I still have work to do, but I will need bits 0-3 of PCDR as well, so if there is an impact of the SPCR value, I need to factor that in as well.
Thanks in advance for any and all assistance!