📄 1011.s
字号:
.module _1011.c
.area text(rom, con, rel)
.dbfile E:\V3U~1\sd\M64-SD卡MP3程序\1011.c
.dbfunc e delay_nnus _delay_nnus fV
; b -> R20
; n -> R16,R17
.even
_delay_nnus::
xcall push_gset1
.dbline -1
.dbline 13
; #include <iom64v.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(4)
; #define MP3_DATA_REST BIT(5)
; #define MP3_DATA_REQ BIT(6)
; #define MP3_DATA_CS BIT(7)
; void delay_nnus(unsigned int n)
; {
.dbline 15
; unsigned char b;
; for (b = 1; b<n; b++)
ldi R20,1
xjmp L5
L2:
.dbline 16
L3:
.dbline 15
inc R20
L5:
.dbline 15
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 21
; ;
; }
;
; //SPI initialize
; void spi_init(void)
; {
.dbline 22
; DDRB = 0xBF; //SI输入,SO,SCK,SS输出
ldi R24,191
out 0x17,R24
.dbline 23
; SPCR = 0x51; //setup SPI
ldi R24,81
out 0xd,R24
.dbline 24
; SPSR = 0x00; //setup SPI
clr R2
out 0xe,R2
.dbline -2
L6:
.dbline 0 ; func end
ret
.dbend
.dbfunc e mp3_port_init _mp3_port_init fV
.even
_mp3_port_init::
.dbline -1
.dbline 27
; }
; void mp3_port_init()
; {
.dbline 28
; spi_init();
xcall _spi_init
.dbline 29
; MP3_DDR|=MP3_DATA_CS |MP3_CMD_CS|MP3_DATA_REST;
in R24,0x17
ori R24,176
out 0x17,R24
.dbline 30
; MP3_DDR&=~MP3_DATA_REQ;
cbi 0x17,6
.dbline 31
; MP3_PORT|=MP3_DATA_CS |MP3_CMD_CS|MP3_DATA_REST;
in R24,0x18
ori R24,176
out 0x18,R24
.dbline -2
L7:
.dbline 0 ; func end
ret
.dbend
.dbfunc e Write_Byte_SPI _Write_Byte_SPI fV
; byte -> R16
.even
_Write_Byte_SPI::
.dbline -1
.dbline 34
; }
; void Write_Byte_SPI(unsigned char byte)
; {
.dbline 35
; SPDR = byte;
out 0xf,R16
L9:
.dbline 36
L10:
.dbline 36
; while (!(SPSR & (1<<SPIF)));
sbis 0xe,7
rjmp L9
.dbline -2
L8:
.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 39
; }
; unsigned char Read_Byte_SPI(void)
; {
.dbline 40
; SPDR = 0xFF;
ldi R24,255
out 0xf,R24
L13:
.dbline 41
L14:
.dbline 41
; while (!(SPSR &(1<<SPIF)));
sbis 0xe,7
rjmp L13
.dbline 42
; return SPDR;
in R16,0xf
.dbline -2
L12:
.dbline 0 ; func end
ret
.dbend
.dbfunc e vs1003_cmd_write _vs1003_cmd_write fV
; data -> R20,R21
; address -> R22
.even
_vs1003_cmd_write::
xcall push_gset2
movw R20,R18
mov R22,R16
.dbline -1
.dbline 46
; }
;
; void vs1003_cmd_write(uchar address,uint data)
; {
.dbline 48
; //==============新增
; SPCR = 0x53; //
ldi R24,83
out 0xd,R24
.dbline 49
; SPSR = 0x00; //低速度spi
clr R2
out 0xe,R2
.dbline 51
; //==============
; MP3_PORT|=MP3_DATA_CS; //MP3_DATA_CS=1;
sbi 0x18,7
.dbline 52
; MP3_PORT&=~MP3_CMD_CS; //MP3_CMD_CS=0;
cbi 0x18,4
.dbline 53
; Write_Byte_SPI(0x02); //VS1011的写命令
ldi R16,2
xcall _Write_Byte_SPI
.dbline 54
; delay_nnus(20);
ldi R16,20
ldi R17,0
xcall _delay_nnus
.dbline 55
; Write_Byte_SPI(address); //地址
mov R16,R22
xcall _Write_Byte_SPI
.dbline 56
; Write_Byte_SPI(data>>8);
movw R16,R20
mov R16,R17
clr R17
xcall _Write_Byte_SPI
.dbline 57
; Write_Byte_SPI(data);
mov R16,R20
xcall _Write_Byte_SPI
.dbline 58
; delay_nnus(20);
ldi R16,20
ldi R17,0
xcall _delay_nnus
.dbline 59
; MP3_PORT|=MP3_CMD_CS; //MP3_CMD_CS=1;
sbi 0x18,4
.dbline 61
; //==============以下新增
; SPCR = 0x50; //
ldi R24,80
out 0xd,R24
.dbline 62
; SPSR = 0x01; //高速spi
ldi R24,1
out 0xe,R24
.dbline -2
L16:
xcall pop_gset2
.dbline 0 ; func end
ret
.dbsym r data 20 i
.dbsym r address 22 c
.dbend
.dbfunc e vs1003_data_write _vs1003_data_write fV
; data -> R20
.even
_vs1003_data_write::
xcall push_gset1
mov R20,R16
.dbline -1
.dbline 67
; //=========================
; }
;
; void vs1003_data_write(uchar data)
; {
.dbline 68
; MP3_PORT&=~MP3_DATA_CS; //MP3_DATA_CS=0;
cbi 0x18,7
.dbline 69
; Write_Byte_SPI(data);
mov R16,R20
xcall _Write_Byte_SPI
.dbline 70
; MP3_PORT|=MP3_DATA_CS; //MP3_DATA_CS=1;
sbi 0x18,7
.dbline 71
; MP3_PORT|=MP3_CMD_CS; //MP3_CMD_CS=1;
sbi 0x18,4
.dbline -2
L17:
xcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r data 20 c
.dbend
.dbfunc e vs1003_read _vs1003_read fi
; temp1 -> R22
; temp -> R20,R21
; address -> R10
.even
_vs1003_read::
xcall push_gset3
mov R10,R16
.dbline -1
.dbline 75
; }
;
; uint vs1003_read(uchar address)
; {
.dbline 76
; uchar temp1=0;
clr R22
.dbline 77
; uint temp=0;
clr R20
clr R21
.dbline 78
; MP3_PORT|=MP3_DATA_CS; //MP3_DATA_CS=1;
sbi 0x18,7
.dbline 79
; MP3_PORT&=~MP3_CMD_CS; //MP3_CMD_CS=0;
cbi 0x18,4
.dbline 80
; Write_Byte_SPI(0x03); //VS1011的读命令
ldi R16,3
xcall _Write_Byte_SPI
.dbline 81
; delay_nnus(30);
ldi R16,30
ldi R17,0
xcall _delay_nnus
.dbline 82
; Write_Byte_SPI(address); //地址
mov R16,R10
xcall _Write_Byte_SPI
.dbline 83
; temp=Read_Byte_SPI();
xcall _Read_Byte_SPI
mov R20,R16
clr R21
.dbline 84
; temp=temp<<8;
mov R21,R20
clr R20
.dbline 85
; temp1=Read_Byte_SPI();
xcall _Read_Byte_SPI
mov R22,R16
.dbline 86
; temp=temp|temp1;
mov R2,R22
clr R3
or R20,R2
or R21,R3
.dbline 87
; MP3_PORT|=MP3_CMD_CS; //MP3_CMD_CS=1;
sbi 0x18,4
.dbline 88
; 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 vs1003_init _vs1003_init fV
.even
_vs1003_init::
.dbline -1
.dbline 93
;
; }
;
; void vs1003_init(void)
; {
.dbline 94
; vs1003_cmd_write(0x0b,0X1010); //VOLUME
ldi R18,4112
ldi R19,16
ldi R16,11
xcall _vs1003_cmd_write
.dbline 95
; vs1003_cmd_write(0x00,0x0800); //NEW MODE
ldi R18,2048
ldi R19,8
clr R16
xcall _vs1003_cmd_write
.dbline 96
; vs1003_cmd_write(0x02,0X1fff); //BASS
ldi R18,8191
ldi R19,31
ldi R16,2
xcall _vs1003_cmd_write
.dbline 97
; vs1003_cmd_write(0x03,0X4000); //CLOCK F
ldi R18,16384
ldi R19,64
ldi R16,3
xcall _vs1003_cmd_write
.dbline 98
; vs1003_cmd_write(0x03,0X4000); //CLOCK F
ldi R18,16384
ldi R19,64
ldi R16,3
xcall _vs1003_cmd_write
.dbline -2
L19:
.dbline 0 ; func end
ret
.dbend
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -