ON and OFF config ?

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

Guys,

 

I tried to make a config on EEPROM...but I can't change to OFF...

 

Here's the code :

 

char *chime[]={"ON","OFF"};	
..
..
..
int chime_on;
uint16_t config_ee_chime_on EEMEM = 0x0005;
....
....
                  
                   case SET_CHIME_ON_OFF:
			   lcd_xy(0,0);    //put on 0,0
			   lcd_string("CHIME ON/OFF   ");
			   sprintf(chime_char,"%.0d",chime_on);
			   lcd_xy(1,0);    // same as lcd_cmd(0xC0);
			   //lcd_cmd(0xC0);
			   //lcd_string(alarm_day_char);
			   lcd_string(chime[chime_on]);
			   lcd_string("             ");
			   button_input = button_is_pressed();//read button
			   
			   switch (button_input)
			   {
				   case 1:
				   state_var = DISPLAY_TIME;
				   break;
				   
				   case 2:
				   //chime_on ==1;
				  
				   chime_on++;
				   tone(50);
				   _delay_ms(50);
				   tone(0);
				   if (chime_on >= 1)
				   {
					   chime_on = 0;
				   }
				  
				   eeprom_update_byte (&config_ee_chime_on, chime_on );
				   
				   state_var = SET_CHIME_ON_OFF;
				   break;
				   
				   case 3:
				   state_var = BATTERY_STATUS;
				   break;
			   }
			   break;
			   //set chime_on_off end

any clues ?

 

Thanks

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

Take your pencil and paper.   Hand trace the state of the chime_on variable.

 

Then look for the error in your logic.

 

If you don't see it immediately,   drink a cup of tea.

 

David.
 

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

Just a debugging tip, you have an LCD, use it to print the variable before you write it. If it's not then obvious why it's always 0 then sprinkle some more output to show the value at each point where you change it.

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

clawson wrote:
Just a debugging tip, you have an LCD, use it to print the variable

+1

 

Or, if you have a serial port, use that.

 

Or, better still, if your chip has onboard debug then use it!!

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I don't understand,

 

I put like this below.....and it's not changing to "OFF"

 

char *chime[]={"ON","OFF"};	
..
..
..
int chime_on;

....

case 2:
				   chime_on == 1;
				  
				  
				   //debugging variable chime_on
 				   lcd_cmd(0x01);
				   lcd_xy(0,0);    //put on 0,0
				   lcd_string("button2,     ");
				   lcd_string(chime[chime_on]);

??

Last Edited: Mon. Apr 6, 2015 - 10:58 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
                             if (chime_on > 1)
				   {
					   chime_on = 0;
				   }

I got the solution above....thanks for the clues guys....

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

Forget all the 'complex' advice.    A pencil and paper is cheap and effective.

 

And most importantly,   your brain will be in gear.

 

Just observing JTAG or an LCD will only report real life.    Your brain is still required to find the solution.

 

David.

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

But LCD or JTAG will give you the clue as to how/why your logic is wrong.

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

I would agree that well placed printf() or JTAG 'break's can show you the real-life state of a variable.

 

It would be interesting to see which method achieved success for bianchi77.

 

In previous questions,   he has rushed at the problem rather than putting his brain into gear and thinking quietly.

 

David.

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

rather than putting his brain into gear and thinking quietly.

But you must admit he is pretty good at getting other people's brain into gear. cheeky

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

Yes,  but that is only because he has mellowed significantly.    And he reads the replies now!

 

David.

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

david.prentice wrote:
Your brain is still required to find the solution.

+99 !!

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...