go_away

Author Topic: what is wrong with this little code?  (Read 998 times)

0 Members and 1 Guest are viewing this topic.

Offline santiagoTopic starter

  • Jr. Member
  • **
  • Posts: 32
  • Helpful? 0
what is wrong with this little code?
« 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;
   }
}

Offline GearMotion

  • Supreme Robot
  • *****
  • Posts: 489
  • Helpful? 24
  • Two decades+ of Embedded Design
Re: what is wrong with this little code?
« Reply #1 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."

Offline santiagoTopic starter

  • Jr. Member
  • **
  • Posts: 32
  • Helpful? 0
Re: what is wrong with this little code?
« Reply #2 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...

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,132
  • Helpful? 108
Re: what is wrong with this little code?
« Reply #3 on: May 17, 2010, 06:11:32 PM »
What ATMega are you using?
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline santiagoTopic starter

  • Jr. Member
  • **
  • Posts: 32
  • Helpful? 0
Re: what is wrong with this little code?
« Reply #4 on: May 17, 2010, 07:09:38 PM »
I'am using Atmega8

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,132
  • Helpful? 108
Re: what is wrong with this little code?
« Reply #5 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.
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline santiagoTopic starter

  • Jr. Member
  • **
  • Posts: 32
  • Helpful? 0
Re: what is wrong with this little code?
« Reply #6 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

 


Get Your Ad Here