is there an assembler example (e.g. blink.s) with command line build and
upload instructions available for Duemilanove ?
I found the following code example, but do not really know how to use it.
Got errors when try to compile
That looks like Atmel Assembler (the "*.inc" filenames are giveaways; the gnu assembler uses the same .h files as the C compiler.)
Are you specifically wanting to use the gnu tools?
Code modified for gnu assembler, and adding (approximately) delay_n_ms:
; Assembly Code:
;;; Allow us to use names like "PORTB"
#define __SFR_OFFSET 0
#include "avr/io.h"
start:
SBI DDRB,5
blink: LDI r20,250
CALL delay_n_ms
SBI PORTB,5
LDI r20,250
CALL delay_n_ms
CBI PORTB,5
JMP blink
delay_n_ms:
;;; Delay about r20*1ms. Destroys r20, r30, and r31.
;;; One millisecond is about 16000 cycles at 16MHz.
;;; The basic loop takes about 5 cycles, so we need about 3000 loops.
ldi 31, 3000>>8 ; high(3000)
ldi 30, 3000&255 ; low(3000)
delaylp:
sbiw r30, 1
brne delaylp
subi r20, 1
brne delay_n_ms
ret
Compile: (note that this uses the C compiler front end, cause that's the part that knows where the .include files are and etc.)
avr-gcc -mmcu=atmega328p -nostartfiles foo.S
Convert to .hex:
avr-objcopy -O ihex a.out foo.hex
I think you need to use a capital S for the file extension if you want gcc to know to use the C preprocessor on the file (which it needs to do for the #include and #define.)
Edit: yep:
BillW-MacOSX-2<5004> avr-gcc -mmcu=atmega328p -nostartfiles foo.S
(no errors)
BillW-MacOSX-2<5005> cp foo.S bar.s
BillW-MacOSX-2<5006> avr-gcc -mmcu=atmega328p -nostartfiles bar.s
bar.s: Assembler messages:
bar.s:10: Error: constant value required
bar.s:15: Error: constant value required
bar.s:18: Error: constant value required
sbi 4,5; set ddrb as output (pin13)
Loop:; Label name
sbi 5,5;set bit 5 from portb
call Delay; call subroutine and save prog counter
cbi 5,5;clear bit 5 from portb
call Delay; call subroutine again to.....
rjmp LOOP; jump to label nam loop, start over
Delay:;label name
sbr r18, 0xff;put 11111111 in rigister r18
sbr r17, 0xff;put 11111111 in rigister r17
sbr r16, 0xff;put 11111111 in rigister r16
wait:;label name
dec r16 ;Decrement r16 (-1)
brne wait; jump to label name wait if <> zero
dec r17 ;Decrement r16 (-1)
brne wait;jump to label name wait if <> zero
dec r18;Decrement r16 (-1)
brne wait;jump to label name wait if <> zero
ret;go back to call --> pc +1