go_away

Author Topic: AVR help  (Read 489 times)

0 Members and 1 Guest are viewing this topic.

Offline roboninja93Topic starter

  • Jr. Member
  • **
  • Posts: 24
  • Helpful? 0
AVR help
« on: January 19, 2012, 01:11:11 PM »
hello
i am using atmega8 with avrstudio4 to compile the code..
for keeping led on(test program) i used the following code:
#include <avr/io.h>   
int main(void)
{
DDRC = 0xff;
while (1)
{
PORTC = 0x00;
}
return (0);
}
but its showing error with the included header <avr/io.h>
what are the headers i need to use?
Thanks

Offline newInRobotics

  • Supreme Robot
  • *****
  • Posts: 1,015
  • Helpful? 48
  • N.I.R.
Re: AVR help
« Reply #1 on: January 19, 2012, 02:37:08 PM »
Hi, Your code looks OK, and #include is used in a right way.

I would write code this way:
Code: [Select]
#include <avr/io.h>

int main(void)
{
      DDRC |= 1 << DDC0; //Set only PC0 to output
      PORTC |= 1 << PORTC0; //Set only PC0 HIGH

      for(;;;){} //Unlimited loop
}

Now, I see one mistake in Your code and that is PORTC = 0x00;, as this part of code would keep Your LED OFF all the time.

but its showing error with the included header <avr/io.h>
For AVRStudio4 You need to have WinAVR libraries installed separately. If You don't have them - compiler cannot find them. Go to Options and find out if library is linked (see attached image (it shows AVRStudio5, but it should similar (or maybe it isn't, I'm not sure  ;D))).

My advice is to get AVRStudio5 which is briliant IDE and comes together with libraries.
« Last Edit: January 19, 2012, 02:42:05 PM by newInRobotics »
"Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian W

 


Get Your Ad Here