check the code.

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

here look at this code i copied from internet.
#include "avr\io.h"
#include "avr\iom8.h"
int main(void) {
DDRD&=~_BV(0);//set PORTD pin0 to zero as input
PORTD|=_BV(0);//Enable pull up
PORTD|=_BV(1);//led OFF
DDRD|=_BV(1);//set PORTD pin1 to one as output
while(1) {
if (bit_is_clear(PIND, 0))//if button is pressed
{
PORTD&=~_BV(1);//led ON
loop_until_bit_is_set(PIND, 0);//LED ON while Button is pressd
PORTD|=_BV(1);//led OFF
}
}
}

now my que is
1. while making pin1 as output guy has first made port as 1 then ddr is made equal to 1 it should be reversed in order i mean first make pin as output then turn it on. moreover he has written led off should be on..
2. in while loop he used bit_is_clear function and loop_until_bit_is_set. are these funtions predefined in some predefined librairy iom8.h. i mean is this library already there or he has jst created it himself .if functions exists which i am hoping they are what is there defination what does they do???

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

Do not include iom8.h. All of the processor dependent definitions will be added by avr\io.h

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

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

Quote:

moreover he has written led off should be on..

That depends completely on how the LED has been wired up to the AVR. Ity is very common to have switches or LEDs (or both) wired up as "active low", i.e. the LED is off when you write a 1 to the port pin, and on when you write a zero.

Quote:

in while loop he used bit_is_clear function and loop_until_bit_is_set. are these funtions predefined in some predefined librairy iom8.h.

Not in iom8.h, at least. (And as has been noted above, this file should not be explicitly included in code at all).

Did the code not have any additional #includes that you have chosen not to show?

Have you searched this forum for "bit_is_clear" and "loop_until_bit_is_set"? Go over to the tutorials forum ans locate the tutorial on "Bit manipulation" and you will most certainly find implementations of such functions/macros in that thread.

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

Oh, a gentle hint for avoiding future complaints.

You will notice, above the edit window, a button captioned "Code". Just before you start entering code, click that button. Click, again, at the end of the code.

Now, the code will be in a separate box, properly obeying indents and such. Many will not take the time to analyze it unless it is Code format.

You can also enter your code, highlight the code, and click the Code button. It will add the proper formatting tags. Here is an example using more or less random code:

void main( void ) {
   
   while(1) (

        if ( (PORTB & (1<<PB6)) 
            PORTB |= (1<<PB1);
        else
            PORTB &= ~(1<<PB1);
        } //end while

    } //end of main

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

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

well thnx.
even if led pin is active low.isnt it customary to initialise ddr register first???
n no other includes are there and i couldnt find any reference on any forum on what bit_is_clear and other funtion do thats why i thought that may be its defined by writer himself but he forgot to include the file

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

Suggest you get into the habit of reading the user manual ;-)

www. nongnu.org/avr-libc/user-manual/group__avr__sfr.html

I had to murder that URL to get past the spam filter so it will need to be repaired to use it.

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

Just leave off the "www.". A good browser :wink: should work without it.

"I may make you feel but I can't make you think" - Jethro Tull - Thick As A Brick

"void transmigratus(void) {transmigratus();} // recursio infinitus" - larryvc

"It's much more practical to rely on the processing powers of the real debugger, i.e. the one between the keyboard and chair." - JW wek3

"When you arise in the morning think of what a privilege it is to be alive: to breathe, to think, to enjoy, to love." -  Marcus Aurelius

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

OK ... having had my original post classified as spam a couple of days ago, I will use this attempt as both a test of the "fixed" Molly and a reply about bit_is_clear

Googling "avr-gcc bit_is_clear" produces this subset of the help file.

http://www.nongnu.org/avr-libc/u...

Cheers,

Ross

edit. Yea ... it works!

Ross McKenzie, Melbourne Australia

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

larryvc wrote:
Just leave off the "www.". A good browser :wink: should work without it.

AFAIK that actually depends on the webserver, not the browser ;)

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

jayjay1974 wrote:
AFAIK that actually depends on the webserver, not the browser ;)

Shh!!! Don't ruin my joke. :wink:

"I may make you feel but I can't make you think" - Jethro Tull - Thick As A Brick

"void transmigratus(void) {transmigratus();} // recursio infinitus" - larryvc

"It's much more practical to rely on the processing powers of the real debugger, i.e. the one between the keyboard and chair." - JW wek3

"When you arise in the morning think of what a privilege it is to be alive: to breathe, to think, to enjoy, to love." -  Marcus Aurelius

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

jayjay1974 wrote:
larryvc wrote:
Just leave off the "www.". A good browser :wink: should work without it.

AFAIK that actually depends on the webserver, not the browser ;)

Actually, it depends on the DNS records on the internet for the domain in question...;)