Can someone help me with this code? Whenever I press a button I want the computer to print a statement. I have an Atmel STK500 development board. But it doesn't work; here's the code:

Code:

#include <avr/io.h> // avr header file for IO ports

int main(void){

DDRA = 0x00; // set PORTA for input

if(PORTA == 0x00){
printf("Hello!");
}
return 1;

}

09-21-2012

std10093

i do not know what DDRA or PORTA is,but i remember that main should return 0 in case of success :)

09-21-2012

jimblumberg

Does your AVR board have a console? Where do you expect to output anything?

Quote:

i do not know what DDRA or PORTA is,but i remember that main should return 0 in case of success

This is a microcontroller project board , PORTA is a digital input/output port and DDRA I believe is the Port A Data Direction Register, which controls whether the port is an input or output port. Also since this is a non-hosted environment returning a value from main() is not required.

Jim

09-21-2012

std10093

Quote:

Originally Posted by jimblumberg

This is a microcontroller project board , PORTA is a digital input/output port and DDRA I believe is the Port A Data Direction Register, which controls whether the port is an input or output port. Also since this is a non-hosted environment returning a value from main() is not required.

Jim

Oh yeah,from the greek word Πόρτα !Now it makes sense !thanks

09-21-2012

aosterminal

Thank you both, and std I tried switching the values for return but nothing changed (I think Jim just explained that). Also to clarify, my code builds and compiles but when I press the button on the board nothing happens :/ Any help?

09-21-2012

Matticus

I'll echo jimblumberg's question in post #3:

Quote:

Does your AVR board have a console? Where do you expect to output anything?

And which bit on PORTA is this button tied to?

And what is the expected polarity (logic high or logic low) when the button is pressed?

09-22-2012

aosterminal

Quote:

Originally Posted by Matticus

I'll echo jimblumberg's question in post #3:

And which bit on PORTA is this button tied to?

And what is the expected polarity (logic high or logic low) when the button is pressed?

Im sorry I didn't see that you asked that! I don't know if my board has a console :/ My teacher told me that I should be able to use printf() to output text to my computer monitor (with the board connected to my computer via RS232).

What is a bit? :3 Next to the first button it says SW0. I have what I believe is a port labelled "SWITCHES" connected to PORTA. On "SWITCHES" there are pins labelled SW0-SW7 that the wire is connected to, and on PORTA there are pins labelled PA0-PA7.

You can see for yourself on this picture if you zoom in, (I found this picture on the internet, same board though)

Does that help? I just want to press a button and have the AVR output text on my computer monitor! Thank you :)

09-22-2012

jimblumberg

If your compiler has been setup to use the RS-232 port as the console then you should be able to use printf() to print to this port. However you must also be running some kind of terminal program, HyperTerminal for example, on your PC in order to receive this information. Also in order for this to work you must know the communication port parameters. Both the PC and your board must both be using the same settings.

Please be aware that unless your compiler has been properly setup for your particular project board this communication will probably fail.