Code:
.include "tn13def.inc"
.equ TIMERVALUE = 256 - 30
.equ LEDDDR = DDRB
.equ LEDPORT = PORTB
.equ LED1 = PB0
.equ LED2 = PB1
.equ LED3 = PB2
.equ LED4 = PB3
.equ LED5 = PB4
.equ LED6 = DDB5
.def sregsav = R1
.def time1 = R2
.def time2 = R3
.def time3 = R4
.def time4 = R5
.def time5 = R6
.def time6 = R7
.def schritt1 = R8
.def schritt2 = R9
.def schritt3 = R10
.def schritt4 = R11
.def schritt5 = R12
.def schritt6 = R13
.def tmp1 = R16
.def tmp2 = R17
.def tmp3 = R18
.def tmpi1 = R19
.org 0x0000
rjmp reset
.org TIM0_OVF0addr
rjmp timer5ms
reset:
ldi tmp1,RAMEND
out SPL,tmp1
ldi tmp1,(1<<LED1)|(1<<LED2)|(1<<LED3)|(1<<LED4)|(1<<LED5)
out LEDDDR,tmp1
;; Timer 0
ldi tmp1,(1<<CS02)
out TCCR0B,tmp1
ldi tmp1,(1<<TOIE0)
out TIMSK0,tmp1
ldi tmp1,TIMERVALUE
out TCNT0,tmp1
sei
ldi tmp3,1
clr tmp2
clr schritt1
clr schritt2
clr schritt3
clr schritt4
clr schritt5
clr schritt6
loop:
tst time1
brne loop_1
rjmp led1update
loop_1:
tst time2
brne loop_2
rjmp led2update
loop_2:
tst time3
brne loop_3
rjmp led3update
loop_3:
tst time4
brne loop_4
rjmp led4update
loop_4:
tst time5
brne loop_5
rjmp led5update
loop_5:
tst time6
brne loop
; rjmp led6update RESET erstmal weg
rjmp loop
led1update:
ldi ZH,HIGH(timesled1*2)
ldi ZL,LOW(timesled1*2)
add ZL,schritt1
adc ZH,tmp2
lpm
cp R0,tmp2
breq led1update1
sbi LEDPORT,LED1
rjmp led1update2
led1update1:
cbi LEDPORT,LED1
led1update2:
add ZL,tmp3
adc ZH,tmp2
lpm
mov time1,R0
inc schritt1
inc schritt1
ldi tmp1,8
cp schritt1,tmp1
brlo loop
clr schritt1
rjmp loop
led2update:
ldi ZH,HIGH(timesled2*2)
ldi ZL,LOW(timesled2*2)
add ZL,schritt2
adc ZH,tmp2
lpm
cp R0,tmp2
breq led2update1
sbi LEDPORT,LED2
rjmp led2update2
led2update1:
cbi LEDPORT,LED2
led2update2:
add ZL,tmp3
adc ZH,tmp2
lpm
mov time2,R0
inc schritt2
inc schritt2
ldi tmp1,4
cp schritt2,tmp1
brlo loop
clr schritt2
rjmp loop
led3update:
ldi ZH,HIGH(timesled3*2)
ldi ZL,LOW(timesled3*2)
add ZL,schritt3
adc ZH,tmp2
lpm
cp R0,tmp2
breq led3update1
sbi LEDPORT,LED3
rjmp led3update2
led3update1:
cbi LEDPORT,LED3
led3update2:
add ZL,tmp3
adc ZH,tmp2
lpm
mov time3,R0
inc schritt3
inc schritt3
ldi tmp1,4
cp schritt3,tmp1
brlo led3update3
clr schritt3
led3update3:
rjmp loop
led4update:
ldi ZH,HIGH(timesled4*2)
ldi ZL,LOW(timesled4*2)
add ZL,schritt4
adc ZH,tmp2
lpm
cp R0,tmp2
breq led4update1
sbi LEDPORT,LED4
rjmp led4update2
led4update1:
cbi LEDPORT,LED4
led4update2:
add ZL,tmp3
adc ZH,tmp2
lpm
mov time4,R0
inc schritt4
inc schritt4
ldi tmp1,14
cp schritt4,tmp1
brlo led4update3
clr schritt4
led4update3:
rjmp loop
led5update:
ldi ZH,HIGH(timesled5*2)
ldi ZL,LOW(timesled5*2)
add ZL,schritt5
adc ZH,tmp2
lpm
cp R0,tmp2
breq led5update1
sbi LEDPORT,LED5
rjmp led5update2
led5update1:
cbi LEDPORT,LED5
led5update2:
add ZL,tmp3
adc ZH,tmp2
lpm
mov time5,R0
inc schritt5
inc schritt5
ldi tmp1,14
cp schritt5,tmp1
brlo led5update3
clr schritt5
led5update3:
rjmp loop
led6update:
ldi ZH,HIGH(timesled6*2)
ldi ZL,LOW(timesled6*2)
add ZL,schritt6
adc ZH,tmp2
lpm
cp R0,tmp2
breq led6update1
cbi DDRB,LED6
rjmp led6update2
led6update1:
sbi DDRB,LED6
led6update2:
add ZL,tmp3
adc ZH,tmp2
lpm
mov time6,R0
inc schritt6
inc schritt6
ldi tmp1,14
cp schritt6,tmp1
brlo led6update3
clr schritt6
led6update3:
rjmp loop
timer5ms:
in sregsav,SREG
clr tmpi1
cpse time1,tmpi1
dec time1
cpse time2,tmpi1
dec time2
cpse time3,tmpi1
dec time3
cpse time4,tmpi1
dec time4
cpse time5,tmpi1
dec time5
cpse time6,tmpi1
dec time6
ldi tmpi1,TIMERVALUE
out TCNT0,tmpi1
out SREG,sregsav
reti
timesled1:
.db 0,10,1,10,0,10,1,100
timesled2:
.db 0,10,1,100
timesled3:
.db 0,100,1,100
timesled4:
.db 1,100,0,7,1,7,1,7,1,7,1,7,1,7
timesled5:
.db 1,100,1,7,1,7,0,7,1,7,1,7,1,7
timesled6:
.db 1,100,1,7,1,7,1,7,1,7,0,7,1,7
Wenn es zu langsamm oder zu schnell blinkt mußt Du TIMERVALUE anpassen.
Lesezeichen