📄 1011.s
字号:
.module _1011.c
.area text(rom, con, rel)
.dbfile D:\Temp\AVRTest\SDMP3~1\1011.c
.dbfunc e delay_Nus _delay_Nus fV
; b -> R20
; n -> R16,R17
.even
_delay_Nus::
xcall push_gset1
.dbline -1
.dbline 19
; /************************************************************/
; /* VS1011 Code for M32L */
; /* By pasyong */
; /* 2006-4 */
; /* Base ICC6.31A */
; /************************************************************/
; #include <iom32v.h>
; #include <macros.h>
; #define uchar unsigned char
; #define uint unsigned int
; #define MP3_DDR DDRB
; #define MP3_PORT PORTB
; #define MP3_PIN PINB
; #define MP3_CMD_CS BIT(0)
; #define MP3_DATA_CS BIT(3)
; #define MP3_DATA_REQ BIT(2)
; #define MP3_DATA_REST BIT(1)
; void delay_Nus(unsigned int n)
; {
.dbline 21
; unsigned char b;
; for (b = 1; b<n; b++)
ldi R20,1
xjmp L5
L2:
.dbline 22
L3:
.dbline 21
inc R20
L5:
.dbline 21
mov R2,R20
clr R3
cp R2,R16
cpc R3,R17
brlo L2
.dbline -2
L1:
xcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r b 20 c
.dbsym r n 16 i
.dbend
.dbfunc e spi_init _spi_init fV
.even
_spi_init::
.dbline -1
.dbline 27
; ;
; }
; //SPI initialize
; // clock rate: 500000hz
; void spi_init(void)
; {
.dbline 28
; DDRB=0xBF; //SI输入,SO,SCK,SS输出
ldi R24,191
out 0x17,R24
.dbline 29
; SPCR = 0x53; //setup SPI
ldi R24,83
out 0xd,R24
.dbline 30
; SPSR = 0x00; //setup SPI
clr R2
out 0xe,R2
.dbline -2
L6:
.dbline 0 ; func end
ret
.dbend
.dbfunc e Write_Byte_SPI _Write_Byte_SPI fV
; byte -> R16
.even
_Write_Byte_SPI::
.dbline -1
.dbline 33
; }
; void Write_Byte_SPI(unsigned char byte)
; {
.dbline 34
; SPDR = byte;
out 0xf,R16
L8:
.dbline 35
L9:
.dbline 35
; while (!(SPSR & (1<<SPIF)));
sbis 0xe,7
rjmp L8
.dbline -2
L7:
.dbline 0 ; func end
ret
.dbsym r byte 16 c
.dbend
.dbfunc e Read_Byte_SPI _Read_Byte_SPI fc
.even
_Read_Byte_SPI::
.dbline -1
.dbline 38
; }
; unsigned char Read_Byte_SPI(void)
; {
.dbline 39
; SPDR = 0xFF;
ldi R24,255
out 0xf,R24
L12:
.dbline 40
L13:
.dbline 40
; while (!(SPSR &(1<<SPIF)));
sbis 0xe,7
rjmp L12
.dbline 41
; return SPDR;
in R16,0xf
.dbline -2
L11:
.dbline 0 ; func end
ret
.dbend
.dbfunc e mp3_port_init _mp3_port_init fV
.even
_mp3_port_init::
.dbline -1
.dbline 44
; }
; void mp3_port_init()
; {
.dbline 45
; spi_init();
xcall _spi_init
.dbline 46
; MP3_DDR|=MP3_DATA_CS |MP3_CMD_CS|MP3_DATA_REST;
in R24,0x17
ori R24,11
out 0x17,R24
.dbline 47
; MP3_DDR&=~MP3_DATA_REQ;
cbi 0x17,2
.dbline 48
; MP3_PORT|=MP3_DATA_CS |MP3_CMD_CS|MP3_DATA_REST;
in R24,0x18
ori R24,11
out 0x18,R24
.dbline -2
L15:
.dbline 0 ; func end
ret
.dbend
.dbfunc e vs1011_cmd_write _vs1011_cmd_write fV
; data -> R20,R21
; address -> R22
.even
_vs1011_cmd_write::
xcall push_gset2
movw R20,R18
mov R22,R16
.dbline -1
.dbline 52
; //MP3_PORT&=~MP3_DATA_REST;
; }
; void vs1011_cmd_write(uchar address,uint data)
; {
.dbline 53
; MP3_PORT|=MP3_DATA_CS; //MP3_DATA_CS=1;
sbi 0x18,3
.dbline 54
; MP3_PORT&=~MP3_CMD_CS; //MP3_CMD_CS=0;
cbi 0x18,0
.dbline 55
; Write_Byte_SPI(0x02); //VS1011的写命令
ldi R16,2
xcall _Write_Byte_SPI
.dbline 57
; //delay_nus(20);
; Write_Byte_SPI(address); //地址
mov R16,R22
xcall _Write_Byte_SPI
.dbline 58
; Write_Byte_SPI(data>>8);
movw R16,R20
mov R16,R17
clr R17
xcall _Write_Byte_SPI
.dbline 59
; Write_Byte_SPI(data);
mov R16,R20
xcall _Write_Byte_SPI
.dbline 61
; //delay_nus(200);
; MP3_PORT|=MP3_CMD_CS; //MP3_CMD_CS=1;
sbi 0x18,0
.dbline -2
L16:
xcall pop_gset2
.dbline 0 ; func end
ret
.dbsym r data 20 i
.dbsym r address 22 c
.dbend
.dbfunc e vs1011_data_write _vs1011_data_write fV
; data -> R20
.even
_vs1011_data_write::
xcall push_gset1
mov R20,R16
.dbline -1
.dbline 65
; }
;
; void vs1011_data_write(uchar data)
; {
.dbline 66
; MP3_PORT&=~MP3_DATA_CS; //MP3_DATA_CS=0;
cbi 0x18,3
.dbline 67
; Write_Byte_SPI(data);
mov R16,R20
xcall _Write_Byte_SPI
.dbline 68
; MP3_PORT|=MP3_DATA_CS; //MP3_DATA_CS=1;
sbi 0x18,3
.dbline 69
; MP3_PORT|=MP3_CMD_CS; //MP3_CMD_CS=1;
sbi 0x18,0
.dbline -2
L17:
xcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r data 20 c
.dbend
.dbfunc e vs1011_read _vs1011_read fi
; temp1 -> R22
; temp -> R20,R21
; address -> R10
.even
_vs1011_read::
xcall push_gset3
mov R10,R16
.dbline -1
.dbline 73
; }
;
; uint vs1011_read(uchar address)
; {
.dbline 74
; uchar temp1=0;
clr R22
.dbline 75
; uint temp=0;
clr R20
clr R21
.dbline 76
; MP3_PORT|=MP3_DATA_CS; //MP3_DATA_CS=1;
sbi 0x18,3
.dbline 77
; MP3_PORT&=~MP3_CMD_CS; //MP3_CMD_CS=0;
cbi 0x18,0
.dbline 78
; Write_Byte_SPI(0x03); //VS1011的读命令
ldi R16,3
xcall _Write_Byte_SPI
.dbline 80
; //delay_nus(20);
; Write_Byte_SPI(address); //地址
mov R16,R10
xcall _Write_Byte_SPI
.dbline 81
; temp=Read_Byte_SPI();
xcall _Read_Byte_SPI
mov R20,R16
clr R21
.dbline 82
; temp=temp<<8;
mov R21,R20
clr R20
.dbline 83
; temp1=Read_Byte_SPI();
xcall _Read_Byte_SPI
mov R22,R16
.dbline 84
; temp=temp|temp1;
mov R2,R22
clr R3
or R20,R2
or R21,R3
.dbline 85
; MP3_PORT|=MP3_CMD_CS; //MP3_CMD_CS=1;
sbi 0x18,0
.dbline 86
; return temp;
movw R16,R20
.dbline -2
L18:
xcall pop_gset3
.dbline 0 ; func end
ret
.dbsym r temp1 22 c
.dbsym r temp 20 i
.dbsym r address 10 c
.dbend
.dbfunc e vs1011_init _vs1011_init fV
.even
_vs1011_init::
.dbline -1
.dbline 91
;
; }
;
; void vs1011_init(void)
; {
.dbline 93
;
; delay_Nus(50);
ldi R16,50
ldi R17,0
xcall _delay_Nus
.dbline 94
; vs1011_cmd_write(0x00,0x0800); //NEW MODE
ldi R18,2048
ldi R19,8
clr R16
xcall _vs1011_cmd_write
.dbline 95
; vs1011_cmd_write(0x02,0X75); //BASS
ldi R18,117
ldi R19,0
ldi R16,2
xcall _vs1011_cmd_write
.dbline 96
; vs1011_cmd_write(0x03,0X9800); //CLOCK F
ldi R18,38912
ldi R19,152
ldi R16,3
xcall _vs1011_cmd_write
.dbline 97
; vs1011_cmd_write(0x0b,0X3030); //VOLUME
ldi R18,12336
ldi R19,48
ldi R16,11
xcall _vs1011_cmd_write
.dbline -2
L19:
.dbline 0 ; func end
ret
.dbend
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -