Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

AVR STUDIO (compiling C and running)

  1. Sep 17, 2009 #1
    okay i can compile the c file fine. but when i run it, its trying to connect through jtag and hardware. I just want to see the output of the compiled program!! any1 know how? thankyouu verry much
  2. jcsd
  3. Sep 18, 2009 #2


    User Avatar
    Science Advisor

    Are you aware that the AVR Compiler compiles to AVR machine code and needs to be run on an AVR microcontroller? If so (sorry, have to cover all the bases), and you're using a printf statement or two, that means that you need to wire up a DB-9 connector, hook it up to your computer's serial port, and use a terminal program to take input.

    If you don't want to go to all that trouble (or lack serial ports and/or a serial-to-USB converter), and you're just looking to do some kind of "Hello world!" thing, just hook up an LED and a resistor in series to one of the pins, and have it light up:

    Code (Text):

    #include <avr/io.h>
    #include <util/delay.h>

    #define F_CPU 8000000UL //change to whatever

    void _delay_1s(void)
    //1s delay routine
        int n;

        for(n=0; n<50; n++)
        {   _delay_ms(20);  }

    int main(void)
        DDRA |= 1 << PINA7;
        PORTA |= 1 << PINA7;
        for(;;) //toggle PIN A7 every second
            PORTA ^= (1 << PINA7);  //XOR existing value to toggle
    If not, and you're just looking for something to do a very simple program in, look into how to use the GCC compiler (Linux), Visual C++ (Windows, the personal edition is free), or XCode (Mac--also free)
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook