AVR development without Arduino IDE

arduino is a great tool when you're trying to quickly whip together a prototype for a project. the reason of its success is due to it simplifying the whole process of programming an AVR MCU.

there's four essential components to this task;

here's the example program we'll be uploading

#define F_CPU 16000000L /* frequency */
#include <util/delay.h>
#include <avr/io.h>


main() {
    /* data direction */
    DDRD = _BV(PD5);

    for (;;) {
        PORTB ^= _BV(PB5);
        _delay_ms(500);
    }
}

the order we'll compile it in;

avr-gcc -mmcu=atmega328p -o pgm.elf pgm.c
avr-objcopy -j .text -j .data -o ihex pgm.elf pgm.hex

and to upload it

avrdude -qq -P /dev/ttyUSB0 -b 57000 -c usbtiny -p m328p -U flash:w:pgm.hex

where /dev/ttyUSB0 is the device node associated with the ISP, 57000 is the baud/bps rate, usbtiny is the programmer type/id, and m328p is the part#/MCU.

if you don't wanna dish out for a "genuine" USBTiny ISP, I suggest going on aliexpress. I got mine for around $3.50, and haven't had any problems yet.

see also; avrdude option descriptions