Code:
.include "m8def.inc"
.def rBin1H = r0
.def rBin1L = r1
.def temp = r16 ; Arbeitsregister
.def temp2 = r17 ; Arbeitsregister
.def schwarzL = r18 ; Schwellwert für schwarz
.def schwarzH = r19
.def weisL = r20 ; Schwellwert für weiß
.def weisH = r21
.equ CLOCK = 8000000
.cseg
.org 0x000
rjmp Prog_Initial ; Interruptvektoren überspringen
reti ; INT0addr - Externer Interrupt 0
reti ; INT1addr - Externer Interrupt 1
reti ; OC2addr - Output Compare2
reti ; OVF2addr - Overflow2
reti ; ICP1addr - Input Capture1
reti ; OC1Aaddr - Output Compare1A
reti ; OC1Baddr - Output Compare1B
reti ; OVF1addr - Overflow1
reti ; OVF0addr - Overflow0
reti ; SPIaddr - SPI
reti ; URXCaddr - USART Receive Complete
reti ; UDREaddr - USART Data Register Empty
reti ; UTXCaddr - USART Transmit Complete
reti ; ADCCaddr - Analog Digital wandler
reti ; ERDYaddr - EEPROM
reti ; ACIaddr - Analog Comparator
reti ; TWIaddr - Two - Wire Interface
reti ; SPMaddr - SPM complete
Prog_Initial:
;******************************************************************************
; Stack Pointer setzen *
;******************************************************************************
ldi temp, LOW(RAMEND) ; Stack Pointer low
out SPL, temp ; setzen
ldi temp, HIGH(RAMEND) ; Stack Pointer high
out SPH, temp ; setzen
;******************************************************************************
;* Init LEDs *
;******************************************************************************
sbi DDRB, DDB0 ; Duo LED grün
sbi DDRD, DDD2 ; Duo LED rot
cbi PORTB, PORTB0 ; aus
cbi PORTD, PORTD2 ; schalten
sbi DDRD, DDD6 ; Front LED
cbi PORTD, PORTD6 ; aus
sbi DDRD, DDD7 ; Back LEDs
cbi PORTD, PORTD7
sbi DDRC, DDC0
sbi DDRC, DDC1
cbi PORTC, PORTC1
cbi PORTC, PORTC1 ; ausschalten
sei ; Interrupts erlauben
;**************** Ende Init **********************************************
Prog_Run:
rcall odometrie_led_on
rcall odo_ticks_rechts
rjmp Prog_Run
;******************************************************************************
; Odometrie Sensor Ticks Rechts *
;******************************************************************************
odo_ticks_rechts:
ldi schwarzL, 0x8A
ldi schwarzH, 0x02
ldi weisL, 0xC2
ldi weisH, 0x01
weis: ; schwarz -> weiß übergang
rcall odometrie_r
cp rBin1L, weisL ; compare aktuellen Wert
cpc rBin1H, weisH ; mit weiß
brlo wtiksplus3 ; branch wenn < schwellwert weiß
rjmp weis ; nein weiter warten
wtiksplus3:
rcall front_led_on
schwarz: ; weiß -> schwarz Übergang
rcall odometrie_r
cp rBin1L, schwarzL ; compare aktuellen Wert
cpc rBin1H, schwarzH ; mit schwarz
brsh wtiksplus4 ; branch wenn => schwellwert schwarz
rjmp schwarz ; nein weiter warten
wtiksplus4:
rcall front_led_off
rjmp weis
;******************************************************************************
; Odometrie LED On *
;******************************************************************************
odometrie_led_on:
cbi DDRC, DDC0 ; Richtungs Steuerung
cbi DDRC, DDC1 ; C= + C1 = INPUT
sbi PORTD, PORTD7 ; Odometrie LED On
ret
;******************************************************************************
; Odometrie Sensor Rechts *
;******************************************************************************
odometrie_r:
;ADMUX = (1 << REFS0) | WHEEL_RIGHT AVCC reference with external capacitor
LDI R30,0x27 ;Load immediate
LDI R31,0x00 ;Load immediate
LDI R24,0x40 ;Load immediate
STD Z+0,R24 ;Store indirect with displacement
;ADCSRA |= (1 << ADSC); // Start conversion
LDI R26,0x26 ;Load immediate
LDI R27,0x00 ;Load immediate
LDI R30,0x26 ;Load immediate
LDI R31,0x00 ;Load immediate
LDD R24,Z+0 ;Load indirect with displacement
ORI R24,0x40 ;Logical OR with immediate
ST X,R24 ;Store indirect
;while (!(ADCSRA & (1 << ADIF))) wait for conversion complete
lab2:
LDI R30,0x26 ;Load immediate
LDI R31,0x00 ;Load immediate
LDD R24,Z+0 ;Load indirect with displacement
CLR R25 ;Clear Register
ANDI R24,0x10 ;Logical AND with immediate
ANDI R25,0x00 ;Logical AND with immediate
SBIW R24,0x00 ;Subtract immediate from word
BREQ lab2 ;Branch if equal
;ADCSRA |= (1 << ADIF) clear ADCIF
LDI R26,0x26 ;Load immediate
LDI R27,0x00 ;Load immediate
LDI R30,0x26 ;Load immediate
LDI R31,0x00 ;Load immediate
LDD R24,Z+0 ;Load indirect with displacement
ORI R24,0x10 ;Logical OR with immediate
ST X,R24 ;Store indirect
;**************** Daten sichern und weiter Verarbeiten *********************
;data[1] = ADCL + (ADCH << 8);
in rBin1L, ADCL ; Ergebnis
in rBin1H, ADCH ; sichern
ret ;Subroutine return
;******************************************************************************
;* Front LED Ein *
;******************************************************************************
front_led_on:
sbi PORTD, PORTD6
ret
;******************************************************************************
;* Front LED Aus *
;******************************************************************************
front_led_off:
cbi PORTD, PORTD6
ret
MfG
Lesezeichen