Society of Robots - Robot Forum
Software => Software => Topic started 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;
}
}
-
I assume one of your errors is "Line 1: Didn't remember to post errors in thread."
-
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...
-
What ATMega are you using?
-
I'am using Atmega8
-
Then the answer is that the ATMega8 does not have a PORTA (nor DDRA, PINA)
It only has PORTB, PORTC and PORTD.
-
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