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

📄 dac_sin.s

📁 这是atmega128单片机的数模转换程序
💻 S
字号:
	.module dac_sin.c
	.area text(rom, con, rel)
	.dbfile E:\产品\开发板\mega128-board\实验程序\数模转换\正弦波\dac_sin.c
	.dbfunc e s_ms _s_ms fV
;              t -> R16,R17
	.even
_s_ms::
	.dbline -1
	.dbline 8
; #include<iom128v.h>
; #include"math.h"
; #define uchar unsigned char 
; #define uint unsigned int 
; 
; //延时函数
; void s_ms(unsigned int t)
; {
	.dbline 9
;     for(;t>1;t--)
	xjmp L5
L2:
	.dbline 10
;     {
	.dbline 11
;     }
L3:
	.dbline 9
	subi R16,1
	sbci R17,0
L5:
	.dbline 9
	ldi R24,1
	ldi R25,0
	cp R24,R16
	cpc R25,R17
	brlo L2
X0:
	.dbline -2
L1:
	.dbline 0 ; func end
	ret
	.dbsym r t 16 i
	.dbend
	.dbfunc e spi_init _spi_init fV
	.even
_spi_init::
	.dbline -1
	.dbline 16
; }
; 
; //SPI初始化
; void spi_init()    
; {
	.dbline 17
; DDRB=0xf7;   //端口设置
	ldi R24,247
	out 0x17,R24
	.dbline 18
; PORTB=0xff;
	ldi R24,255
	out 0x18,R24
	.dbline 19
; SPSR&=0x00;
	clr R2
	out 0xe,R2
	.dbline 20
; SPCR=0x5d;   //主机模式 方式0 ocs/16
	ldi R24,93
	out 0xd,R24
	.dbline -2
L6:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e spi_send _spi_send fV
;         spi_hi -> R12
;         spi_lo -> R10
;       spi_data -> R16,R17
	.even
_spi_send::
	xcall push_xgset003C
	.dbline -1
	.dbline 24
; }
; 
; void spi_send(uint spi_data)
; {
	.dbline 26
; uchar spi_lo,spi_hi;
; spi_lo=spi_data;
	mov R10,R16
	.dbline 27
; spi_hi=spi_data>>8;
	movw R12,R16
	mov R12,R13
	clr R13
	.dbline 29
; 
; PORTB&=~(1<<0);                //ss=0
	cbi 0x18,0
	.dbline 30
; SPDR=spi_hi;                   //发送高字节
	out 0xf,R12
L8:
	.dbline 31
; while(!(SPSR&(1<<SPIF)));  
L9:
	.dbline 31
	sbis 0xe,7
	rjmp L8
X1:
	.dbline 32
; SPDR=spi_lo;                   //发送低字节
	out 0xf,R10
L11:
	.dbline 33
; while(!(SPSR&(1<<SPIF)));
L12:
	.dbline 33
	sbis 0xe,7
	rjmp L11
X2:
	.dbline 34
; PORTB|=(1<<0);
	sbi 0x18,0
	.dbline -2
L7:
	.dbline 0 ; func end
	xjmp pop_xgset003C
	.dbsym r spi_hi 12 c
	.dbsym r spi_lo 10 c
	.dbsym r spi_data 16 i
	.dbend
	.dbfunc e main _main fI
;             aa -> y+4
;          sin_p -> R20,R21
;            pai -> y+0
	.even
_main::
	sbiw R28,8
	.dbline -1
	.dbline 41
; }
; 
; //使用DAC产生27Hz的正弦波
; //主要时间消耗在sin的计算上,使用查表会更快
; //主函数
; main()
; {
	.dbline 42
; float pai=0,aa;
	ldi R16,<L15
	ldi R17,>L15
	xcall elpm32
	std y+0,R16
	std y+1,R17
	std y+2,R18
	std y+3,R19
	.dbline 44
; int sin_p;
; s_ms(50000);  //等待7512复位
	ldi R16,50000
	ldi R17,195
	xcall _s_ms
	.dbline 45
; spi_init();
	xcall _spi_init
	.dbline 47
; 
; spi_send(0x07ff);
	ldi R16,2047
	ldi R17,7
	xcall _spi_send
	xjmp L17
L16:
	.dbline 49
; while(1)
;      {
	.dbline 50
; 	  pai+=0.1;
	ldd R2,y+0
	ldd R3,y+1
	ldd R4,y+2
	ldd R5,y+3
	ldi R16,<L19
	ldi R17,>L19
	xcall elpm32
	st -y,R19
	st -y,R18
	st -y,R17
	st -y,R16
	movw R16,R2
	movw R18,R4
	xcall fpadd2
	std y+0,R16
	std y+1,R17
	std y+2,R18
	std y+3,R19
	.dbline 51
; 	  sin_p=sin(pai)*2000;
	ldd R16,y+0
	ldd R17,y+1
	ldd R18,y+2
	ldd R19,y+3
	xcall _sinf
	movw R2,R16
	movw R4,R18
	ldi R16,<L20
	ldi R17,>L20
	xcall elpm32
	st -y,R5
	st -y,R4
	st -y,R3
	st -y,R2
	xcall fpmule2
	xcall fpint
	movw R20,R16
	.dbline 52
;       sin_p+=2048;               //2048作为中点
	subi R20,0  ; offset = 2048
	sbci R21,248
	.dbline 53
; 	  spi_send(sin_p);
	movw R16,R20
	xcall _spi_send
	.dbline 54
; 	  if(pai==6.28)              //2pai回零
	ldd R2,y+0
	ldd R3,y+1
	ldd R4,y+2
	ldd R5,y+3
	ldi R16,<L23
	ldi R17,>L23
	xcall elpm32
	st -y,R19
	st -y,R18
	st -y,R17
	st -y,R16
	movw R16,R2
	movw R18,R4
	xcall fpcmp2
	brne L21
X3:
	.dbline 55
; 	    {pai=0;}
	.dbline 55
	ldi R16,<L15
	ldi R17,>L15
	xcall elpm32
	std y+0,R16
	std y+1,R17
	std y+2,R18
	std y+3,R19
	.dbline 55
L21:
	.dbline 56
;  	 }
L17:
	.dbline 48
	xjmp L16
X4:
	.dbline -2
L14:
	.dbline 0 ; func end
	adiw R28,8
	ret
	.dbsym l aa 4 D
	.dbsym r sin_p 20 I
	.dbsym l pai 0 D
	.dbend
	.area lit(rom, con, rel)
L23:
	.word 0xf5c3,0x40c8
L20:
	.word 0x0,0x44fa
L19:
	.word 0xcccd,0x3dcc
L15:
	.word 0x0,0x0
; }

⌨️ 快捷键说明

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