While loop not working (Solved)

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

Hello!

Sorry if this very same problem was discussed before, but for some unknown reason the search of the forum always give me a blank page with "NO DATA RECEIVED" error message.

I have a problem with a while loop and I´m unable to realize what I did wrong. Please, someone can point me what is wrong with this piece of code?

While (seconds <= 0x14)
   {
      if (((PINB & 0x0f)==0x0b) & ((PINB & 0x10)==0x10) )	
      {
        _delay_ms(1000);
        status();
      }
   }
LINE_OFF;

The idea was, for some seconds (modified by timer interrupt), stay waiting for a specific change in port B, which if occurs, would execute those two lines inside if statement. After those seconds, should reach the LINE_OFF.

The problem is even with the seconds variable in While loop is over 0x14 the processing will not leave the while loop.

Ps: I´m using Atmel Studio 6.2.993 with attiny2313A.

Any comment will be welcome.

Good Soldering JRGandara

Last Edited: Sat. Jun 7, 2014 - 09:10 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

FAQ#1

I bet "seconds" is updated in an ISR and needs to be volatile.

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

Side note:

      if (((PINB & 0x0f)==0x0b) & ((PINB & 0x10)==0x10) )

The second AND should be a logical one (not a bitwise one):

      if (((PINB & 0x0f)==0x0b) && ((PINB & 0x10)==0x10) )

It'll work with your mistake in this certain but this kind of mistake will bite you sooner or later.

Quote:
for some unknown reason the search of the forum always give me a blank page with "NO DATA RECEIVED" error message

Yup. This happens often. The search function here is flawed, to put it gently. Tinkering with search criteria will make it work most of the time. Consider using Google, directed to this specific site, as an alternative.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

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

Thank you both!

The seconds should be volatile and it was not. Solve the problem!

Although I have experimented with C few years ago, I still have not enough experience. Now I will have more contact with this language and I have to learn one way or another.

Good Soldering JRGandara

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

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

 if (((PINB & 0x0f)==0x0b) & ((PINB & 0x10)==0x10) )

Can you not simplify this to:

 if ((PINB & 0x1f)==0x1b)

Regards,
Steve A.

The Board helps those that help themselves.

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

Thank you Clawson for the tutorial and Koshchi for the tip.

Good Soldering JRGandara

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

JohanEkdahl wrote:
Quote:
for some unknown reason the search of the forum always give me a blank page with "NO DATA RECEIVED" error message
Yup. This happens often. The search function here is flawed, to put it gently. Tinkering with search criteria will make it work most of the time. Consider using Google, directed to this specific site, as an alternative.
I have found this to be the result of too-common a search term, such as 'compiler' or 'avr'. The search engine probably barfs when there are too many results.

The problem persists even if you combine the common term(s) with less common ones. Searching for 'avr' and 'asdfasdf' (with 'Search for all terms') will nevertheless fail.

Try to use less common search terms which are still descriptive of and unique to your problem.

The trick of course is knowing how to do that. After all, you're searching because you don't know!

A better bet in some cases is to use Google to search for keywords or phrases, and add site:avrfreaks.net to the search terms.

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]