I am using CodeWarrior 11.1 with a MC9S08SH MCU and the project uses Processor Expert. There are 3 buttons attached to the MCU via on-chip pull-ups.I.E. while a button is pressed the input pin returns a "0" , otherwise it returns a "1". The idea is that if the button is pressed for less than 1 second the first section the code runs to (3) and then exits. If the button is held down the code jumps to (3) and then loops until the button is released. This section works correctly.
if(!MODE_GetVal()) //mode switch pressed (1)
{
NewSetPoint=1;
DelayX1ms(1000); // 1 second delay
key_mode = 1;
if(MODE_GetVal()==1) // was the key released? (2)
{ // if so - change the mode
if(Mode==0)
{
Mode = 1; //switch between functions
StartupTime = Time_1;
}
else
{
Mode = 0;
dt();
}
}
else // repeat this loop untilkey is released
while(!MODE_GetVal()) (3)
{
..............
While stepping through the code, when the MODE button is pressed execution correctly arrives at (1) and code is executed correctly up to (2). The execution then jumps to (3) irrespective of the state of the MODE button.
On examination of the assembly code there is nothing between (2) and (3). Apparently the code between these two points has been removed as "DEAD CODE" because the test at point (2) is "always false" which is, of course, incorrect if the button has been released.
The component Mode is configured as a BitIO with method GetVal()
Hi juliancox
Please create a demo project to show the issue. Thus we can run the demo to see problem directly.
Thanks,
Jun Zhang
A further anomaly:
According to The CodeWarrior documentation, if set as an input the function MODE_GetVal() should read THE PIN and return a BOOLEAN value. However, in this case it returns either 0 or 0x08. Noting that this particular input is on Port C, bit 3 - which has a value of 0x08. Furthermore, I solved the problem by changing the statement
if(MODE_GetVal()==1) to if(MODE_GetVal()!=0)
I also tried if(MODE_GetVal()) but it did not work.
why does this function not return a boolean value as it should?