📄 vs1003.s
字号:
.module vs1003.c
.area text(rom, con, rel)
.dbfile E:\software\MP3程序\Vs1003\vs1003.c
.dbfunc e DelayIni _DelayIni fV
.even
_DelayIni::
.dbline -1
.dbline 9
; #include <iom64v.h>
; #include <macros.h>
; #define uchar unsigned char
; #define uint unsigned int
; #include "vs1003.h"
; void vs1003_infor(void);
;
; void DelayIni(void)
; {
.dbline 10
; TCCR0 = 0x00; //stop
clr R2
out 0x33,R2
.dbline 11
; TCNT0 = 0x83; //set count
ldi R24,131
out 0x32,R24
.dbline -2
L1:
.dbline 0 ; func end
ret
.dbend
.dbfunc e delay_ms _delay_ms fV
; ms -> R16
.even
_delay_ms::
.dbline -1
.dbline 15
; }
;
; void delay_ms(unsigned char ms)
; {
.dbline 16
; TCCR0 = 0x04; //start timer
ldi R24,4
out 0x33,R24
xjmp L4
X0:
.dbline 18
; while(ms--)
; {
L6:
.dbline 19
L7:
.dbline 19
in R24,0x36
andi R24,1
cpi R24,1
brne L6
.dbline 20
in R24,0x36
ori R24,1
out 0x36,R24
.dbline 21
ldi R24,131
out 0x32,R24
.dbline 22
L4:
.dbline 17
mov R2,R16
clr R3
subi R16,1
tst R2
brne L7
.dbline 23
; while((TIFR & (1<<TOV0)) != (1<<TOV0));
; TIFR |= (1<<TOV0);
; TCNT0 = 0x83; //set count
; }
; TCCR0 = 0x00; //stop
clr R2
out 0x33,R2
.dbline -2
L2:
.dbline 0 ; func end
ret
.dbsym r ms 16 c
.dbend
.dbfunc e mp3portIni _mp3portIni fV
.even
_mp3portIni::
.dbline -1
.dbline 27
; }
;
; void mp3portIni(void)
; {
.dbline 28
; DDRD |= nDCS; // 使能芯片片选输出
sbi 0x11,2
.dbline 29
; DDRD |= nCS; // 使能数据接口片选输出
sbi 0x11,3
.dbline 30
; DDRD &= ~DREQ;
cbi 0x11,0
.dbline 32
;
; PORTD |= nDCS;
sbi 0x12,2
.dbline 33
; PORTD |= nCS;
sbi 0x12,3
.dbline 34
; PORTD |= DREQ;
sbi 0x12,0
.dbline 36
;
; DDRB = 0xff; // 使能硬件复位输出
ldi R24,255
out 0x17,R24
.dbline 37
; DDRB &= ~(1<<3);
cbi 0x17,3
.dbline 38
; PORTB = 0xff;
out 0x18,R24
.dbline 40
;
; SPCR = (1 << SPE) | (1 << MSTR) | (0 << SPR1) | (0 << SPR0);
ldi R24,80
out 0xd,R24
.dbline 41
; SPSR |= 1<<SPI2X;
sbi 0xe,0
.dbline -2
L9:
.dbline 0 ; func end
ret
.dbend
.dbfunc e spiByte _spiByte fc
; tmp -> R20
; data -> R16
.even
_spiByte::
xcall push_gset1
.dbline -1
.dbline 45
; }
;
; unsigned char spiByte(unsigned char data)
; {
.dbline 47
; unsigned char tmp;
; SPDR = data;
out 0xf,R16
L11:
.dbline 48
L12:
.dbline 48
; while( !(SPSR & (1 << SPIF)) );
sbis 0xe,7
rjmp L11
.dbline 49
; tmp = SPDR;
in R20,0xf
.dbline 50
; return tmp;
mov R16,R20
.dbline -2
L10:
xcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r tmp 20 c
.dbsym r data 16 c
.dbend
.dbfunc e spiSend _spiSend fV
; data -> R16
.even
_spiSend::
.dbline -1
.dbline 54
; }
;
; void spiSend(unsigned char data)
; {
.dbline 55
; SPDR = data;
out 0xf,R16
L15:
.dbline 56
L16:
.dbline 56
; while( !(SPSR & (1 << SPIF)) );
sbis 0xe,7
rjmp L15
.dbline -2
L14:
.dbline 0 ; func end
ret
.dbsym r data 16 c
.dbend
.dbfunc e mp3WriteReg _mp3WriteReg fV
; lByte -> R20
; hByte -> R22
; add -> R10
.even
_mp3WriteReg::
xcall push_gset3
mov R22,R18
mov R10,R16
ldd R20,y+6
.dbline -1
.dbline 61
;
; }
;
; void mp3WriteReg(unsigned char add,unsigned char hByte,unsigned char lByte)
; {
L19:
.dbline 62
L20:
.dbline 62
; while((PIND & DREQ) == 0);
sbis 0x10,0
rjmp L19
.dbline 63
; mp3OutData();
.dbline 63
sbi 0x12,2
.dbline 63
.dbline 63
.dbline 64
; mp3InCmd();
.dbline 64
cbi 0x12,3
.dbline 64
.dbline 64
.dbline 65
; spiByte(VS_WRITE_COMMAND);
ldi R16,2
xcall _spiByte
.dbline 66
; spiByte(add);
mov R16,R10
xcall _spiByte
.dbline 67
; spiByte(hByte);
mov R16,R22
xcall _spiByte
.dbline 68
; spiByte(lByte);
mov R16,R20
xcall _spiByte
.dbline 69
; mp3OutCmd();
.dbline 69
sbi 0x12,3
.dbline 69
.dbline 69
.dbline -2
L18:
xcall pop_gset3
.dbline 0 ; func end
ret
.dbsym r lByte 20 c
.dbsym r hByte 22 c
.dbsym r add 10 c
.dbend
.dbfunc e mp3ReadReg _mp3ReadReg fi
; hByte -> R20
; lByte -> R22
; add -> R10
.even
_mp3ReadReg::
xcall push_gset3
mov R10,R16
.dbline -1
.dbline 73
; }
;
; unsigned int mp3ReadReg(unsigned char add)
; {
L23:
.dbline 75
L24:
.dbline 75
; unsigned char lByte,hByte;
; while((PIND & DREQ) == 0);
sbis 0x10,0
rjmp L23
.dbline 76
; mp3OutData();
.dbline 76
sbi 0x12,2
.dbline 76
.dbline 76
.dbline 77
; mp3InCmd();
.dbline 77
cbi 0x12,3
.dbline 77
.dbline 77
.dbline 78
; spiByte(VS_READ_COMMAND);
ldi R16,3
xcall _spiByte
.dbline 79
; spiByte(add);
mov R16,R10
xcall _spiByte
.dbline 80
; hByte = spiByte(0xFF);
ldi R16,255
xcall _spiByte
mov R20,R16
.dbline 81
; lByte = spiByte(0xFF);
ldi R16,255
xcall _spiByte
mov R22,R16
.dbline 82
; mp3OutCmd();
.dbline 82
sbi 0x12,3
.dbline 82
.dbline 82
.dbline 83
; return((unsigned int)(hByte << 8) | lByte);
mov R2,R22
clr R3
mov R16,R20
clr R17
mov R17,R16
clr R16
or R16,R2
or R17,R3
.dbline -2
L22:
xcall pop_gset3
.dbline 0 ; func end
ret
.dbsym r hByte 20 c
.dbsym r lByte 22 c
.dbsym r add 10 c
.dbend
.dbfunc e SoftReset _SoftReset fV
.even
_SoftReset::
sbiw R28,1
.dbline -1
.dbline 86
; }
; void SoftReset(void)
; {
.dbline 87
; SPSR &= ~(1<<SPI2X);
cbi 0xe,0
.dbline 88
; mp3WriteReg(SPI_MODE,0x08,0x04); //软件复位
ldi R24,4
std y+0,R24
ldi R18,8
clr R16
xcall _mp3WriteReg
.dbline 89
; mp3WriteReg(SPI_CLOCKF,0x58,0x00); //设置时钟3倍频
clr R2
std y+0,R2
ldi R18,88
ldi R16,3
xcall _mp3WriteReg
.dbline 90
; mp3WriteReg(SPI_VOL,0X01,0X01); //设置音量
ldi R24,1
std y+0,R24
ldi R18,1
ldi R16,11
xcall _mp3WriteReg
.dbline 91
; delay_ms(100);
ldi R16,100
xcall _delay_ms
.dbline 92
; delay_ms(1);
ldi R16,1
xcall _delay_ms
.dbline 93
; mp3InData();
.dbline 93
cbi 0x12,2
.dbline 93
.dbline 93
.dbline 94
; spiByte(0);
clr R16
xcall _spiByte
.dbline 95
; spiByte(0);
clr R16
xcall _spiByte
.dbline 96
; spiByte(0);
clr R16
xcall _spiByte
.dbline 97
; spiByte(0);
clr R16
xcall _spiByte
.dbline 98
; mp3OutData();
.dbline 98
sbi 0x12,2
.dbline 98
.dbline 98
.dbline 99
; SPSR |= 1<<SPI2X;
sbi 0xe,0
.dbline -2
L26:
adiw R28,1
.dbline 0 ; func end
ret
.dbend
.dbfunc e mp3Reset _mp3Reset fV
.even
_mp3Reset::
sbiw R28,1
.dbline -1
.dbline 103
; }
;
; void mp3Reset(void)
; {
.dbline 104
; SPSR &= ~(1<<SPI2X);
cbi 0xe,0
.dbline 105
; mp3OutCmd();
.dbline 105
sbi 0x12,3
.dbline 105
.dbline 105
.dbline 106
; mp3OutData();
.dbline 106
sbi 0x12,2
.dbline 106
.dbline 106
.dbline 107
; mp3OutRst();
.dbline 107
sbi 0x18,7
.dbline 107
.dbline 107
.dbline 108
; delay_ms(250);
ldi R16,250
xcall _delay_ms
.dbline 110
;
; mp3InRst();
.dbline 110
cbi 0x18,7
.dbline 110
.dbline 110
.dbline 111
; delay_ms(250);
ldi R16,250
xcall _delay_ms
.dbline 112
; mp3OutRst();
.dbline 112
sbi 0x18,7
.dbline 112
.dbline 112
.dbline 113
; delay_ms(150);
ldi R16,150
xcall _delay_ms
.dbline 115
;
; mp3WriteReg(SPI_MODE, 0x08, 0x00); /* Normal SW reset + other bits */
clr R2
std y+0,R2
ldi R18,8
clr R16
xcall _mp3WriteReg
.dbline 116
; delay_ms(150);
ldi R16,150
xcall _delay_ms
.dbline 117
; mp3WriteReg(SPI_CLOCKF, 0x58, 0x00); /* 4.0x 12.288MHz */
clr R2
std y+0,R2
ldi R18,88
ldi R16,3
xcall _mp3WriteReg
.dbline 118
; delay_ms(150);
ldi R16,150
xcall _delay_ms
.dbline 119
; mp3WriteReg(SPI_VOL, 0x01, 0x01); /* Recording monitor volume */
ldi R24,1
std y+0,R24
ldi R18,1
ldi R16,11
xcall _mp3WriteReg
.dbline 120
; delay_ms(150);
ldi R16,150
xcall _delay_ms
.dbline 121
; mp3WriteReg(SPI_BASS, 0x00, 0x00); /* Bass/treble disabled */
clr R2
std y+0,R2
clr R18
ldi R16,2
xcall _mp3WriteReg
.dbline 122
; delay_ms(150);
ldi R16,150
xcall _delay_ms
L28:
.dbline 123
L29:
.dbline 123
; while((PIND & DREQ) == 0);
sbis 0x10,0
rjmp L28
.dbline 124
; delay_ms(250);
ldi R16,250
xcall _delay_ms
.dbline 126
; //vs1003_infor();
; SPSR |= 1<<SPI2X;
sbi 0xe,0
.dbline -2
L27:
adiw R28,1
.dbline 0 ; func end
ret
.dbend
.dbfunc e vs1003_infor _vs1003_infor fV
.even
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -