⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.s

📁 ATMEGA128的ADC驱动程序
💻 S
字号:
	.module main.c
	.area text(rom, con, rel)
	.dbfile D:\avrvi\AVRVi_m128_Starter_Kit\ADC\source\main.c
	.dbfunc e adc_init _adc_init fV
	.even
_adc_init::
	.dbline -1
	.dbline 13
; /************************************************
; 文件:main.c
; 用途:
; 注意:内部8M晶振
; 创建:2008.4.1
; 修改:2008.4.1
; Copy Right  (c)  www.avrvi.com  AVR与虚拟仪器
; ************************************************/
; 
; #include "config.h"
; float adc_result;
; void adc_init(void)
; {
	.dbline 14
;  ADCSRA = 0x00; //disable adc
	clr R2
	out 0x6,R2
	.dbline 15
;  ADMUX = (1<<REFS0)|(1<<ADLAR);
	ldi R24,96
	out 0x7,R24
	.dbline 16
;  ACSR = (1<<ACD);
	ldi R24,128
	out 0x8,R24
	.dbline 17
;  ADCSRA = (1<<ADEN);
	out 0x6,R24
	.dbline -2
L1:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e get_adc _get_adc fV
;          value -> R20
;    adc_channel -> R20,R21
	.even
_get_adc::
	xcall push_gset1
	movw R20,R16
	.dbline -1
	.dbline 21
; }
; 
; void get_adc(unsigned adc_channel)
; {
	.dbline 23
;  unsigned char value; 
;  adc_init();
	xcall _adc_init
	.dbline 24
;  ADMUX += adc_channel;
	in R2,0x7
	clr R3
	add R2,R20
	adc R3,R21
	out 0x7,R2
	.dbline 25
;  ADCSRA |= (1<<ADSC);
	sbi 0x6,6
	.dbline 27
;  
;  delay_nus(100);
	ldi R16,100
	ldi R17,0
	xcall _delay_nus
	.dbline 28
;  value=ADCH;
	in R20,0x5
	.dbline 29
;  adc_result=(value*4.98)/256; 
	ldi R16,<L3
	ldi R17,>L3
	xcall lpm32
	st -y,R19
	st -y,R18
	st -y,R17
	st -y,R16
	mov R16,R20
	clr R17
	xcall int2fp
	st -y,R19
	st -y,R18
	st -y,R17
	st -y,R16
	xcall empy32fs
	ldi R16,<L4
	ldi R17,>L4
	xcall lpm32
	st -y,R19
	st -y,R18
	st -y,R17
	st -y,R16
	xcall div32f
	sts _adc_result+1,R17
	sts _adc_result,R16
	sts _adc_result+2+1,R19
	sts _adc_result+2,R18
	.dbline -2
L2:
	xcall pop_gset1
	.dbline 0 ; func end
	ret
	.dbsym r value 20 c
	.dbsym r adc_channel 20 i
	.dbend
	.dbfunc e main _main fV
	.even
_main::
	.dbline -1
	.dbline 33
; }
; 
; void main(void)
; { 
	.dbline 34
;  HC_595_init();
	xcall _HC_595_init
	xjmp L7
L6:
	.dbline 37
	.dbline 38
	ldi R16,1
	ldi R17,0
	xcall _get_adc
	.dbline 39
	lds R18,_adc_result+2
	lds R19,_adc_result+2+1
	lds R16,_adc_result
	lds R17,_adc_result+1
	xcall _Seg7_Led_float
	.dbline 40
L7:
	.dbline 36
	xjmp L6
X0:
	.dbline -2
L5:
	.dbline 0 ; func end
	ret
	.dbend
	.area bss(ram, con, rel)
	.dbfile D:\avrvi\AVRVi_m128_Starter_Kit\ADC\source\main.c
_adc_result::
	.blkb 4
	.dbsym e adc_result _adc_result D
	.area lit(rom, con, rel)
L4:
	.word 0x0,0x4380
L3:
	.word 0x5c29,0x409f

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -