Code:
/*
.equ ADC_ddr = ddr?
.equ ADC_Port = Port?
.equ ADC_Pin = Pin?
.equ Chan0 = 0
.equ Chan1 = 1
.equ Chan2 = 2
.equ Chan3 = 3
.equ Chan4 = 4
.equ Chan5 = 5
.equ ref5 = $1312
.equ ref256 = $09d0
*/
;mit Interrupt
start_convers_int:
in temp0,adcsra ;wenn ADFR aktiv dann nur adc_read nötig für jeweiligen kanal
ori temp0,(0<<ADEN|1<<ADSC|0<<ADFR|1<<ADIE|1<<ADPS2|0<<ADPS1|0<<ADPS0) ;freigabe ADC Abtastrate zwischen 50Khz-200Khz Teiler=32 single mode
out adcsra,temp0 ;
sei
ret
;ohne Interrupt dann abfrage auf des bits ADSC=1?????
start_convers:
in temp0,adcsra
ori temp0,(0<<ADEN|1<<ADSC|0<<ADFR|0<<ADIE|1<<ADPS2|0<<ADPS1|1<<ADPS0);freigabe der Messung
out adcsra,temp0
start_convers2: ;;;
sbic ADCSR,ADSC ;;;;;; diese kleine routine braucht man nicht wenn man mit ints arbeitet
rjmp start_convers2 ;;;
in temp0,adcl ;wichtig erst low
in temp1,adch ;dann high lesen sonst erg müll
sts ladc,temp0
sts hadc,temp1
ret
;******************************adc_interrupt**********************
adc_rdy:
in temp0,adcl ;wichtig erst low
sts ladc,temp0
in temp1,adch ;dann high lesen sonst erg müll
sts hadc,temp1
reti
;***********************adc_init*****************************
adc_init:
ldi temp0,(0<<Chan6|0<<Chan5|0<<Chan4|0<<Chan3|0<<Chan2|0<<Chan1|0<<Chan0)
out ADC_ddr_a,temp0
ldi temp0,(0<<Chan6|0<<Chan5|0<<Chan4|0<<Chan3|0<<Chan2|0<<Chan1|0<<Chan0)
out ADC_Pin_a,temp0
ldi temp0,(0<<Chan9|0<<Chan8|0<<Chan7)
out ADC_ddr_b,temp0
ldi temp0,(0<<Chan9|0<<Chan8|0<<Chan7)
out ADC_ddr_b,temp0
in temp0,adcsra
ori temp0,(1<<ADEN|0<<ADSC|0<<ADFR|0<<ADIE|1<<ADPS2|0<<ADPS1|1<<ADPS0) ;
out adcsra,temp0
rcall adc_ref_5V
ret
;*********************AREF
adc_ref_5V: ;AVCC on
in temp0,admux
andi temp0,(0<<REFS1|0<<REFS0|1<<ADLAR|1<<MUX4|1<<MUX3|1<<MUX2|1<<MUX1|1<<MUX0)
ori temp0,(0<<REFS1|0<<REFS0|0<<ADLAR|1<<MUX4|1<<MUX3|1<<MUX2|1<<MUX1|1<<MUX0) ;AVCC with external capacitor at AREF pin
out admux,temp0
ret
adc_ref_extern: ;AREexternF
in temp0,admux
andi temp0,(0<<REFS1|0<<REFS0|1<<ADLAR|1<<MUX4|1<<MUX3|1<<MUX2|1<<MUX1|1<<MUX0)
ori temp0,(0<<REFS1|1<<REFS0|0<<ADLAR|1<<MUX4|1<<MUX3|1<<MUX2|1<<MUX1|1<<MUX0) ;AVCC with external capacitor at AREF pin
out admux,temp0
ret
adc_ref_256V1: ;2,56V on
in temp0,admux
andi temp0,(0<<REFS1|0<<REFS0|1<<ADLAR|1<<MUX4|1<<MUX3|1<<MUX2|1<<MUX1|1<<MUX0)
ori temp0,(1<<REFS1|0<<REFS0|0<<ADLAR|1<<MUX4|1<<MUX3|1<<MUX2|1<<MUX1|1<<MUX0) ;AVCC with external capacitor at AREF pin
out admux,temp0
ret
adc_ref_256V2: ;extern on
in temp0,admux
andi temp0,(0<<REFS1|0<<REFS0|1<<ADLAR|1<<MUX4|1<<MUX3|1<<MUX2|1<<MUX1|1<<MUX0)
ori temp0,(1<<REFS1|1<<REFS0|0<<ADLAR|1<<MUX4|1<<MUX3|1<<MUX2|1<<MUX1|1<<MUX0) ;AVCC with external capacitor at AREF pin
out admux,temp0
ret
;*******************Channels**************************************************************************************
adc_chan_0:
in temp0,admux
andi temp0,(1<<REFS1|1<<REFS0|1<<ADLAR|0<<MUX4|0<<MUX3|0<<MUX2|0<<MUX1|0<<MUX0)
ori temp0,(0<<REFS1|0<<REFS0|0<<ADLAR|0<<MUX4|0<<MUX3|0<<MUX2|0<<MUX1|0<<MUX0)
out admux,temp0
ret
adc_chan_1:
in temp0,admux
andi temp0,(1<<REFS1|1<<REFS0|1<<ADLAR|0<<MUX4|0<<MUX3|0<<MUX2|0<<MUX1|0<<MUX0)
ori temp0,(0<<REFS1|0<<REFS0|0<<ADLAR|0<<MUX4|0<<MUX3|0<<MUX2|0<<MUX1|1<<MUX0)
out admux,temp0
ret
adc_chan_2:
in temp0,admux
andi temp0,(1<<REFS1|1<<REFS0|1<<ADLAR|0<<MUX4|0<<MUX3|0<<MUX2|0<<MUX1|0<<MUX0)
ori temp0,(0<<REFS1|0<<REFS0|0<<ADLAR|0<<MUX4|0<<MUX3|0<<MUX2|1<<MUX1|0<<MUX0)
out admux,temp0
ret
adc_chan_3:
in temp0,admux
andi temp0,(1<<REFS1|1<<REFS0|1<<ADLAR|0<<MUX4|0<<MUX3|0<<MUX2|0<<MUX1|0<<MUX0)
ori temp0,(0<<REFS1|0<<REFS0|0<<ADLAR|0<<MUX4|0<<MUX3|0<<MUX2|1<<MUX1|1<<MUX0)
out admux,temp0
ret
adc_chan_4:
in temp0,admux
andi temp0,(1<<REFS1|1<<REFS0|1<<ADLAR|0<<MUX4|0<<MUX3|0<<MUX2|0<<MUX1|0<<MUX0)
ori temp0,(0<<REFS1|0<<REFS0|0<<ADLAR|0<<MUX4|0<<MUX3|1<<MUX2|0<<MUX1|0<<MUX0)
out admux,temp0
ret
adc_chan_5:
in temp0,admux
andi temp0,(1<<REFS1|1<<REFS0|1<<ADLAR|0<<MUX4|0<<MUX3|0<<MUX2|0<<MUX1|0<<MUX0)
ori temp0,(0<<REFS1|0<<REFS0|0<<ADLAR|0<<MUX4|0<<MUX3|1<<MUX2|0<<MUX1|1<<MUX0)
out admux,temp0
ret
adc_chan_6:
in temp0,admux
andi temp0,(1<<REFS1|1<<REFS0|1<<ADLAR|0<<MUX4|0<<MUX3|0<<MUX2|0<<MUX1|0<<MUX0)
ori temp0,(0<<REFS1|0<<REFS0|0<<ADLAR|0<<MUX4|0<<MUX3|1<<MUX2|1<<MUX1|0<<MUX0)
out admux,temp0
ret
adc_chan_7:
in temp0,admux
andi temp0,(1<<REFS1|1<<REFS0|1<<ADLAR|0<<MUX4|0<<MUX3|0<<MUX2|0<<MUX1|0<<MUX0)
ori temp0,(0<<REFS1|0<<REFS0|0<<ADLAR|0<<MUX4|0<<MUX3|1<<MUX2|1<<MUX1|1<<MUX0)
out admux,temp0
ret
adc_chan_8:
in temp0,admux
andi temp0,(1<<REFS1|1<<REFS0|1<<ADLAR|0<<MUX4|0<<MUX3|0<<MUX2|0<<MUX1|0<<MUX0)
ori temp0,(0<<REFS1|0<<REFS0|0<<ADLAR|0<<MUX4|1<<MUX3|0<<MUX2|0<<MUX1|0<<MUX0)
out admux,temp0
ret
adc_chan_9:
in temp0,admux
andi temp0,(1<<REFS1|1<<REFS0|1<<ADLAR|0<<MUX4|0<<MUX3|0<<MUX2|0<<MUX1|0<<MUX0)
ori temp0,(0<<REFS1|0<<REFS0|0<<ADLAR|0<<MUX4|1<<MUX3|0<<MUX2|0<<MUX1|1<<MUX0)
out admux,temp0
ret
adc_chan_BG:
in temp0,admux
andi temp0,(1<<REFS1|1<<REFS0|1<<ADLAR|0<<MUX4|0<<MUX3|0<<MUX2|0<<MUX1|0<<MUX0)
ori temp0,(0<<REFS1|0<<REFS0|0<<ADLAR|1<<MUX4|1<<MUX3|1<<MUX2|1<<MUX1|0<<MUX0)
out admux,temp0
ret
adc_chan_GND:
in temp0,admux
andi temp0,(1<<REFS1|1<<REFS0|1<<ADLAR|0<<MUX4|0<<MUX3|0<<MUX2|0<<MUX1|0<<MUX0)
ori temp0,(0<<REFS1|0<<REFS0|0<<ADLAR|1<<MUX4|1<<MUX3|1<<MUX2|1<<MUX1|1<<MUX0)
out admux,temp0
ret
Lesezeichen