Step 1. Write your program in assembler in AVR Studio, build then save the hex file.
Step 2. Go into the command prompt and invoke avrdude with the right switches.
I started with the usual Arduino C blink program, just to make sure I got the COM port right and to see the hardware was all working. Then did steps above.
Below are some relevant screen shots.
Blink for AVR Studio 4 assembler
.include "m328pdef.inc"
;Based on http://www.robertoinzerillo.com/wordpress/?p=5
;-----------------------------------------;
; FIRST WE'LL DEFINE SOME REGISTER TO USE ;
;-----------------------------------------;
.DEF A = R16 ;GENERAL PURPOSE ACCUMULATOR
.DEF I = R21 ;INDEXES FOR LOOP CONTROL
.ORG $0000
;-----------------------------------------;
; FIRST WE SETUP A STACK AREA THEN SET ;
; DIRECTION BIT ON PORT-B FOR OUTPUT/SPKR ;
;-----------------------------------------;
START:
LDI A,LOW(RAMEND) ;SETUP STACK POINTER
OUT SPL,A ;SO CALLS TO SUBROUTINES
LDI A,HIGH(RAMEND) ;SETUP STACK POINTER
OUT SPH,A ;SO CALLS TO SUBROUTINES
LDI A,0b1111_1111 ;SET ALL PORTB FOR OUTPUT
OUT DDRB,A ;WRITE 1s TO DIRECTN REGS
;--------------;
; MAIN ROUTINE ;
;--------------;
LEDONOFF:
SER A
OUT PORTB,A
RCALL DELAYLONG
CLR A
OUT PORTB,A
RCALL DELAYLONG
RJMP LEDONOFF
DELAYLONG:
; =============================
; Delaying approximately 1 sec at 8Mhz.
; This code has been created with “AVR Delay Loop Generator V1.2?.
ldi R17, $48
WGLOOP0: ldi R18, $BC
WGLOOP1: ldi R19, $C4
WGLOOP2: dec R19
brne WGLOOP2
dec R18
brne WGLOOP1
dec R17
brne WGLOOP0
; =============================
RET
No comments:
Post a Comment