View previous topic :: View next topic |
Author |
Message |
Zampar Guest
|
This is another bug in CCS? (3.212) |
Posted: Thu Feb 24, 2005 3:54 pm |
|
|
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
|
|
Posted: Thu Feb 24, 2005 4:20 pm |
|
|
Hola Zampar,
1) I guess that it�s too early to suppose such error as a bug compiler.
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
Humberto |
|
|
Hans Wedemeyer
Joined: 15 Sep 2003 Posts: 226
|
Re: This is another bug in CCS? (3.212) |
Posted: Fri Feb 25, 2005 2:57 pm |
|
|
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 |
|
|
|