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

📄 main.s

📁 基于MEGA128的双通道AD转换例程序
💻 S
字号:
	.module main.c
	.area text(rom, con, rel)
	.dbfile D:\avrvi\AVRVi_m128_Starter_Kit\ADC_2_Channel\source\main.c
	.dbfunc e adc_init _adc_init fV
	.even
_adc_init::
	.dbline -1
	.dbline 14
; /************************************************
; 文件: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 15
;  ADCSRA = 0x00; //disable adc
	clr R2
	out 0x6,R2
	.dbline 16
;  ADMUX = (1<<REFS0)|(1<<ADLAR);
	ldi R24,96
	out 0x7,R24
	.dbline 17
;  ACSR = (1<<ACD);
	ldi R24,128
	out 0x8,R24
	.dbline 18
;  ADCSRA = (1<<ADEN);
	out 0x6,R24
	.dbline -2
L2:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e get_adc _get_adc fV
;          value -> R20,R21
;              i -> R22,R23
;    adc_channel -> R22,R23
	.even
_get_adc::
	xcall push_gset2
	movw R22,R16
	.dbline -1
	.dbline 22
; }
; 
; void get_adc(unsigned adc_channel)
; {
	.dbline 23
;  unsigned int value=0,i;
	clr R20
	clr R21
	.dbline 25
;  
;  adc_init();
	xcall _adc_init
	.dbline 26
;  ADMUX += adc_channel;
	in R2,0x7
	clr R3
	add R2,R22
	adc R3,R23
	out 0x7,R2
	.dbline 28
;  
;  for(i=0;i<4;i++)
	clr R22
	clr R23
	xjmp L7
L4:
	.dbline 29
	.dbline 30
	sbi 0x6,6
	.dbline 31
	ldi R16,100
	ldi R17,0
	xcall _delay_nus
	.dbline 32
	in R2,0x5
	clr R3
	add R20,R2
	adc R21,R3
	.dbline 33
L5:
	.dbline 28
	subi R22,255  ; offset = 1
	sbci R23,255
L7:
	.dbline 28
	cpi R22,4
	ldi R30,0
	cpc R23,R30
	brlo L4
	.dbline 35
;  {
;   ADCSRA |= (1<<ADSC); 
;   delay_nus(100);
;   value += ADCH;
;  }
;  
;  value >>= 2;
	movw R2,R20
	lsr R3
	ror R2
	lsr R3
	ror R2
	movw R20,R2
	.dbline 37
;  
;  adc_result=(value*4.97)/256;
	ldi R16,<L8
	ldi R17,>L8
	xcall lpm32
	st -y,R19
	st -y,R18
	st -y,R17
	st -y,R16
	ldi R16,<L9
	ldi R17,>L9
	xcall lpm32
	st -y,R19
	st -y,R18
	st -y,R17
	st -y,R16
	movw R16,R20
	lsr R17
	ror R16
	xcall int2fp
	st -y,R19
	st -y,R18
	st -y,R17
	st -y,R16
	xcall empy32fs
	movw R16,R20
	andi R16,1
	andi R17,0
	xcall int2fp
	st -y,R19
	st -y,R18
	st -y,R17
	st -y,R16
	xcall add32fs
	xcall empy32fs
	ldi R16,<L10
	ldi R17,>L10
	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
L3:
	xcall pop_gset2
	.dbline 0 ; func end
	ret
	.dbsym r value 20 i
	.dbsym r i 22 i
	.dbsym r adc_channel 22 i
	.dbend
	.dbfunc e main _main fV
;              i -> R22
;        adc_str -> R20,R21
	.even
_main::
	sbiw R28,2
	.dbline -1
	.dbline 41
; }
; 
; void main(void)
; { 
	.dbline 42
;  unsigned char *adc_str="The adc result of channel 0 is : 2.031 V\n\n",i=0;
	ldi R20,<L12
	ldi R21,>L12
	.dbline 42
	clr R22
	.dbline 43
;  CLI();
	cli
	.dbline 44
;  Com_init();
	xcall _Com_init
	.dbline 45
;  SEI();
	sei
	xjmp L14
L13:
	.dbline 47
;  while(1)
;  {
	.dbline 48
;   get_adc(i);
	mov R16,R22
	clr R17
	xcall _get_adc
	.dbline 49
;   adc_str[26]=i+0x30;
	mov R24,R22
	subi R24,208    ; addi 48
	movw R30,R20
	std z+26,R24
	.dbline 50
;   adc_result *= 1000;
	ldi R16,<L16
	ldi R17,>L16
	xcall lpm32
	st -y,R19
	st -y,R18
	st -y,R17
	st -y,R16
	lds R4,_adc_result+2
	lds R5,_adc_result+2+1
	lds R2,_adc_result
	lds R3,_adc_result+1
	st -y,R5
	st -y,R4
	st -y,R3
	st -y,R2
	xcall empy32f
	sts _adc_result+1,R17
	sts _adc_result,R16
	sts _adc_result+2+1,R19
	sts _adc_result+2,R18
	.dbline 51
;   adc_str[33]=(unsigned int)adc_result/1000+0x30;
	st -y,R19
	st -y,R18
	st -y,R17
	st -y,R16
	ldi R16,<L19
	ldi R17,>L19
	xcall lpm32
	st -y,R19
	st -y,R18
	st -y,R17
	st -y,R16
	xcall cmp32f
	brlt L17
	lds R4,_adc_result+2
	lds R5,_adc_result+2+1
	lds R2,_adc_result
	lds R3,_adc_result+1
	st -y,R5
	st -y,R4
	st -y,R3
	st -y,R2
	ldi R16,<L19
	ldi R17,>L19
	xcall lpm32
	st -y,R19
	st -y,R18
	st -y,R17
	st -y,R16
	xcall sub32f
	xcall fp2int
	movw R24,R16
	subi R24,0  ; offset = 32768
	sbci R25,128
	movw R10,R24
	xjmp L18
L17:
	lds R18,_adc_result+2
	lds R19,_adc_result+2+1
	lds R16,_adc_result
	lds R17,_adc_result+1
	xcall fp2int
	movw R10,R16
L18:
	ldi R18,1000
	ldi R19,3
	movw R16,R10
	xcall div16u
	movw R24,R16
	adiw R24,48
	movw R30,R20
	std z+33,R24
	.dbline 52
;   adc_str[35]=((unsigned int)adc_result%1000)/100+0x30;
	lds R4,_adc_result+2
	lds R5,_adc_result+2+1
	lds R2,_adc_result
	lds R3,_adc_result+1
	st -y,R5
	st -y,R4
	st -y,R3
	st -y,R2
	ldi R16,<L19
	ldi R17,>L19
	xcall lpm32
	st -y,R19
	st -y,R18
	st -y,R17
	st -y,R16
	xcall cmp32f
	brlt L20
	lds R4,_adc_result+2
	lds R5,_adc_result+2+1
	lds R2,_adc_result
	lds R3,_adc_result+1
	st -y,R5
	st -y,R4
	st -y,R3
	st -y,R2
	ldi R16,<L19
	ldi R17,>L19
	xcall lpm32
	st -y,R19
	st -y,R18
	st -y,R17
	st -y,R16
	xcall sub32f
	xcall fp2int
	movw R24,R16
	subi R24,0  ; offset = 32768
	sbci R25,128
	movw R10,R24
	xjmp L21
L20:
	lds R18,_adc_result+2
	lds R19,_adc_result+2+1
	lds R16,_adc_result
	lds R17,_adc_result+1
	xcall fp2int
	movw R10,R16
L21:
	ldi R18,1000
	ldi R19,3
	movw R16,R10
	xcall mod16u
	ldi R18,100
	ldi R19,0
	xcall div16u
	movw R24,R16
	adiw R24,48
	movw R30,R20
	std z+35,R24
	.dbline 53
;   adc_str[36]=((unsigned int)adc_result%100)/10+0x30;
	lds R4,_adc_result+2
	lds R5,_adc_result+2+1
	lds R2,_adc_result
	lds R3,_adc_result+1
	st -y,R5
	st -y,R4
	st -y,R3
	st -y,R2
	ldi R16,<L19
	ldi R17,>L19
	xcall lpm32
	st -y,R19
	st -y,R18
	st -y,R17
	st -y,R16
	xcall cmp32f
	brlt L22
	lds R4,_adc_result+2
	lds R5,_adc_result+2+1
	lds R2,_adc_result
	lds R3,_adc_result+1
	st -y,R5
	st -y,R4
	st -y,R3
	st -y,R2
	ldi R16,<L19
	ldi R17,>L19
	xcall lpm32
	st -y,R19
	st -y,R18
	st -y,R17
	st -y,R16
	xcall sub32f
	xcall fp2int
	movw R24,R16
	subi R24,0  ; offset = 32768
	sbci R25,128
	movw R10,R24
	xjmp L23
L22:
	lds R18,_adc_result+2
	lds R19,_adc_result+2+1
	lds R16,_adc_result
	lds R17,_adc_result+1
	xcall fp2int
	movw R10,R16
L23:
	ldi R18,100
	ldi R19,0
	movw R16,R10
	xcall mod16u
	ldi R18,10
	ldi R19,0
	xcall div16u
	movw R24,R16
	adiw R24,48
	movw R30,R20
	std z+36,R24
	.dbline 54
;   adc_str[37]=(unsigned int)adc_result%10+0x30;
	lds R4,_adc_result+2
	lds R5,_adc_result+2+1
	lds R2,_adc_result
	lds R3,_adc_result+1
	st -y,R5
	st -y,R4
	st -y,R3
	st -y,R2
	ldi R16,<L19
	ldi R17,>L19
	xcall lpm32
	st -y,R19
	st -y,R18
	st -y,R17
	st -y,R16
	xcall cmp32f
	brlt L24
	lds R4,_adc_result+2
	lds R5,_adc_result+2+1
	lds R2,_adc_result
	lds R3,_adc_result+1
	st -y,R5
	st -y,R4
	st -y,R3
	st -y,R2
	ldi R16,<L19
	ldi R17,>L19
	xcall lpm32
	st -y,R19
	st -y,R18
	st -y,R17
	st -y,R16
	xcall sub32f
	xcall fp2int
	movw R24,R16
	subi R24,0  ; offset = 32768
	sbci R25,128
	movw R10,R24
	xjmp L25
L24:
	lds R18,_adc_result+2
	lds R19,_adc_result+2+1
	lds R16,_adc_result
	lds R17,_adc_result+1
	xcall fp2int
	movw R10,R16
L25:
	ldi R18,10
	ldi R19,0
	movw R16,R10
	xcall mod16u
	movw R24,R16
	adiw R24,48
	movw R30,R20
	std z+37,R24
	.dbline 56
;   
;   Com_putstring (adc_str,41,&RTbuf_UART0);
	ldi R24,<_RTbuf_UART0
	ldi R25,>_RTbuf_UART0
	std y+1,R25
	std y+0,R24
	ldi R18,41
	movw R16,R20
	xcall _Com_putstring
	.dbline 57
;   i++;
	inc R22
	.dbline 58
;   if(i>1) i=0;
	ldi R24,1
	cp R24,R22
	brsh L26
	.dbline 58
	clr R22
L26:
	.dbline 60
	ldi R16,300
	ldi R17,1
	xcall _delay_nms
	.dbline 61
L14:
	.dbline 46
	xjmp L13
X0:
	.dbline -2
L11:
	adiw R28,2
	.dbline 0 ; func end
	ret
	.dbsym r i 22 c
	.dbsym r adc_str 20 pc
	.dbend
	.area bss(ram, con, rel)
	.dbfile D:\avrvi\AVRVi_m128_Starter_Kit\ADC_2_Channel\source\main.c
_adc_result::
	.blkb 4
	.dbsym e adc_result _adc_result D
	.area lit(rom, con, rel)
L19:
	.word 0x0,0x4700
L16:
	.word 0x0,0x447a
	.area data(ram, con, rel)
	.dbfile D:\avrvi\AVRVi_m128_Starter_Kit\ADC_2_Channel\source\main.c
L12:
	.blkb 43
	.area idata
	.byte 'T,'h,'e,32,'a,'d,'c,32,'r,'e,'s,'u,'l,'t,32,'o
	.byte 'f,32,'c,'h,'a,'n,'n,'e,'l,32,48,32,'i,'s,32,58
	.byte 32,50,46,48,51,49,32,'V,10,10,0
	.area data(ram, con, rel)
	.dbfile D:\avrvi\AVRVi_m128_Starter_Kit\ADC_2_Channel\source\main.c
	.area lit(rom, con, rel)
L10:
	.word 0x0,0x4380
L9:
	.word 0x0,0x4000
L8:
	.word 0xa3d,0x409f

⌨️ 快捷键说明

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