Code:
.include "m8def.inc"
.def temp=r16
.equ TIMERWERT=65536-3906
.equ TIMERWERT2=65536-7812
; INIT
ldi temp, LOW(RAMEND)
out spl, temp
ldi temp, HIGH(RAMEND)
out sph, temp
SBI DDRB, PB1 ;Datenrichtungsbit für alle Ports für die Motoren gesetzt
SBI DDRB, PB2
SBI DDRB, PB4
SBI DDRB, PB5
SBI DDRD, PD4
SBI DDRD, PD5
SBI DDRD, PD6 ;Front LED an
SBI PORTD, PD6
CBI DDRC, PC4
SBI PORTC, PC4
rjmp main_start
; Funktionen
motor_v_on:
SBI PORTB, PB1
SBI PORTB, PB2
SBI PORTB, PB5
SBI PORTD, PD5
ret
motor_v_off:
CBI PORTB, PB1
CBI PORTB, PB2
CBI PORTB, PB5
CBI PORTD, PD5
ret
motor_r_on:
SBI PORTB, PB1
SBI PORTB, PB2
SBI PORTB, PB4
SBI PORTD, PD4
ret
motor_r_off:
CBI PORTB, PB1
CBI PORTB, PB2
CBI PORTB, PB4
CBI PORTD, PD4
ret
rueckwaerts:
rcall motor_r_on
rcall timer_reset
rcall timer_schleife
rcall motor_r_off
ret
drehen:
rcall timer_reset2
SBI PORTB, PB4
rcall timer_schleife
CBI PORTB, PB4
ret
timer_reset:
ldi temp, HIGH(TIMERWERT)
out TCNT1H, temp
ldi temp, LOW(TIMERWERT)
out TCNT1L, temp
ldi temp, (1<<CS12)
out TCCR1B, temp
ret
timer_reset2:
ldi temp, HIGH(TIMERWERT2)
out TCNT1H, temp
ldi temp, LOW(TIMERWERT2)
out TCNT1L, temp
ldi temp, (1<<CS12)
out TCCR1B, temp
ret
timer_schleife:
IN temp, TOV1
sbrs temp, TOV1
rjmp timer_schleife
ldi temp,(1<<TOV1)
out TIFR, temp
ret
; Main
main_start:
rcall motor_v_on
main:
sbis PINC, 4
rjmp ausloesen
rjmp main
ausloesen:
rcall motor_v_off
rcall rueckwaerts
rcall drehen
rcall motor_v_on
rjmp main
Nur leider funktioniert es nicht wie gewünscht!
Lesezeichen