Help, help, I'm being repressed! Er, optimised This is CodeWarrior 10.2, target is HCS08.
For some reason, when I follow a loop with another loop, subsequent loops are getting optimised out, with a message "...ProcessorExpert.c:70:warning:C5660 Removed dead code"
Here is a sample of my code:
/* Write your code here */
/* For example: for(;;) { } */
for(;;)
{
for (i=1; i<=255; i++)
{
LED1R_SetRatio8(i);
LED2G_SetRatio8(255-i);
WAIT1_Waitms(5);
}
for (i=1; i<=255; i++)
{
LED2B_SetRatio8(i);
LED1R_SetRatio8(255-i);
WAIT1_Waitms(5);
}
}
Why am I not able to have subsequent loops?
Solved! Go to Solution.
Hi Matthew,
Hint: pay close attention to compiler warning and information messages ;-).
I assume your variable 'i' is of type unsigned char?
That means that the variable has a value range of 0..255 (0..0xff).
And if you do a comparison of 'i<=255' in the for() loop, this means that this condition is always TRUE.
As such, you should see a message C4000 Condition always is TRUE (unless you have switched off such messages).
Which means that your first loop never will finish.
:-).
Hope this helps,
Erich
Hi Matthew,
Hint: pay close attention to compiler warning and information messages ;-).
I assume your variable 'i' is of type unsigned char?
That means that the variable has a value range of 0..255 (0..0xff).
And if you do a comparison of 'i<=255' in the for() loop, this means that this condition is always TRUE.
As such, you should see a message C4000 Condition always is TRUE (unless you have switched off such messages).
Which means that your first loop never will finish.
:-).
Hope this helps,
Erich
Thanks, Erich! I didn't notice any other warnings, but I guess they may have been scrolled off the page.
Now that you point out the error, yes, I can well see what I've done! That's the problem with not being used to typed languages - I've written tens of thousands of lines of Perl over the last few years, but very, very, little C - so it would have taken me a LONG time to spot that, if you hadn't pointed it out!
Whilst I was waiting to see if anyone came up with an answer, I started testing something else - driving the LEDs by setting the PWM values and the delays between changing them from the output of an LFSR, which I generated the code for using lfsr-generator - makes for some very groovy effects! (This project is actually wearable jewellery - LED effects triggered by an MMA7660 accelerometer, for which I am now working on the I2C code.)
Thanks again for your continued support!