quote:
'k heb niet echt veel assembly op de hd die ik op 't heden moment heb meegenomen (ben niet thuis), maar hier is nog 'n vingeroefeningetje:
.include "m16def.inc"
.def Temp =r16 ; Temporary register
.def Temp2 =r17
.def Temp3 =r18
.def Delay =r19 ; Delay variable 1
.def Delay2 =r20 ; Delay variable 2
.def Richting =r21 ; Richtingsvector 0=rechts 1 = links
.def VectorL =r22 ; Vorige Links
.def VectorR =r23 ; Vorige Rechts
.def All =r24
; ***** Initialization
RESET:
LDI Temp, HIGH(RAMEND) ; Upper byte
OUT SPH,Temp ; to stack pointer
LDI Temp, LOW(RAMEND) ; Lower byte
OUT SPL,Temp ; to stack pointer
ldi All, 0xFF
Call Aan
ldi VectorL, 0x01
ldi VectorR, 0x00
ldi Temp, 0x01
com Temp
out PORTB, Temp ; Set PORTB to output
; ***** Test input/output
LOOP:
;Zet de vorige leds in de temp2
mov temp2, temp
;Check als lampje aan het begin of eind is dan moet het terug gaan.
sbis PINB, 0x00
call goRight
sbis PINB, 0x07
call goLeft
;Is de richting Links is dan linksom
cpse Richting, VectorL
rol Temp
;Is de richting Links is dan linksom
cpse Richting, VectorR
ror Temp
;Update LEDS
out PORTB, Temp
sbis PIND, 0x00
call checkLed
sbis PIND, 0x01
call checkLed
sbis PIND, 0x02
call checkLed
sbis PIND, 0x03
call checkLed
sbis PIND, 0x04
call checkLed
sbis PIND, 0x05
call checkLed
sbis PIND, 0x06
call checkLed
sbis PIND, 0x07
call checkLed
;sbic DDRD, 0x06
;call checkDirection
;sbic DDRD, 0x01
;call checkDirection
;sbis PIND, 0x00 ; If (Port D, pin0 == 0)
;inc Temp ; then count LEDS one down
;sbis PIND, 0x01 ; If (Port D, pin1 == 0)
;dec Temp ; then count LEDS one up
;sbis PIND, 0x02 ; If (Port D, pin2 == 0)
;ror Temp ; then rotate LEDS one right
;sbis PIND, 0x03 ; If (Port D, pin3 == 0)
;rol Temp ; then rotate LEDS one left
;sbis PIND, 0x04 ; If (Port D, pin4 == 0)
;com Temp ; then invert all LEDS
;sbis PIND, 0x05 ; If (Port D, pin5 == 0)
;neg Temp ; then invert all LEDS and add 1
;sbis PIND, 0x06 ; If (Port D, pin6 == 0)
;swap Temp ; then swap nibbles of LEDS
; ***** Now wait a while to make LED changes visible.
call initDelay
DLY:
dec Delay
brne DLY
dec Delay2
brne DLY
rjmp LOOP
goLeft:
ldi Richting, 0x01
ret
goRight:
ldi Richting, 0x00
ret
checkDirection:
cpse Richting, VectorL
rol Temp
cpse Richting, VectorL
rol Temp
cpse Richting, VectorR
ror Temp
cpse Richting, VectorR
ror Temp
ret
;---------------------------------------
;Voegt een extra led toe als er op gedrukt is!
checkLed:
in Temp3, PIND
;com Temp2
cpse Temp2, Temp3
rjmp Eraf
Voegtoe:
;Tel erbij op!
and Temp, Temp2
rjmp Einde
Eraf:
or Temp, Temp2
rjmp Einde
Einde:
ret
;---------------------------------------
;---------------------------------------
;Stelt DDRB in als uitgang
Aan:
out DDRB, All
out DDRC, All
ret
;---------------------------------------