CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

"if" Stranger Operation

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
rodrigo.bzsilva



Joined: 13 Nov 2012
Posts: 4

View user's profile Send private message Visit poster's website

"if" Stranger Operation
PostPosted: Thu Oct 10, 2013 11:00 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Oct 10, 2013 1:20 pm     Reply with quote

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: 19561

View user's profile Send private message

PostPosted: Fri Oct 11, 2013 1:04 am     Reply with quote

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

View user's profile Send private message Visit poster's website

PostPosted: Fri Oct 11, 2013 6:04 am     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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