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 support@ccsinfo.com

This is another bug in CCS? (3.212)

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Zampar
Guest







This is another bug in CCS? (3.212)
PostPosted: Thu Feb 24, 2005 3:54 pm     Reply with quote

i'm is working in a menu and i have a big problem:

whats have wrong in a logic because I need press two times the key 4 to view the next window.

the function ajuste_dispositivos() retorn void.
Code:

   While (true)
      {

         for(;((Nova_Tecla) && (Tecla == 4)); menu_p++) // MENU PRINCIPAL
           {
            disable_interrupts(int_TIMER1);
            Nova_Tecla = 0;
                  if (menu_p < maximo_dispositivos)
                   {
                     ajuste_dispositivos(menu_p);
                   }

                   if (menu_p == maximo_dispositivos)
                     {
                      ajuste_relogio();
                     }


           }

      }






regards

Zampar

(sorry for my English, but I speak and write only in Portuguese)
Saudações ao BRASIL!!
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Thu Feb 24, 2005 4:20 pm     Reply with quote

Hola Zampar,

1) I guess that it´s too early to suppose such error as a bug compiler. Confused

2) With the code you posted we don´t have enough information to test
and reproduce the error.

3) We doesn´t know the previous state of your variables to analize the
code.

Saludos Very Happy

Humberto
Hans Wedemeyer



Joined: 15 Sep 2003
Posts: 226

View user's profile Send private message

Re: This is another bug in CCS? (3.212)
PostPosted: Fri Feb 25, 2005 2:57 pm     Reply with quote

Zampar wrote:
i'm is working in a menu and i have a big problem:

whats have wrong in a logic because I need press two times the key 4 to view the next window.

the function ajuste_dispositivos() retorn void.
Code:

   While (true)
      {

         for(;((Nova_Tecla) && (Tecla == 4)); menu_p++) // MENU PRINCIPAL
           {
            disable_interrupts(int_TIMER1);
            Nova_Tecla = 0;
                  if (menu_p < maximo_dispositivos)
                   {
                     ajuste_dispositivos(menu_p);
                   }

                   if (menu_p == maximo_dispositivos)
                     {
                      ajuste_relogio();
                     }


           }

      }






regards

Zampar

(sorry for my English, but I speak and write only in Portuguese)
Saudações ao BRASIL!!


Try using if() and not for() It will be easier to read your code. There is no glory in making code difficult to read :-)

Assuming variables Nova_Tecla and Tecla are zero, then if Nova_Tecla is true Tecla must be equal to 4 before the code will do any thing.

So everytime (Nova_Tecla && Tecla == 4) is true the code will do something.

The question is When or what ( I suspect a key press) increments Tecla ?

Any if Tecla started at 0 and it increments by 1 then it will take FOUR (4) actions, and you say it takes two !
Which makes me think you may also have a debounce problem wherever Tecla is being handled.


This should be easier to read….

Nova_Tecla = 0;
Tecla = 0;

while (true)
{

if( Nova_Tecla && Tecla == 4) // then do something
{
disable_interrupts(int_TIMER1);

Nova_Tecla = 0;
if (menu_p < maximo_dispositivos)
{
ajuste_dispositivos(menu_p);
}

if (menu_p == maximo_dispositivos)
{
ajuste_relogio();
}

menu_p++;
}

}

I'm not saying the compiler is perfect, however it's too easy to blame it... I recommend you use a better easier to read syntax. for() is for doing something a number of times while a conditions is not true.
In this case I think your code needs to test two variables to see if they are true and then do one thing, in which case if() is the better choice.

Good luck
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