Getting a digital input

I would like to read whether a pin is high (at 5v) or low (0v). I’ve been trying a few approaches, but don’t seem to be making headway. Could anyone give me some advice? I’ve looked through the documentation (I’m using a RCM4000), but the issue isn’t covered in any obvious way (e.g., there doesn’t seem to be an explanation of the port address defines).

Anyway, I’m trying to read in PB3 and PB4 (I’m picked them more or less at random). I used the utility program to make sure the pins are set to input.

I’ve tried:

printf("port4:%u, port3:%u
", BitRdPortI(PBDR, 4),BitRdPortI(PBDR, 3));


", RdPortI(PBDR));

The value they return seem to indicate whether the pins are input or outputs, not whether they’re high or low.

Many thanks for any help!

The problem was with the file that the Lib Utility outputted. In the Utility it looked like the pins were set correctly for I/O, but the actual code had them misconfigured.

I’m guessing that I edited the file and screwed up how it was read by the Utility (there is a warning about that). However, I did expect some error message from the Utility when loading the corrupted file (I’m assuming that’s what the checksum value at the bottom of the file is for).

Can’t anyone answer this? Being able to read whether a pin is high or low must be one of the most basic operations on a microcontroller. Someone must be able to give me a hint for how to do it using DynamicC!

Actually, the I/O Utility doesn’t seem to be generating legit code for the Port B I/O pins (even when I don’t manually edit the file), but perhaps that a human error on my part.