📄 vs1001.s
字号:
.module vs1001.c
.area text(rom, con, rel)
.dbfile C:\DATA\MP3\Player\Code\vs1001.c
.dbfunc e WriteByteSPI _WriteByteSPI fc
; byte -> R16
.even
_WriteByteSPI::
.dbline -1
.dbline 11
; #include <iom128v.h>
; #include <macros.h>
; #include "vs1001.h"
; #include "generic.h"
; #include "remote.h"
;
; //*************************************
; // unsigned char byte void WriteByteSPI(unsigned char byte)
; //*************************************
; unsigned char WriteByteSPI(unsigned char byte)
; {
.dbline 12
; SPDR = byte;
out 0xf,R16
L2:
.dbline 13
L3:
.dbline 13
; while(!(SPSR & (1<<SPIF))); // Wait Queue off
sbis 0xe,7
rjmp L2
.dbline 14
; return SPDR;
in R16,0xf
.dbline -2
L1:
.dbline 0 ; func end
ret
.dbsym r byte 16 c
.dbend
.dbfunc e VS1001_Read _VS1001_Read fV
; pData -> R22,R23
; Count -> R20,R21
; Address -> R10
.even
_VS1001_Read::
xcall push_gset3
movw R20,R18
mov R10,R16
ldd R22,y+6
ldd R23,y+7
.dbline -1
.dbline 21
; }
;
; //*************************************
; // void VS1001_Read(unsigned char Address,int Count,unsigned int *pData)
; //*************************************
; void VS1001_Read(unsigned char Address,int Count,unsigned int *pData)
; {
.dbline 22
; PORT_MP3_OUT &= ~XCS; // XCS Low
cbi 0x18,4
.dbline 23
; WriteByteSPI(VS1001_READ);
ldi R16,3
xcall _WriteByteSPI
.dbline 24
; WriteByteSPI(Address);
mov R16,R10
xcall _WriteByteSPI
xjmp L7
L6:
.dbline 26
.dbline 27
clr R16
xcall _WriteByteSPI
mov R2,R16
clr R3
mov R3,R2
clr R2
movw R30,R22
std z+1,R3
std z+0,R2
.dbline 28
subi R22,254 ; offset = 2
sbci R23,255
clr R16
push R30
push R31
xcall _WriteByteSPI
pop R3
pop R2
mov R4,R16
clr R5
movw R30,R2
ldd R6,z+0
ldd R7,z+1
or R6,R4
or R7,R5
std z+1,R7
std z+0,R6
.dbline 29
L7:
.dbline 25
; while(Count--)
movw R2,R20
subi R20,1
sbci R21,0
tst R2
brne L6
tst R3
brne L6
X0:
.dbline 30
; {
; *pData = WriteByteSPI(0) << 8;
; *pData++ |= WriteByteSPI(0);
; }
; PORT_MP3_OUT |= XCS; // XCS High
sbi 0x18,4
.dbline 31
; delay_us(5);
ldi R16,5
ldi R17,0
xcall _delay_us
.dbline -2
.dbline 32
; }
L5:
xcall pop_gset3
.dbline 0 ; func end
ret
.dbsym r pData 22 pi
.dbsym r Count 20 I
.dbsym r Address 10 c
.dbend
.dbfunc e VS1001_Write _VS1001_Write fV
; pData -> R22,R23
; Count -> R20,R21
; Address -> R10
.even
_VS1001_Write::
xcall push_gset3
movw R20,R18
mov R10,R16
ldd R22,y+6
ldd R23,y+7
.dbline -1
.dbline 38
;
; //*************************************
; // void VS1001_Write(unsigned char Address,int Count,unsigned int *pData)
; //*************************************
; void VS1001_Write(unsigned char Address,int Count,unsigned int *pData)
; {
.dbline 39
; PORT_MP3_OUT &= ~XCS; // XCS Low
cbi 0x18,4
.dbline 40
; WriteByteSPI(VS1001_WRITE);
ldi R16,2
xcall _WriteByteSPI
.dbline 41
; WriteByteSPI(Address);
mov R16,R10
xcall _WriteByteSPI
xjmp L11
L10:
.dbline 43
.dbline 44
movw R30,R22
ldd R16,z+0
ldd R17,z+1
mov R16,R17
clr R17
xcall _WriteByteSPI
.dbline 45
movw R30,R22
ldd R16,z+0
xcall _WriteByteSPI
.dbline 46
L11:
.dbline 42
; while(Count--)
movw R2,R20
subi R20,1
sbci R21,0
tst R2
brne L10
tst R3
brne L10
X1:
.dbline 47
; {
; WriteByteSPI((unsigned char) ((*pData) >> 8));
; WriteByteSPI((unsigned char) *pData);
; }
; PORT_MP3_OUT |= XCS; // XCS High
sbi 0x18,4
.dbline 48
; delay_us(5);
ldi R16,5
ldi R17,0
xcall _delay_us
.dbline -2
.dbline 49
; }
L9:
xcall pop_gset3
.dbline 0 ; func end
ret
.dbsym r pData 22 pi
.dbsym r Count 20 I
.dbsym r Address 10 c
.dbend
.dbfunc e VS1001_Stream _VS1001_Stream fV
; Qte -> R22
; Data -> R20,R21
.even
_VS1001_Stream::
xcall push_gset2
mov R22,R18
movw R20,R16
.dbline -1
.dbline 55
;
; //*************************************
; // void VS1001_Stream(unsigned char Data,unsigned char Qte)
; //*************************************
; void VS1001_Stream(unsigned char *Data,unsigned char Qte)
; {
xjmp L15
L14:
.dbline 57
; while(Qte--)
; {
.dbline 58
; PORT_MP3_OUT |= BSYNC; // BSYNC High
sbi 0x18,5
.dbline 59
; WDR();
wdr
.dbline 60
; WDR();
wdr
.dbline 61
; SPDR = *Data++;
movw R30,R20
ld R2,Z+
movw R20,R30
out 0xf,R2
.dbline 62
; delay_us(1);
ldi R16,1
ldi R17,0
xcall _delay_us
.dbline 63
; PORT_MP3_OUT &= ~BSYNC; // BSYNC Low
cbi 0x18,5
L17:
.dbline 64
L18:
.dbline 64
sbis 0xe,7
rjmp L17
.dbline 65
L15:
.dbline 56
mov R2,R22
clr R3
subi R22,1
tst R2
brne L14
.dbline -2
.dbline 66
; while(!(SPSR & (1<<SPIF))); // Wait Queue off
; }
; }
L13:
xcall pop_gset2
.dbline 0 ; func end
ret
.dbsym r Qte 22 c
.dbsym r Data 20 pc
.dbend
.dbfunc e VS1001Init _VS1001Init fV
; buf -> y+34
; null -> y+2
; i -> R20,R21
; HardReset -> R20
.even
_VS1001Init::
xcall push_gset1
mov R20,R16
sbiw R28,38
.dbline -1
.dbline 72
;
; //*************************************
; // void VS1001Init(void)
; //*************************************
; void VS1001Init(unsigned char HardReset)
; {
.dbline 77
; unsigned int buf[2];
; unsigned char null[32];
; int i;
;
; if (HardReset == TRUE)
cpi R20,1
brne L21
.dbline 78
; {
.dbline 79
; PORT_MP3_DDR = XRES | BSYNC | XCS | MOSI | SCK | SS;
ldi R24,119
out 0x17,R24
.dbline 80
; SPCR = 0x51; // SPI ENABLE, MSB FIRST, MASTER,
ldi R24,81
out 0xd,R24
.dbline 84
; // CPOL=0, CPHA=0, CLK/16
;
;
; PORT_MP3_OUT = XRES + XCS; // XCS 1 - RESET 1 - BSYNC 0
ldi R24,80
out 0x18,R24
.dbline 85
; delay_ms(5);
ldi R16,5
ldi R17,0
xcall _delay_ms
.dbline 87
;
; PORT_MP3_OUT &= ~XRES; // Reset is 0
cbi 0x18,6
.dbline 88
; delay_ms(5);
ldi R16,5
ldi R17,0
xcall _delay_ms
.dbline 89
; PORT_MP3_OUT |= XRES;; // Reset is 1
sbi 0x18,6
.dbline 89
.dbline 90
; delay_ms(5);
ldi R16,5
ldi R17,0
xcall _delay_ms
.dbline 91
; }
L21:
.dbline 93
clr R20
clr R21
L23:
.dbline 93
movw R24,R28
adiw R24,2
movw R30,R20
add R30,R24
adc R31,R25
clr R2
std z+0,R2
L24:
.dbline 93
;
; for (i=0;i<32;i++) null[i] = 0;
subi R20,255 ; offset = 1
sbci R21,255
.dbline 93
cpi R20,32
ldi R30,0
cpc R21,R30
brlt L23
.dbline 95
;
; delay_ms(5);
ldi R16,5
ldi R17,0
xcall _delay_ms
.dbline 96
; VS1001_Stream(&null[0],32); // 32 null's
ldi R18,32
movw R16,R28
subi R16,254 ; offset = 2
sbci R17,255
xcall _VS1001_Stream
.dbline 97
; delay_ms(200);
ldi R16,200
ldi R17,0
xcall _delay_ms
.dbline 99
;
; buf[0] = 0x0004;
ldi R24,4
ldi R25,0
std y+35,R25
std y+34,R24
.dbline 100
; VS1001_Write(0,1,buf);
movw R24,R28
adiw R24,34
std y+1,R25
std y+0,R24
ldi R18,1
ldi R19,0
clr R16
xcall _VS1001_Write
.dbline 101
; delay_ms(2);
ldi R16,2
ldi R17,0
xcall _delay_ms
L27:
.dbline 102
L28:
.dbline 102
; while(!(PORT_MP3_IN & DREQ)); // wait for DREQ
sbis 0x16,7
rjmp L27
.dbline 104
;
; buf[0] = 0x0000;
clr R2
clr R3
std y+35,R3
std y+34,R2
.dbline 105
; VS1001_Write(0,1,buf);
movw R24,R28
adiw R24,34
std y+1,R25
std y+0,R24
ldi R18,1
ldi R19,0
clr R16
xcall _VS1001_Write
.dbline 106
; delay_ms(2);
ldi R16,2
ldi R17,0
xcall _delay_ms
L30:
.dbline 107
L31:
.dbline 107
; while(!(PORT_MP3_IN & DREQ)); // wait for DREQ
sbis 0x16,7
rjmp L30
.dbline 109
;
; buf[0] = 0x9800; // Clock 12.288Mhz
ldi R24,38912
ldi R25,152
std y+35,R25
std y+34,R24
.dbline 110
; VS1001_Write(3,1,buf);
movw R24,R28
adiw R24,34
std y+1,R25
std y+0,R24
ldi R18,1
ldi R19,0
ldi R16,3
xcall _VS1001_Write
.dbline 111
; VS1001_Stream(&null[0],16); // 16 null's
ldi R18,16
movw R16,R28
subi R16,254 ; offset = 2
sbci R17,255
xcall _VS1001_Stream
.dbline 112
; VS1001_SetVolume(10,10);
ldi R18,10
ldi R16,10
xcall _VS1001_SetVolume
.dbline -2
.dbline 113
; }
L20:
adiw R28,38
xcall pop_gset1
.dbline 0 ; func end
ret
.dbsym l buf 34 A[4:2]i
.dbsym l null 2 A[32:32]c
.dbsym r i 20 I
.dbsym r HardReset 20 c
.dbend
.dbfunc e Reg_Test _Reg_Test fc
; buf -> y+2
; j -> R20,R21
.even
_Reg_Test::
xcall push_gset1
sbiw R28,42
.dbline -1
.dbline 119
;
; //*************************************
; // void Reg_Test(void)
; //*************************************
; unsigned char Reg_Test()
; {
.dbline 123
; unsigned int buf[20];
; unsigned int j;
;
; for (j=0;j<20;j++)
clr R20
clr R21
xjmp L37
L34:
.dbline 124
; {
.dbline 125
; buf[0] = j*256+j;
ldi R16,256
ldi R17,1
movw R18,R20
xcall empy16s
movw R2,R16
add R2,R20
adc R3,R21
std y+3,R3
std y+2,R2
.dbline 126
; VS1001_Write(3,1,buf);
movw R24,R28
adiw R24,2
std y+1,R25
std y+0,R24
ldi R18,1
ldi R19,0
ldi R16,3
xcall _VS1001_Write
.dbline 127
; buf[0] = 0xffff;
ldi R24,65535
ldi R25,255
std y+3,R25
std y+2,R24
.dbline 128
; VS1001_Read(3,1,buf);
movw R24,R28
adiw R24,2
std y+1,R25
std y+0,R24
ldi R18,1
ldi R19,0
ldi R16,3
xcall _VS1001_Read
.dbline 129
; if (buf[0] != j*256+j) return 0;
ldi R16,256
ldi R17,1
movw R18,R20
xcall empy16s
movw R2,R16
add R2,R20
adc R3,R21
ldd R4,y+2
ldd R5,y+3
cp R4,R2
cpc R5,R3
breq L38
.dbline 129
clr R16
xjmp L33
L38:
.dbline 130
L35:
.dbline 123
subi R20,255 ; offset = 1
sbci R21,255
L37:
.dbline 123
cpi R20,20
ldi R30,0
cpc R21,R30
brlo L34
.dbline 131
; }
; return 1;
ldi R16,1
.dbline -2
L33:
adiw R28,42
xcall pop_gset1
.dbline 0 ; func end
ret
.dbsym l buf 2 A[40:20]i
.dbsym r j 20 i
.dbend
.dbfunc e Sine_On _Sine_On fV
; i -> <dead>
; buf -> y+0
; Freq -> R20
.even
_Sine_On::
xcall push_gset1
mov R20,R16
sbiw R28,4
.dbline -1
.dbline 138
; }
;
; //*************************************
; // void Sine_On(unsigned char Freq)
; //*************************************
; void Sine_On(unsigned char Freq)
; {
.dbline 141
; unsigned char i,buf[4];
;
; buf[0] = 0x53;
ldi R24,83
std y+0,R24
.dbline 142
; buf[1] = 0xef;
ldi R24,239
std y+1,R24
.dbline 143
; buf[2] = 0x6e;
ldi R24,110
std y+2,R24
.dbline 144
; buf[3] = Freq;
std y+3,R20
.dbline 145
; VS1001_Stream(&buf[0],4);
ldi R18,4
movw R16,R28
xcall _VS1001_Stream
.dbline 147
;
; buf[0] = 0x00;
clr R2
std y+0,R2
.dbline 148
; buf[1] = 0x00;
std y+1,R2
.dbline 149
; buf[2] = 0x00;
std y+2,R2
.dbline 150
; buf[3] = 0x00;
std y+3,R2
.dbline 151
; VS1001_Stream(&buf[0],4);
ldi R18,4
movw R16,R28
xcall _VS1001_Stream
.dbline -2
.dbline 152
; }
L40:
adiw R28,4
xcall pop_gset1
.dbline 0 ; func end
ret
.dbsym l i 1 c
.dbsym l buf 0 A[4:4]c
.dbsym r Freq 20 c
.dbend
.dbfunc e Sine_Off _Sine_Off fV
; i -> <dead>
; buf -> y+0
.even
_Sine_Off::
sbiw R28,4
.dbline -1
.dbline 158
;
; //*************************************
; // void Sine_Off(void)
; //*************************************
; void Sine_Off(void)
; {
.dbline 161
; unsigned char i,buf[4];
;
; buf[0] = 0x45;
ldi R24,69
std y+0,R24
.dbline 162
; buf[1] = 0x78;
ldi R24,120
std y+1,R24
.dbline 163
; buf[2] = 0x69;
ldi R24,105
std y+2,R24
.dbline 164
; buf[3] = 0x74;
ldi R24,116
std y+3,R24
.dbline 165
; VS1001_Stream(&buf[0],4);
ldi R18,4
movw R16,R28
xcall _VS1001_Stream
.dbline 167
;
; buf[0] = 0x00;
clr R2
std y+0,R2
.dbline 168
; buf[1] = 0x00;
std y+1,R2
.dbline 169
; buf[2] = 0x00;
std y+2,R2
.dbline 170
; buf[3] = 0x00;
std y+3,R2
.dbline 171
; VS1001_Stream(&buf[0],4);
ldi R18,4
movw R16,R28
xcall _VS1001_Stream
.dbline -2
.dbline 172
; }
L47:
adiw R28,4
.dbline 0 ; func end
ret
.dbsym l i 1 c
.dbsym l buf 0 A[4:4]c
.dbend
.dbfunc e Sine_Sweep _Sine_Sweep fV
; i -> R20
.even
_Sine_Sweep::
xcall push_gset1
.dbline -1
.dbline 178
;
; //*************************************
; // void Sine_Sweep(void)
; //*************************************
; void Sine_Sweep(void)
; {
.dbline 181
; unsigned char i;
;
; for (i=48;i<119;i++)
ldi R20,48
xjmp L58
L55:
.dbline 182
.dbline 183
xcall _Sine_Off
.dbline 184
mov R16,R20
xcall _Sine_On
.dbline 185
ldi R16,25
ldi R17,0
xcall _delay_ms
.dbline 186
L56:
.dbline 181
inc R20
L58:
.dbline 181
cpi R20,119
brlo L55
.dbline 187
; {
; Sine_Off();
; Sine_On(i);
; delay_ms(25);
; }
; Sine_Off();
xcall _Sine_Off
.dbline -2
.dbline 188
; }
L54:
xcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r i 20 c
.dbend
.dbfunc e VS1001_SetVolume _VS1001_SetVolume fV
; buf -> y+2
; Right -> R22
; Left -> R20
.even
_VS1001_SetVolume::
xcall push_gset2
mov R22,R18
mov R20,R16
sbiw R28,6
.dbline -1
.dbline 194
;
; //*************************************
; // void VS1001_SetVolume(unsigned char Left,unsigned char Right)
; //*************************************
; void VS1001_SetVolume(unsigned char Left,unsigned char Right)
; {
.dbline 197
; unsigned int buf[2];
;
; buf[0] = (((unsigned int)Left) << 8) | ((unsigned int)Right);
mov R2,R22
clr R3
mov R4,R20
clr R5
mov R5,R4
clr R4
or R4,R2
or R5,R3
std y+3,R5
std y+2,R4
.dbline 198
; VS1001_Write(11,1,buf);
movw R24,R28
adiw R24,2
std y+1,R25
std y+0,R24
ldi R18,1
ldi R19,0
ldi R16,11
xcall _VS1001_Write
.dbline -2
.dbline 199
; }
L59:
adiw R28,6
xcall pop_gset2
.dbline 0 ; func end
ret
.dbsym l buf 2 A[4:2]i
.dbsym r Right 22 c
.dbsym r Left 20 c
.dbend
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -