init_adc:			
	ldi	tmp1,0	;channel0 first
	out	admux,tmp1		
	ldi	tmp1,prescaler_adc
	out	adcsr,tmp1	
	sbi	adcsr,aden	;ADC enabled
	sbi	adcsr,adsc	;start first conversion	
	ret			
get_adc:
	sbis	adcsr,adif	;if current conversion 
	ret			;not redy exit
	in	tmp1,admux	;else get current channel
	andi	tmp1,0b00000111
	ldi	xl,low(buf_adc)	;get adc buffer addr
	ldi	xh,high(buf_adc)
	clr	tmp2
	push	tmp1		;save channel number
	add	tmp1,tmp1	;calculate addr adc buffer  
	add	xl,tmp1		;of current channel
	adc	xh,tmp2
	in	tmp1,adcl	;get AD conversion result
	in	tmp2,adch
	st	x+,tmp1		;and store it
	st	x,tmp2
	pop	tmp1		;restore channel number
	inc	tmp1		;increment
	cpi	tmp1,adc_max_ch+1; if new channel number
	brlo	getadc1		;is overflow
	clr	tmp1		; back to first channel
getadc1:
	out	admux,tmp1	;init adc mux
	sbi	adcsr,adsc	;start a new convertion
	ret


