<sorry if this is a duplicate, problems with "from" address>
I've got a device driver that I've been using for an HD44780 LCD display.
It's been working under mspgcc for quite a while, but it stopped working
when I upgraded to mspgcc4.
There's some code that polls the "busy" flag, which is on the DB7 pin.
Basically you bring the E pin high, read the busy flag, then bring the E pin
low again. A simplified version of the code follows:
bool busy;
do {
P4OUT |= E_PIN;
busy = P4IN & DB7_PIN;
P4OUT &= ~E_PIN;
} while (busy);
There are some nops for timing as well, plus a bit of code so that it
doesn't wait forever, but that's the basic idea.
I finally discovered that the compiler had reordered things so that the E
pin was brought high, then low, then it checked the DB7 pin, which was too
late. (Just to confuse things, if I put a scope probe on this pin, the
capacitance slowed it down just enough to make it work occasionally.)
The solution of course was to use the "volatile" keyword for "busy". My
question is this: If P4IN is already marked volatile, why would busy have
to be volatile too? The "busy" variable isn't really volatile anyway, it's
the input port that's volatile.
Anyone have any insight about this?
Todd