Code:
.include"m8def.inc"
.org 0x0000
rjmp reset
.org OC2addr ; OCR2 Interrupt Vector Address
rjmp hitvalue
reset:
ldi r16,HIGH(RAMEND)
out SPH,r16
ldi r16,LOW(RAMEND)
out SPL,r16
ldi r16,0b00000000
out DDRB,r16
out PORTB,r16
ldi r16,0b10000000
out TIMSK,r16
ldi r16,0b01101001
out TCCR2, r16; fast PWM,
ldi r16,255
out ICR1H,r16
out ICR1L,r16
ldi r16,255
out OCR1AL,r16
ldi r16,0b10100010
out TCCR1A,r16; clear on match, compare output, fast PWM => ICR1A = Top
ldi r16,0b00011001
out TCCR1B,r16; fast PWM => ICR1A = Top, prescaler = 1
sei
main:
;**********************
;Erfassung Dimmwert
;
ldi r16,0b00100000
out ADMUX,r16
ldi r16,0b11010101
out ADCSRA,r16
warten0:
in r16,ADCSRA
sbrs r16,4
rjmp warten0
in r18,ADCH ;DIMMER
ori r18,1
;**********************
ldi r16,0b00100011
out ADMUX,r16
ldi r16,0b11010101
out ADCSRA,r16
warten3:
in r16,ADCSRA
sbrs r16,4
rjmp warten3
in r21,ADCH
out OCR2,r21
;*********************************
;die gehen an die Comapre Units des Timer 1
;
ldi r16,0b00100001
out ADMUX,r16
ldi r16,0b11010101
out ADCSRA,r16
warten1:
in r16,ADCSRA
sbrs r16,4
rjmp warten1
in r19,ADCH
mul r18,r19
out OCR1AH,r1
out OCR1AL,r0
ldi r16,0b00100010
out ADMUX,r16
ldi r16,0b11010101
out ADCSRA,r16
warten2:
in r16,ADCSRA
sbrs r16,4
rjmp warten2
in r20,ADCH
mul r20,r18
out OCR1BH,r1
out OCR1BL,r0
;*********************************
rjmp main
hitvalue:
out DDRB,r27
inc r25;
;***************************
;hier wird die Bitkodierung des DDRB für den nächsten Durchgang
; vorrausberechnet
mov r26,r25;
inc r26;<<<<=== VORALLEM HIER!!!
cp r26,r18;
brlo ok;
ldi r27,0b00000110;
rjmp nicht_ok;
ok:;
ldi r27,0b00001110;
nicht_ok:;
;***************************
reti
Lesezeichen