📄 vs1011b.s
字号:
.module VS1011B.c
.area text(rom, con, rel)
.dbfile D:\学习\AVRpro\Mega16程序\TestLCD\VS1011B.c
.dbfunc e VS1011B_SPI_Low _VS1011B_SPI_Low fV
.even
_VS1011B_SPI_Low::
.dbline -1
.dbline 18
; # include "iom16v.h"
; # include "macros.h"
; # include "VS1011B.h"
;
; #define uchar unsigned char
; #define uint unsigned int
; #ifndef SPI_CS_Deassert()
; #define MMC_SD_PORT PORTB //引脚定义
; #define MMC_SD_CS_PIN 4 //mega16,MMC/SD卡的片选引脚,接PortB4/ss
; #define SPI_CS_Deassert() MMC_SD_PORT |= BIT(MMC_SD_CS_PIN) //SS为高,释放MMC
; #endif
;
; extern unsigned char CurVol,CurBass;
; extern void Delay(unsigned int DelayTimes);
;
; //以最低速度运行 //low speed
; void VS1011B_SPI_Low(void)
; {
.dbline 19
; SPCR = BIT(SPE)|BIT(MSTR)|BIT(SPR1)|BIT(SPR0);
ldi R24,83
out 0xd,R24
.dbline 20
; SPSR &= ~BIT(SPI2X);
cbi 0xe,0
.dbline -2
L1:
.dbline 0 ; func end
ret
.dbend
.dbfunc e VS1011B_SPI_High _VS1011B_SPI_High fV
.even
_VS1011B_SPI_High::
.dbline -1
.dbline 25
; }
;
; //以FCK/4速度运行 //full speed
; void VS1011B_SPI_High(void)
; {
.dbline 26
; SPCR = BIT(SPE)|BIT(MSTR);
ldi R24,80
out 0xd,R24
.dbline 27
; SPSR |= BIT(SPI2X);
sbi 0xe,0
.dbline -2
L2:
.dbline 0 ; func end
ret
.dbend
.dbfunc e VS1011B_WriteByte _VS1011B_WriteByte fV
; CH -> R16
.even
_VS1011B_WriteByte::
.dbline -1
.dbline 32
; }
;
; //向VS1011B写一字节 //write one byte to vs1011b
; void VS1011B_WriteByte(unsigned char CH)
; {
.dbline 33
; SPDR = CH;
out 0xf,R16
L4:
.dbline 34
; while(!(SPSR & BIT(SPIF)));
L5:
.dbline 34
sbis 0xe,7
rjmp L4
X0:
.dbline -2
L3:
.dbline 0 ; func end
ret
.dbsym r CH 16 c
.dbend
.dbfunc e VS1011B_ReadByte _VS1011B_ReadByte fc
.even
_VS1011B_ReadByte::
.dbline -1
.dbline 39
; }
;
; //从VS1011B读一字节 //read one byte from vs1011b
; unsigned char VS1011B_ReadByte(void)
; {
.dbline 40
; SPDR = 0xff;
ldi R24,255
out 0xf,R24
L8:
.dbline 41
; while(!(SPSR & BIT(SPIF)));
L9:
.dbline 41
sbis 0xe,7
rjmp L8
X1:
.dbline 42
; return SPDR;
in R16,0xf
.dbline -2
L7:
.dbline 0 ; func end
ret
.dbend
.dbfunc e VS1011B_WriteCMD _VS1011B_WriteCMD fV
; dat -> R10,R11
; addr -> R12
.even
_VS1011B_WriteCMD::
xcall push_xgset003C
movw R10,R18
mov R12,R16
.dbline -1
.dbline 47
; }
;
; //写寄存器,参数,地址和数据 //config register
; void VS1011B_WriteCMD(unsigned char addr, unsigned int dat)
; {
.dbline 48
; VS1011B_XDCS_H();
sbi 0x1b,0
.dbline 49
; VS1011B_XCS_L();
cbi 0x1b,1
.dbline 50
; VS1011B_WriteByte(0x02);
ldi R16,2
xcall _VS1011B_WriteByte
.dbline 51
; VS1011B_WriteByte(addr);
mov R16,R12
xcall _VS1011B_WriteByte
.dbline 52
; VS1011B_WriteByte(dat>>8);
movw R16,R10
mov R16,R17
clr R17
xcall _VS1011B_WriteByte
.dbline 53
; VS1011B_WriteByte(dat);
mov R16,R10
xcall _VS1011B_WriteByte
.dbline 54
; VS1011B_XCS_H();
sbi 0x1b,1
.dbline -2
L11:
.dbline 0 ; func end
xjmp pop_xgset003C
.dbsym r dat 10 i
.dbsym r addr 12 c
.dbend
.dbfunc e VS1011B_ReadCMD _VS1011B_ReadCMD fi
; temp -> R10,R11
; addr -> R10
.even
_VS1011B_ReadCMD::
st -y,R10
st -y,R11
mov R10,R16
.dbline -1
.dbline 59
; }
;
; //读寄存器,参数 地址 返回内容 //read register
; unsigned int VS1011B_ReadCMD(unsigned char addr)
; {
.dbline 61
; unsigned int temp;
; VS1011B_XDCS_H();
sbi 0x1b,0
.dbline 62
; VS1011B_XCS_L();
cbi 0x1b,1
.dbline 63
; VS1011B_WriteByte(0x03);
ldi R16,3
xcall _VS1011B_WriteByte
.dbline 64
; VS1011B_WriteByte(addr);
mov R16,R10
xcall _VS1011B_WriteByte
.dbline 65
; temp = VS1011B_ReadByte();
xcall _VS1011B_ReadByte
mov R10,R16
clr R11
.dbline 66
; temp <<= 8;
mov R11,R10
clr R10
.dbline 67
; temp += VS1011B_ReadByte();
xcall _VS1011B_ReadByte
mov R2,R16
clr R3
add R10,R2
adc R11,R3
.dbline 68
; VS1011B_XCS_H();
sbi 0x1b,1
.dbline 69
; return temp;
movw R16,R10
.dbline -2
L12:
.dbline 0 ; func end
ld R11,y+
ld R10,y+
ret
.dbsym r temp 10 i
.dbsym r addr 10 c
.dbend
.dbfunc e VS1011B_WriteDAT _VS1011B_WriteDAT fV
; dat -> R10
.even
_VS1011B_WriteDAT::
st -y,R10
mov R10,R16
.dbline -1
.dbline 74
; }
;
; //写数据,音乐数据 //write data (music data)
; void VS1011B_WriteDAT(unsigned char dat)
; {
.dbline 75
; VS1011B_XDCS_L();
cbi 0x1b,0
.dbline 76
; VS1011B_WriteByte(dat);
mov R16,R10
xcall _VS1011B_WriteByte
.dbline 77
; VS1011B_XDCS_H();
sbi 0x1b,0
.dbline 78
; VS1011B_XCS_H();
sbi 0x1b,1
.dbline -2
L13:
.dbline 0 ; func end
ld R10,y+
ret
.dbsym r dat 10 c
.dbend
.dbfunc e VS1011B_Init _VS1011B_Init fc
; Tmp -> R10,R11
; retry -> R20
.even
_VS1011B_Init::
xcall push_xgsetF03C
.dbline -1
.dbline 83
; }
;
; // 1 means fail, 0 OK!
; unsigned char VS1011B_Init(void)
; {
.dbline 86
; unsigned char retry;
; unsigned int Tmp;
; DDRB |= BIT(4)|BIT(5)|BIT(7); //mega16,这些SPI端口要输出
in R24,0x17
ori R24,176
out 0x17,R24
.dbline 87
; DDRB &=~BIT(6); //MISO为输入方式
cbi 0x17,6
.dbline 88
; SPI_CS_Deassert(); //释放MMC/SD卡
sbi 0x18,4
.dbline 89
; VS1011B_PORT_INI();
in R24,0x1a
ori R24,67
out 0x1a,R24
.dbline 90
; DDRA &=~BIT(VS1011B_DREQ); //DREQ为输入
cbi 0x1a,2
.dbline 91
; PORTA|= BIT(VS1011B_DREQ); //DREQ=1
sbi 0x1b,2
.dbline 93
;
; VS1011B_XCS_H();
sbi 0x1b,1
.dbline 94
; VS1011B_XDCS_H();
sbi 0x1b,0
.dbline 95
; VS1011B_XRESET_L();
cbi 0x1b,6
.dbline 96
; Delay(2);
ldi R16,2
ldi R17,0
xcall _Delay
.dbline 97
; VS1011B_XRESET_H();//使能芯片 //chip select
sbi 0x1b,6
.dbline 98
; VS1011B_SPI_Low();//先以低频操作 //low speed
xcall _VS1011B_SPI_Low
.dbline 99
; Delay(2);
ldi R16,2
ldi R17,0
xcall _Delay
.dbline 100
; Delay(2);
ldi R16,2
ldi R17,0
xcall _Delay
.dbline 101
; retry=0;
clr R20
.dbline 103
;
; VS1011B_ReadCMD(0x03);
ldi R16,3
xcall _VS1011B_ReadCMD
xjmp L16
L15:
.dbline 105
; while(VS1011B_ReadCMD(0x03)!=CLOCK_REG)//写时钟寄存器 //set PLL register
; {
.dbline 106
; VS1011B_WriteCMD(0x03,CLOCK_REG);
ldi R18,12288
ldi R19,48
ldi R16,3
xcall _VS1011B_WriteCMD
.dbline 107
; if(retry++ >10 )return 1;
mov R2,R20
clr R3
subi R20,255 ; addi 1
ldi R24,10
cp R24,R2
brsh L18
X2:
.dbline 107
ldi R16,1
xjmp L14
L18:
.dbline 108
; }
L16:
.dbline 104
ldi R16,3
xcall _VS1011B_ReadCMD
cpi R16,0
ldi R30,48
cpc R17,R30
brne L15
X3:
.dbline 110
;
; Delay(2);
ldi R16,2
ldi R17,0
xcall _Delay
.dbline 112
;
; VS1011B_WriteCMD(0x05,0xBB81);//0xBB81 AC45);
ldi R18,48001
ldi R19,187
ldi R16,5
xcall _VS1011B_WriteCMD
.dbline 114
;
; retry=0;
clr R20
.dbline 115
; Tmp=CurVol*256+CurVol;
lds R10,_CurVol
mov R18,R10
clr R19
ldi R16,256
ldi R17,1
xcall empy16s
movw R2,R16
mov R4,R10
clr R5
add R2,R4
adc R3,R5
movw R10,R2
xjmp L21
L20:
.dbline 117
; while(VS1011B_ReadCMD(0x0b) != Tmp)//设音量 //set Volume
; {
.dbline 118
; VS1011B_WriteCMD(0x0b,Tmp);
movw R18,R10
ldi R16,11
xcall _VS1011B_WriteCMD
.dbline 119
; if(retry++ >10 )return 2;
mov R22,R20
clr R23
subi R20,255 ; addi 1
ldi R24,10
cp R24,R22
brsh L23
X4:
.dbline 119
ldi R16,2
xjmp L14
L23:
.dbline 120
; }
L21:
.dbline 116
ldi R16,11
xcall _VS1011B_ReadCMD
movw R12,R16
cp R16,R10
cpc R17,R11
brne L20
X5:
.dbline 122
;
; retry=0;
clr R20
.dbline 123
; Tmp=CurBass;
lds R10,_CurBass
clr R11
xjmp L26
L25:
.dbline 125
; while(VS1011B_ReadCMD(0x02)!=Tmp)//写低音寄存器
; {
.dbline 126
; VS1011B_WriteCMD(0x02,Tmp);
movw R18,R10
ldi R16,2
xcall _VS1011B_WriteCMD
.dbline 127
; if(retry++ >10 )return 1;
mov R22,R20
clr R23
subi R20,255 ; addi 1
ldi R24,10
cp R24,R22
brsh L28
X6:
.dbline 127
ldi R16,1
xjmp L14
L28:
.dbline 128
; }
L26:
.dbline 124
ldi R16,2
xcall _VS1011B_ReadCMD
movw R12,R16
cp R16,R10
cpc R17,R11
brne L25
X7:
.dbline 129
; Delay(2);
ldi R16,2
ldi R17,0
xcall _Delay
.dbline 131
;
; retry=0;
clr R20
xjmp L31
L30:
.dbline 133
; while(VS1011B_ReadCMD(0x00) != 0x0800)//0x0800)//写mode寄存器 //set mode register
; {
.dbline 134
; VS1011B_WriteCMD(0x00,0x0800);//0x0800);
ldi R18,2048
ldi R19,8
clr R16
xcall _VS1011B_WriteCMD
.dbline 135
; if(retry++ >10 )return 3;//
mov R22,R20
clr R23
subi R20,255 ; addi 1
ldi R24,10
cp R24,R22
brsh L33
X8:
.dbline 135
ldi R16,3
xjmp L14
L33:
.dbline 136
; }
L31:
.dbline 132
clr R16
xcall _VS1011B_ReadCMD
movw R22,R16
cpi R16,0
ldi R30,8
cpc R17,R30
brne L30
X9:
.dbline 138
;
; Delay(2);
ldi R16,2
ldi R17,0
xcall _Delay
.dbline 140
;
; VS1011B_SoftReset();
xcall _VS1011B_SoftReset
.dbline 141
; VS1011B_SPI_High();
xcall _VS1011B_SPI_High
.dbline 142
; return 0;
clr R16
.dbline -2
L14:
.dbline 0 ; func end
xjmp pop_xgsetF03C
.dbsym r Tmp 10 i
.dbsym r retry 20 c
.dbend
.dbfunc e VS1011B_SoftReset _VS1011B_SoftReset fV
.even
_VS1011B_SoftReset::
.dbline -1
.dbline 147
; }
;
; //VS1003软件复位 //VS1003 soft reset
; void VS1011B_SoftReset(void)
; {
.dbline 148
; VS1011B_WriteCMD(0x00,0x0804);//写复位 //reset
ldi R18,2052
ldi R19,8
clr R16
xcall _VS1011B_WriteCMD
.dbline 149
; Delay(2);//延时,至少1.35ms //wait at least 1.35ms
ldi R16,2
ldi R17,0
xcall _Delay
.dbline 150
; DDRA &=~BIT(VS1011B_DREQ); //DREQ为输入
cbi 0x1a,2
.dbline 151
; PORTA|= BIT(VS1011B_DREQ); //DREQ=1
sbi 0x1b,2
.dbline -2
L35:
.dbline 0 ; func end
ret
.dbend
; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -