Society of Robots - Robot Forum

Software => Software => Topic started by: santiago on May 17, 2010, 05:31:25 PM

Title: what is wrong with this little code?
Post by: santiago on May 17, 2010, 05:31:25 PM
This is just a code that I'm trying to use with AVRStudio 4 in C but it doesn't compile. What is wrong with it?
I simply want to read PINB and map it to PORTA, like this: PORTA = PINB;
However, I get like 4 errors. What's wrong?  (this code is not originally mine).


/********************************************************************************
                  Includes
********************************************************************************/
#include <avr/io.h>
#include <stdbool.h>

/********************************************************************************
                  Main
********************************************************************************/
int main(void) {
   // configure PORTA as output
   DDRA = 0xFF;
   // configure PORTB as input
   DDRB = 0;
   // make sure PORTB is high impedance and will not source
   PORTB = 0;
   // main loop
   while (true) {
      // map PINB switches to PORTA
      PORTA = PINB;
   }
}
Title: Re: what is wrong with this little code?
Post by: GearMotion on May 17, 2010, 05:45:14 PM
I assume one of your errors is "Line 1: Didn't remember to post errors in thread."
Title: Re: what is wrong with this little code?
Post by: santiago on May 17, 2010, 05:58:31 PM
the errors are the following:
../Switches.c :20:error:DDRA' undeclared (first used in this function)
../Switches.c :20:error:(Each undeclared identifier is reported only once)
../Switches.c :20:error:for each function it appears in.)
../Switches.c:37:error:'PORTA' undeclared(first used in this function)
Make:***(Swiches.o)error 1
Build failed with 4 errors and 0 warnings...
Title: Re: what is wrong with this little code?
Post by: Webbot on May 17, 2010, 06:11:32 PM
What ATMega are you using?
Title: Re: what is wrong with this little code?
Post by: santiago on May 17, 2010, 07:09:38 PM
I'am using Atmega8
Title: Re: what is wrong with this little code?
Post by: Webbot on May 17, 2010, 07:22:39 PM
Then the answer is that the ATMega8 does not have a PORTA (nor DDRA, PINA)
It only has PORTB, PORTC and PORTD.
Title: Re: what is wrong with this little code?
Post by: santiago on May 17, 2010, 09:21:51 PM
Yes ofcourse! I knew that! Thanks for that. Wow, I can't believe I didn't see that. I must be getting younger. Hahaaa.

Thanks