Thoroughly recommended is the evaluation kit, STK200 from ATMEL.
Here is a `hello world' example with walking leds.
;*******************************************************************
; avrwalk.asm
;
; This code walks LEDs backwards and forwards on port b.
; Connect leds from port b (via current limiting Rs) to +5V.
; This code is also compatible with STK200.
;*******************************************************************
;***** Specify Device
.device AT90S1200
;***** I/O Register Definitions
.equ PORTB =$18 ; port b data register
.equ DDRB =$17 ; port b data direction register
.equ PINB =$16 ; port b input pins register
;
;
;
; can only use R16 to R31 for constants
; and logic instructions such as SBCI, SUBI, CPI, ANDI and ORI
; and most importantly LDI!
.def tempport =r16
.def count1 =r17 ; and logic instructions
.def count2 =r18
.def XL =r26
.def XH =r27
.def YL =r28
.def YH =r29
.def ZL =r30
.def ZH =r31
;******************************************************************
.cseg ;CODE segment
.org 0
rjmp init ; origin
.org 4
init:
ldi tempport,$FF
out DDRB,tempport ; set portb as outputs
ser tempport
out PORTB,tempport ; set portb levels all high
start:
ldi tempport,$FE ; set tempport bit 0 low
out PORTB,tempport ; write to port
rot_L:
rcall wait ; wait for a bit
sec ; set the carry bit
rol tempport ; rotate left tempport
out PORTB,tempport ; write to port
sbrc tempport,7 ; skip next line if top bit clr
rjmp rot_L
rot_R:
rcall wait
sec ; set the carry bit
ror tempport ; rotate right tempport
out PORTB,tempport ; write to port
sbrc tempport,0 ; skip next line if bottom bit clr
rjmp rot_R
rjmp rot_L ; do it all again
; ----------------------------
; wait subroutine
; ----------------------------
wait:
ldi count1,200 ; load count1 with decimal 200
d1:
ldi count2,200 ; load count2 with decimal 200
d2:
dec count2 ; decrement count2
brne d2 ; loop if not zero
dec count1 ; decrement count1 if count2 is zero
brne d1 ; do inside loop again if count2 nz
ret
; ----------------------------
Return to the Beginners' PIC and AVR page