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

📄 vs1003.s

📁 AVR单片机系统开发经典实例部分源程序
💻 S
字号:
	.module vs1003.c
	.area lit(rom, con, rel)
_VOL_BUFFER::
	.word 37265
	.word 35980
	.word 34695
	.word 33410
	.word 32125
	.word 30840
	.word 29555
	.word 28270
	.word 26985
	.word 25700
	.word 24415
	.word 23130
	.word 21845
	.word 20560
	.word 19275
	.word 17990
	.word 16705
	.word 15420
	.word 14135
	.word 12850
	.word 11565
	.word 10280
	.word 8995
	.word 7710
	.word 6425
	.word 5140
	.word 3855
	.word 2570
	.word 1285
	.word 0
	.dbfile C:\AVR\M\1\vs1003.c
	.dbsym e VOL_BUFFER _VOL_BUFFER A[60:30]ki
	.area text(rom, con, rel)
	.dbfile C:\AVR\M\1\vs1003.c
	.dbfunc e VS1003_Port_Init _VS1003_Port_Init fV
	.even
_VS1003_Port_Init::
	.dbline -1
	.dbline 23
; 
; #include "vs1003.h"
; 
; uint32 num; 
; 
; uint16  VOL;  // 音量
; 
; // 音量数据表
; const uint16 VOL_BUFFER[30] =
; { 
; 	0x9191,0x8c8c,0x8787,0x8282,0x7d7d,0x7878,0x7373,0x6e6e,0x6969,0x6464,
; 	0x5f5f,0x5a5a,0x5555,0x5050,0x4b4b,0x4646,0x4141,0x3c3c,0x3737,0x3232,
; 	0x2d2d,0x2828,0x2323,0x1e1e,0x1919,0x1414,0x0f0f,0x0a0a,0x0505,0x0000
; };
; 
; 
; //---------------------------------
; //
; // VS1003接口初始化函数 
; //
; //---------------------------------
; void VS1003_Port_Init()
; { 
	.dbline 24
; 	VS1003_XRESET_OUT();
	sbi 0x14,6
	.dbline 25
; 	VS1003_XDCS_OUT();
	sbi 0x14,5
	.dbline 26
; 	VS1003_CS_OUT();
	sbi 0x14,4
	.dbline 27
; 	VS1003_DREQ_IN();	
	cbi 0x14,7
	.dbline -2
L1:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e VS1003_WriteReg _VS1003_WriteReg fV
;            dat -> R20,R21
;           addr -> R22
	.even
_VS1003_WriteReg::
	xcall push_gset2
	movw R20,R18
	mov R22,R16
	.dbline -1
	.dbline 39
; }
; 
; 
; //---------------------------------
; //
; // VS1003写寄存器函数 
; // addr:VS1003内部寄存器地址
; // dat:要写入的数据
; //
; //---------------------------------
; void VS1003_WriteReg(uint8 addr,uint16 dat)
; {
	.dbline 40
; 	VS1003_XDCS_SET();								
	sbi 0x15,5
	.dbline 41
; 	VS1003_CS_CLR();									// 片选VS1003
	cbi 0x15,4
	.dbline 43
; 	
; 	SPI_SrByte(VS1003_WRITE_COM);								
	ldi R16,2
	xcall _SPI_SrByte
	.dbline 45
; 	
; 	SPI_SrByte(addr);
	mov R16,R22
	xcall _SPI_SrByte
	.dbline 47
; 	
; 	SPI_SrByte((uint8)(dat>>8));
	movw R16,R20
	mov R16,R17
	clr R17
	xcall _SPI_SrByte
	.dbline 48
; 	SPI_SrByte((uint8)(dat));
	mov R16,R20
	xcall _SPI_SrByte
	.dbline 50
; 	
; 	VS1003_CS_SET();								  // 取消片选VS1003
	sbi 0x15,4
	.dbline 51
; 	VS1003_XDCS_SET();
	sbi 0x15,5
	.dbline -2
L2:
	xcall pop_gset2
	.dbline 0 ; func end
	ret
	.dbsym r dat 20 i
	.dbsym r addr 22 c
	.dbend
	.dbfunc e VS1003_ReadReg _VS1003_ReadReg fi
;           datL -> R22,R23
;            dat -> R20,R21
;           addr -> R10
	.even
_VS1003_ReadReg::
	xcall push_gset3
	mov R10,R16
	.dbline -1
	.dbline 64
; }
; 
; 
; 
; //---------------------------------
; //
; // VS1003读寄存器函数 
; // addr:VS1003内部寄存器地址
; // dat:返回的数据
; //
; //---------------------------------
; uint16 VS1003_ReadReg(uint8 addr)
; {
	.dbline 65
; 	uint16 dat = 0x0000;
	clr R20
	clr R21
	.dbline 66
; 	uint16 datL = 0x0000;
	clr R22
	clr R23
	.dbline 68
; 		
; 	VS1003_XDCS_SET();
	sbi 0x15,5
	.dbline 69
; 	VS1003_CS_CLR();								
	cbi 0x15,4
	.dbline 71
; 
; 	SPI_SrByte(VS1003_READ_COM);
	ldi R16,3
	xcall _SPI_SrByte
	.dbline 72
; 	SPI_SrByte(addr);
	mov R16,R10
	xcall _SPI_SrByte
	.dbline 74
; 
; 	dat	= SPI_SrByte(0xff);
	ldi R16,255
	xcall _SPI_SrByte
	mov R20,R16
	clr R21
	.dbline 75
; 	dat	= dat<<8;
	mov R21,R20
	clr R20
	.dbline 76
; 	datL = SPI_SrByte(0xff);
	ldi R16,255
	xcall _SPI_SrByte
	mov R22,R16
	clr R23
	.dbline 77
; 	dat	=dat|datL;
	or R20,R22
	or R21,R23
	.dbline 79
; 	
; 	VS1003_CS_SET();
	sbi 0x15,4
	.dbline 80
; 	VS1003_XDCS_SET();
	sbi 0x15,5
	.dbline 82
; 	
; 	return dat;
	movw R16,R20
	.dbline -2
L3:
	xcall pop_gset3
	.dbline 0 ; func end
	ret
	.dbsym r datL 22 i
	.dbsym r dat 20 i
	.dbsym r addr 10 c
	.dbend
	.dbfunc e VS1003_WriteDat _VS1003_WriteDat fV
;            dat -> R20
	.even
_VS1003_WriteDat::
	xcall push_gset1
	mov R20,R16
	.dbline -1
	.dbline 93
; }
; 
; 
; //---------------------------------
; //
; // VS1003写数据函数 
; // dat:要写入的数据
; //
; //---------------------------------
; void VS1003_WriteDat(uint8 dat)
; {
	.dbline 94
; 	VS1003_XDCS_CLR();
	cbi 0x15,5
	.dbline 96
; 	
; 	VS1003_CS_CLR();
	cbi 0x15,4
	.dbline 98
; 
; 	SPI_SrByte(dat);
	mov R16,R20
	xcall _SPI_SrByte
	.dbline 99
; 	VS1003_CS_SET();
	sbi 0x15,4
	.dbline 100
; 	VS1003_XDCS_SET();
	sbi 0x15,5
	.dbline -2
L4:
	xcall pop_gset1
	.dbline 0 ; func end
	ret
	.dbsym r dat 20 c
	.dbend
	.dbfunc e VS1003_HwRst _VS1003_HwRst fV
	.even
_VS1003_HwRst::
	.dbline -1
	.dbline 110
; }
; 
; 
; //---------------------------------
; //
; //      VS1003写硬复位函数 
; //
; //---------------------------------
; void VS1003_HwRst(void)
; {
	.dbline 111
; 	VS1003_XRESET_CLR();  						
	cbi 0x15,6
	.dbline 113
; 										
; 	VS1003_XRESET_SET();  								
	sbi 0x15,6
	.dbline -2
L5:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e VS1003_SfRst _VS1003_SfRst fV
	.even
_VS1003_SfRst::
	.dbline -1
	.dbline 123
; }
; 
; 
; //---------------------------------
; //
; //      VS1003软复位函数 
; //
; //---------------------------------
; void VS1003_SfRst(void)
; {
	.dbline 124
; 	VS1003_WriteReg(0x00,0x0804);								//写复位
	ldi R18,2052
	ldi R19,8
	clr R16
	xcall _VS1003_WriteReg
L7:
	.dbline 126
L8:
	.dbline 126
; 
; 	while(VS1003_DREQ_STATE() != VS1003_DREQ);					//等待软件复位结束
	in R24,0x13
	andi R24,128
	cpi R24,128
	brne L7
	.dbline 128
; 
; 	VS1003_WriteReg(VS1003_SPI_CLOCKF,0x9800);					//设置时钟3倍频
	ldi R18,38912
	ldi R19,152
	ldi R16,3
	xcall _VS1003_WriteReg
	.dbline 129
; 	VS1003_WriteReg(VS1003_SPI_AUDATA,0xB199);					//采样率48k,立体声
	ldi R18,45465
	ldi R19,177
	ldi R16,5
	xcall _VS1003_WriteReg
	.dbline 130
; 	VS1003_WriteReg(VS1003_SPI_BASS,0x0055);					//设置重音
	ldi R18,85
	ldi R19,0
	ldi R16,2
	xcall _VS1003_WriteReg
	.dbline 132
; 	
; 	VS1003_WriteDat(0);											//向vs1003发送四个字节
	clr R16
	xcall _VS1003_WriteDat
	.dbline 133
; 	VS1003_WriteDat(0);											//无效数据,启动spi
	clr R16
	xcall _VS1003_WriteDat
	.dbline 134
; 	VS1003_WriteDat(0);
	clr R16
	xcall _VS1003_WriteDat
	.dbline 135
; 	VS1003_WriteDat(0);
	clr R16
	xcall _VS1003_WriteDat
	.dbline -2
L6:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e VS1003_Init _VS1003_Init fc
	.even
_VS1003_Init::
	xcall push_gset2
	.dbline -1
	.dbline 145
; }
; 
; 
; //---------------------------------
; //
; //      VS1003初始化函数 
; //
; //---------------------------------
; uint8 VS1003_Init(void)
; {
	.dbline 146
; 	VOL=26;	
	ldi R24,26
	ldi R25,0
	sts _VOL+1,R25
	sts _VOL,R24
	.dbline 148
; 	
; 	VS1003_Port_Init();
	xcall _VS1003_Port_Init
	.dbline 150
; 	
; 	VS1003_CS_SET();
	sbi 0x15,4
	.dbline 152
; 
; 	VS1003_XDCS_SET();
	sbi 0x15,5
	.dbline 153
; 	VS1003_XRESET_CLR();
	cbi 0x15,6
	.dbline 154
; 	delay_ms(500);
	ldi R16,244
	ldi R17,1
	ldi R18,0
	ldi R19,0
	xcall _delay_ms
	.dbline 155
; 	VS1003_XRESET_SET();											  //使能芯片
	sbi 0x15,6
	.dbline 156
;     delay_ms(500);
	ldi R16,244
	ldi R17,1
	ldi R18,0
	ldi R19,0
	xcall _delay_ms
L11:
	.dbline 158
L12:
	.dbline 158
; 	
;     while(VS1003_DREQ_STATE() != VS1003_DREQ);
	in R24,0x13
	andi R24,128
	cpi R24,128
	brne L11
	.dbline 160
; 	
; 	VS1003_WriteReg(0x00,0x0804);
	ldi R18,2052
	ldi R19,8
	clr R16
	xcall _VS1003_WriteReg
L14:
	.dbline 162
L15:
	.dbline 162
; 	
; 	while(VS1003_DREQ_STATE() != VS1003_DREQ);	
	in R24,0x13
	andi R24,128
	cpi R24,128
	brne L14
	.dbline 164
; 
; 	VS1003_WriteReg(0x03,0x9800);
	ldi R18,38912
	ldi R19,152
	ldi R16,3
	xcall _VS1003_WriteReg
L17:
	.dbline 166
L18:
	.dbline 166
; 	
; 	while(VS1003_DREQ_STATE() != VS1003_DREQ);	
	in R24,0x13
	andi R24,128
	cpi R24,128
	brne L17
	.dbline 168
; 
; 	VS1003_WriteReg(0x05,0xB199);
	ldi R18,45465
	ldi R19,177
	ldi R16,5
	xcall _VS1003_WriteReg
L20:
	.dbline 170
L21:
	.dbline 170
; 	
; 	while(VS1003_DREQ_STATE() != VS1003_DREQ);	
	in R24,0x13
	andi R24,128
	cpi R24,128
	brne L20
	.dbline 172
; 
; 	VS1003_WriteReg(0x02,0x0055);
	ldi R18,85
	ldi R19,0
	ldi R16,2
	xcall _VS1003_WriteReg
L23:
	.dbline 174
L24:
	.dbline 174
; 	
; 	while(VS1003_DREQ_STATE() != VS1003_DREQ);	
	in R24,0x13
	andi R24,128
	cpi R24,128
	brne L23
	.dbline 176
; 
; 	VS1003_WriteReg(VS1003_SPI_VOL ,VOL_BUFFER[VOL]);
	lds R18,_VOL
	lds R19,_VOL+1
	ldi R16,2
	ldi R17,0
	xcall empy16s
	movw R30,R16
	ldi R24,<_VOL_BUFFER
	ldi R25,>_VOL_BUFFER
	add R30,R24
	adc R31,R25
	lpm R18,Z+
	lpm R19,Z
	ldi R16,11
	xcall _VS1003_WriteReg
L26:
	.dbline 178
L27:
	.dbline 178
; 	
; 	while(VS1003_DREQ_STATE() != VS1003_DREQ);	
	in R24,0x13
	andi R24,128
	cpi R24,128
	brne L26
	.dbline 179
; 		VS1003_WriteReg(0x05,0xB199);
	ldi R18,45465
	ldi R19,177
	ldi R16,5
	xcall _VS1003_WriteReg
L29:
	.dbline 181
L30:
	.dbline 181
; 	
; 	while(VS1003_DREQ_STATE() != VS1003_DREQ);	
	in R24,0x13
	andi R24,128
	cpi R24,128
	brne L29
	.dbline 182
; 		VS1003_WriteReg(0x05,0xB199);
	ldi R18,45465
	ldi R19,177
	ldi R16,5
	xcall _VS1003_WriteReg
L32:
	.dbline 184
L33:
	.dbline 184
; 	
; 	while(VS1003_DREQ_STATE() != VS1003_DREQ);	
	in R24,0x13
	andi R24,128
	cpi R24,128
	brne L32
	.dbline 186
; 	
; 	return 1;
	ldi R16,1
	.dbline -2
L10:
	xcall pop_gset2
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e VS1003_SendNull _VS1003_SendNull fV
;              i -> y+0
	.even
_VS1003_SendNull::
	xcall push_gset2
	sbiw R28,4
	.dbline -1
	.dbline 197
; 
; }
; 
; 
; //---------------------------------
; //
; //     VS1003空数据发送函数 
; //
; //---------------------------------
; void VS1003_SendNull(void)
; {
	.dbline 198
; 	uint32 i=0;
	ldi R20,0
	ldi R21,0
	ldi R22,0
	ldi R23,0
	movw R30,R28
	std z+0,R20
	std z+1,R21
	std z+2,R22
	std z+3,R23
L36:
	.dbline 200
; 	do
; 	{
	.dbline 201
; 		if(VS1003_DREQ_STATE()== VS1003_DREQ) 
	in R24,0x13
	andi R24,128
	cpi R24,128
	brne L39
	.dbline 202
; 		{	
	.dbline 203
; 			VS1003_WriteDat(0x00);
	clr R16
	xcall _VS1003_WriteDat
	.dbline 204
; 			i++;
	ldi R20,1
	ldi R21,0
	ldi R22,0
	ldi R23,0
	movw R30,R28
	ldd R2,z+0
	ldd R3,z+1
	ldd R4,z+2
	ldd R5,z+3
	add R2,R20
	adc R3,R21
	adc R4,R22
	adc R5,R23
	movw R30,R28
	std z+0,R2
	std z+1,R3
	std z+2,R4
	std z+3,R5
	.dbline 205
; 		}
L39:
	.dbline 206
L37:
	.dbline 206
; 	}while(i<1024);
	ldi R20,0
	ldi R21,4
	ldi R22,0
	ldi R23,0
	movw R30,R28
	ldd R2,z+0
	ldd R3,z+1
	ldd R4,z+2
	ldd R5,z+3
	cp R2,R20
	cpc R3,R21
	cpc R4,R22
	cpc R5,R23
	brlo L36
	.dbline -2
L35:
	adiw R28,4
	xcall pop_gset2
	.dbline 0 ; func end
	ret
	.dbsym l i 0 l
	.dbend
	.area bss(ram, con, rel)
	.dbfile C:\AVR\M\1\vs1003.c
_num::
	.blkb 4
	.dbsym e num _num l
_VOL::
	.blkb 2
	.dbsym e VOL _VOL i

⌨️ 快捷键说明

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