Code:
;+----------------------------------------------------------------------
;| Title : myAVR Grundgerüst für ATmega8
;+----------------------------------------------------------------------
;| Funktion : ...
;| Schaltung : ...
;+----------------------------------------------------------------------
;| Prozessor : ATmega8
;| Takt : 3,6864 MHz
;| Sprache : Assembler
;| Datum : ...
;| Version : ...
;| Autor : ...
;+----------------------------------------------------------------------
.include "AVR.H"
;------------------------------------------------------------------------
;Reset and Interrupt vector ;VNr. Beschreibung
rjmp main ;1 POWER ON RESET
reti ;2 Int0-Interrupt
reti ;3 Int1-Interrupt
reti ;4 TC2 Compare Match
reti ;5 TC2 Overflow
reti ;6 TC1 Capture
reti ;7 TC1 Compare Match A
reti ;8 TC1 Compare Match B
reti ;9 TC1 Overflow
reti ;10 TC0 Overflow
reti ;11 SPI, STC Serial Transfer Complete
reti ;12 UART Rx Complete
reti ;13 UART Data Register Empty
reti ;14 UART Tx Complete
reti ;15 ADC Conversion Complete
reti ;16 EEPROM Ready
reti ;17 Analog Comparator
reti ;18 TWI (I²C) Serial Interface
reti ;19 Store Program Memory Ready
;------------------------------------------------------------------------
;Start, Power ON, Reset
main: ldi r16,lo8(RAMEND)
out SPL,r16
ldi r16,hi8(RAMEND)
out SPH,r16
ldi r16,0b11111111
out DDRB,r16
out DDRD,r16
ldi r16,0b00000000
out DDRC,r16
ldi r16,0b01100010
out ADMUX,r16
ldi r16,0b11100010
out ADCSRA,r16
ldi r16,0b00000101 ;prescaler 1/1024
out TCCR0,r16
ldi r16,0b00000000
out EEARH,r16
out EEARL,r16
ldi r28,255 ;dienen zur write oder
ldi r29,0 ; read Anzeige und werden auf PORTD gschoben
;Hier Init-Code eintragen.
;------------------------------------------------------------------------
mainloop: wdr
bis_converted:
in r16,ADCSRA ;auf conversion complete warten
ori r16,0b11101111 ;Wert von r16 verändert!
cpi r16,0b11111111 ;
breq ausgabe
rjmp bis_converted
ausgabe:
out PORTD,r28;zeigt durch PORTD = 255 EEPROM write access an
in r25,ADCH;Aufnahme des ADC Wertes
mov r30,r25
rcall wandeln
rcall marke
rcall ew
inc r26
cpi r26,255
breq lesen
rjmp bis_converted
lesen:
out PORTD,r29 ;zeigt durch PORTD = 0 read access an
rcall er
mov r30,r25
rcall wandeln
rcall marke
dec r26
cpi r26,0b00000000
breq bis_converted
rjmp lesen
;_______________________________________________Quellcode
ew:
eprom_write:
sbic EECR,0b00000010
rjmp eprom_write
out EEARH,r27 ;adresse
out EEARL,r26 ;adresse
out EEDR,r25 ;write value
sbi EECR,0b00000100 ;write srobe
sbi EECR,0b00000010 ;EEWE signt eeprom access - cleared after 4 clock cycles
ret ;Hier den Quellcode eintragen.
er:
eprom_read:
sbic EECR,0b00000010
rjmp eprom_read
out EEARH,r27 ;adresse
out EEARL,r26 ;adresse
sbi EECR,0b00000001
in r25,EEDR
ret
marke:
bis255:
in r16,TCNT0 ;Verzögerung
cpi r16,255
brne bis255
inc r17
cpi r17,2
brne bis255
ret
wandeln: ;da der mega8 pro Port
mov r31,r30 ; nur über 5 BIT´s verfügt,
lsr r31 ;/2 wird so geshiftet, dass zusammen
lsr r31 ;mit PORTD dann 8 BIT angezeigt
;werden können/ hier noch nicht genutzt
lsl r30 ;*2
lsl r30
lsl r30
lsl r30
lsl r30
lsl r30
out PORTB,r31
ret
Lesezeichen