|
|
View previous topic :: View next topic |
Author |
Message |
rodrigo.bzsilva
Joined: 13 Nov 2012 Posts: 4
|
"if" Stranger Operation |
Posted: Thu Oct 10, 2013 11:00 am |
|
|
Hi guys,
I'm using CCS compiler v5.010.
So, I have a function on the timer 1 that toggle a Led on my board. But switching to only function if the flag == false.
Code: |
void T_LED_MCU_ACT()
{
if ((ledMCUact--) == 0)
{
toogle_led_status=!toogle_led_status;
switch(toogle_led_status)
{
case TRUE: ledMCUact=kledMCUact;
if(Timeout_Setup_Button_Ok == FALSE)
ledStatusMCUGreen_On;
break;
case FALSE: ledMCUact=kledMCUNact;
if(Timeout_Setup_Button_Ok == FALSE)
ledStatusMCU_Off;
break;
}
}
}
|
But is not working!
Even if the flag Timeout_Setup_Button_Ok is true, the LED will not stop running.
But if I change the "if" on the situation below, the led stop working as it should work.
See:
Code: |
void T_LED_MCU_ACT()
{
if ((ledMCUact--) == 0)
{
toogle_led_status=!toogle_led_status;
switch(toogle_led_status)
{
case TRUE: ledMCUact=kledMCUact;
if(Timeout_Setup_Button_Ok == FALSE)
{
ledStatusMCUGreen_On;
}
break;
case FALSE: ledMCUact=kledMCUNact;
if(Timeout_Setup_Button_Ok == FALSE)
{
ledStatusMCU_Off;
}
break;
}
}
}
|
Only adding the "{ }" below the "if".
What happened? anyone been through this?
Thanks!
PS: Sorry for my bad english. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Oct 10, 2013 1:20 pm |
|
|
Post a complete (but small) test program so we can see your variable
declarations, and how you initialize the variables. The test program
needs to have the #include for the PIC, #fuses, #use delay, etc., and
a main(). It should have everything necessary to demonstrate the
problem, and it should compile with no errors. But don't put in any lines
of code that are not needed to show the problem. For example, don't
put in lines of code that setup the ADC, or SPI, etc., because they are
not needed in the test program.
After you make the test program, run it, and make sure it actually shows
the failure. Then post it.
Also, if you are not using printf to show the results of the test, then tell us
how you are noticing the results (for example, using a breakpoint and
a watch window). Tell us how you know it fails. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19499
|
|
Posted: Fri Oct 11, 2013 1:04 am |
|
|
I think the key is what ledStatusMCUGreen_On;
actually is?.
I'm guessing probably a #define. There are no brackets to suggest a function, and it is not a variable.
If it is a #define, then you need to remember that #define is only a text substitution, with limited macro abilities. So if it involves multiple statements, after the 'if', only the first will get executed, unless the define includes the {} brackets, or is bracketed.
Best Wishes |
|
|
rodrigo.bzsilva
Joined: 13 Nov 2012 Posts: 4
|
|
Posted: Fri Oct 11, 2013 6:04 am |
|
|
Ttelmah wrote: | I think the key is what ledStatusMCUGreen_On;
actually is?.
I'm guessing probably a #define. There are no brackets to suggest a function, and it is not a variable.
If it is a #define, then you need to remember that #define is only a text substitution, with limited macro abilities. So if it involves multiple statements, after the 'if', only the first will get executed, unless the define includes the {} brackets, or is bracketed.
Best Wishes |
Sorry guys,
#define ledStatusMCUGreen_On:
Code: |
#define ledStatusMCU_Off output_low(ledStatusMCU_pinA); output_low(ledStatusMCU_pinB);
#define ledStatusMCURed_On output_high(ledStatusMCU_pinA); output_low(ledStatusMCU_pinB);
#define ledStatusMCUGreen_On output_low(ledStatusMCU_pinA); output_high(ledStatusMCU_pinB);
|
This is a bicolor Led. This is the error.
Sorry, the error is mine.
Thanks for the help guys. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|