I found your question while trying to do the exact same thing: program an existing Arduino board in pure AVR assembly without having to use any additional hardware. I ended up figuring out how to do it on my own, so I want to share my answer which anyone should be able to re-use on Windows.
First, download Atmel Studio. I'm using version 6.1. This will let you compile the AVR assembly code you write into a .hex
file which will be written to the microcontroller on the Arduino board. My Arduino board is an Arduino Uno which uses the ATmega328P chip, so select that when creating a new project in Atmel Studio.
If you're like me and trying to learn AVR Assembly, you will probably also want the 8-bit AVR Instruction Set guide which tells you what instructions you can use on the ATmega328P.
Here is the code I use to get a blinking LED on Arduino in pure assembly:
/*
* Get an LED blinking on the ATmega328 (Arduino)
* On Arduino, pin 13 has an on-board LED which blinks. Pin 13 should map to PB5 (SCK/PCINT5) on the MCU.
*/
.ORG 0x0000 // Tells the next instruction to be written
RJMP main // State that the program begins at the main label
main:
LDI r16, 0xFF // Load the immedate value 0xFF (all bits 1) into register 16
OUT DDRB, r16 // Set Data Direction Register B to output for all pins
loop:
SBI PortB, 5 // Set the 5th bit in PortB. (i.e. turn on the LED)
RCALL delay_05
CBI PortB, 5 // Clear the 5th bit in PortB. (i.e. turn off the LED)
RCALL delay_05
RJMP loop // Loop again
// Everything beneath is part of the delay loop
delay_05:
LDI r16, 8
outer_loop:
LDI r24, low(3037)
LDI r25, high(3037)
delay_loop:
ADIW r24, 1
BRNE delay_loop
DEC r16
BRNE outer_loop
RET
Locate the .hex
file that Atmel Studio creates when you compile the above code. Mine is in C:\Users\John\Documents\Atmel Studio\6.1\AssemblerApplication1\AssemblerApplication1\Debug
.
The Arduino IDE uses AVRdude to send the programs that you write in C to the Arduino board. You can see this by turning on verbose output in the Arduino IDE and watching what happens in the log. I found that using the same version of AVRdude that the Arduino IDE installs works well. Here is the command to upload your program to your Arduino:
"C:\Program Files (x86)\Arduino\hardware\tools\avr\bin\avrdude" -C avrdude.conf -v -p atmega328p -c arduino -P \\.\COM5 -b 115200 -D -U flash:w:compiled-code.hex:i
You'll need to use a different command if AVRdude is installed in a different spot. You'll also need to find your copy of avrdude.conf
and copy it (along with the .hex
file from the Debug
folder above) into the folder from which you'll run the above command. It's best to turn on the verbose output in the Arduino IDE and verify the correct command for yourself. (For instance, your Arduino might not be connected over COM5.)
You can read more about the options used by AVRdude on ladyada's AVR Tutorial. The instructions above won't work if you don't already have an Arduino working with the Arduino IDE- in other words, the Arduino bootloader must already be on your ATmega328 chip. This will not overwrite the bootloader, and you can easily switch from using this method of programming back to using the Arduino IDE with no headaches.