[Solved] Help on Pushbutton State Machines on a While Loop

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Compiler: AVR-GCC
uC: ATMega644
Ext Freq: 8MHz

/*trigger the wireless_flag here*/
wireless_on = 1;

/*conditionA [wireless button is pressed]*/
if (wireless_on == 1)
	{
	/*conditionB [edit settings?]*/
	/*display [EDIT SETTINGS Yes/No]*/
	OUT_ALLCLR();
	exit_flag = 0;
	while (exit_flag == 0)
	{
		if (get_key_short( 1<<KEY4 ))
			{
			/*display [Pan ID X X X X  Enter]*/ 
			OUT_NO_DATA();
			/*set the PAN ID, let but_5 as confirm button*/
			/*use buttons 1-4 to increment each digit, 5 to confirm selection*/
			exit_flag2 = 0;
			while (exit_flag2 == 0)
				{
				if (get_key_short( 1<<KEY1 )) 
					{
					/*increment the PAN4*/
					pan4 = hexinc(pan4);
					/*convert or decode and display to lcd*/
					convert_decode (pan4, 4);
					}
				else if (get_key_short( 1<<KEY2 )) 
					{
					/*increment the PAN3*/
					pan3 = hexinc(pan3);
					/*convert or decode and display to lcd*/
					convert_decode (pan3, 3);
					}	
				else if (get_key_short( 1<<KEY3 )) 
					{
					/*increment the PAN2*/
					pan2 = hexinc(pan2);
					/*convert or decode and display to lcd*/
					convert_decode (pan2, 2);
					}	
				else if (get_key_short( 1<<KEY4 )) 
					{
					/*increment the PAN1*/
					pan1 = hexinc(pan1);
					/*convert or decode and display to lcd*/
					convert_decode (pan1, 1);
					}
				else if (get_key_short( 1<<KEY5 )) 
					{
					/*confirm button is pressed*/
					exit_flag2 = 1;
					}
				}			
/*send the values of Pan4 to Pan1 to the assembly for display and decoding*/
/*or create a decoding function here*/

Problem:
*no display upon entering the while loop
- OUT_NO_DATA(); does not display

Notes:
*i used the debouncing algorithm of danni
*functions beginning with OUT are calling assembly functions for LCD display

*could it be that the while loop is too fast to detect a button press?

tnx and good day

Last Edited: Fri. May 8, 2009 - 06:09 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

no display upon entering the while loop
- OUT_ALLCLR(); does no display

So effectively you are saying that the problem boils down to:

/*trigger the wireless_flag here*/ 
wireless_on = 1; 

/*conditionA [wireless button is pressed]*/ 
if (wireless_on == 1) 
   { 
   /*conditionB [edit settings?]*/ 
   /*display [EDIT SETTINGS Yes/No]*/ 
   OUT_ALLCLR(); // is never reached

The ONLY way I could see that OUT_ALLCLR() might not be called would be if an interrupt occurred between

wireless_on = 1;

and

if (wireless_on == 1)

and changed the state of 'wireless_on', otherwise there's no way the OUT_ALLCLR() could have been avoided if control did really arrive at the top of this code sequence.

Cliff

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

get_key_short() works only correct, if used in conjunction with get_key_long().
Otherwise get_key_press() must be used.
Also get_key_short() react not until key release, since it was not a clairvoyant.

Also you must use the compiler switch: -fno-inline-small-functions

Peter

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

@Cliff:
- im sorry i meant the OUT_NO_DATA(); function [inside the while loop] does not display
- ive already edited my post

@Peter:
- the get_key_short() function seems to be working when outside a loop
- so you mean that instead of using the get_key_short() function, i will replace it with the get_key_press()?
-e.g.

if (get_key_press( 1<<KEY4 )) 
{OUT_NO_DATA();} 

tnx and good day
-jd

EDIT: PROBLEM SOLVED!
Soln
- readjusted timing for interrupts
- used break; instead of flags
- did not change the get_key_short(); function, left as is
special thanks to danni and clawson :)