⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sd.s

📁 绝对好用的M64-SD卡MP3程序
💻 S
字号:
	.module sd.c
	.area data(ram, con, rel)
_reading::
	.blkb 1
	.area idata
	.byte 0
	.area data(ram, con, rel)
	.dbfile E:\V3U~1\sd\M64-SD卡MP3程序\sd.c
	.dbsym e reading _reading c
_a::
	.blkb 1
	.area idata
	.byte 0
	.area data(ram, con, rel)
	.dbfile E:\V3U~1\sd\M64-SD卡MP3程序\sd.c
	.dbsym e a _a c
_pointer::
	.blkb 1
	.area idata
	.byte 0
	.area data(ram, con, rel)
	.dbfile E:\V3U~1\sd\M64-SD卡MP3程序\sd.c
	.dbsym e pointer _pointer c
	.area text(rom, con, rel)
	.dbfile E:\V3U~1\sd\M64-SD卡MP3程序\sd.c
	.dbfunc e sd_port_init _sd_port_init fV
	.even
_sd_port_init::
	.dbline -1
	.dbline 18
; /************************************************************/
; /*		         SD Code for   M32L					        */
; /*				   By   pasyong								*/
; /*				   2006-4									*/
; /*				   Base ICC6.31A					        */
; /************************************************************/
; #include <iom64v.h>
; #include <macros.h>
; #include "1011.h"
; #include "delay.h"
; #define uchar unsigned char
; #define uint unsigned int
; #define MMC_CS_PIN     BIT(0)    //PORTB.0 
; #define MMC_PORT       PORTB    
; 
;  uchar reading=0,a=0,pointer=0;
; void sd_port_init()
; {
	.dbline 19
; MMC_PORT|=MMC_CS_PIN;
	sbi 0x18,0
	.dbline -2
L1:
	.dbline 0 ; func end
	ret
	.dbend
	.area data(ram, con, rel)
	.dbfile E:\V3U~1\sd\M64-SD卡MP3程序\sd.c
_i::
	.blkb 2
	.area idata
	.word 0
	.area data(ram, con, rel)
	.dbfile E:\V3U~1\sd\M64-SD卡MP3程序\sd.c
	.dbsym e i _i i
	.area text(rom, con, rel)
	.dbfile E:\V3U~1\sd\M64-SD卡MP3程序\sd.c
	.dbfunc e SD_Write_Command _SD_Write_Command fc
;          retry -> R12
;            tmp -> R10
;            arg -> y+10
;            cmd -> R14
	.even
_SD_Write_Command::
	st -y,r19
	st -y,r18
	xcall push_gset5
	mov R14,R16
	.dbline -1
	.dbline 29
; }
; uchar BUFFER[512];                   //扇区缓冲区
; uint i=0;
; 
; //****************************************************************************
; //Send a Command to MMC/SD-Card
; //Return: the second byte of response register of MMC/SD-Card
; //****************************************************************************
; uchar SD_Write_Command(uchar cmd,unsigned long arg)
; {
	.dbline 31
;    uchar tmp;
;    uchar retry=0;
	clr R12
	.dbline 35
;    
;    //MMC_PORT|=MMC_CS_PIN;       //SD卡关闭   
;    //send 8 Clock Impulse
;    Write_Byte_SPI(0xFF);
	ldi R16,255
	xcall _Write_Byte_SPI
	.dbline 38
;    
;    //set MMC_Chip_Select to low (MMC/SD-Card active)
;   MMC_PORT&=~MMC_CS_PIN;       //SD卡使能
	cbi 0x18,0
	.dbline 40
; 
;    Write_Byte_SPI(cmd|0x40);   //送头命令
	mov R16,R14
	ori R16,64
	xcall _Write_Byte_SPI
	.dbline 41
;    Write_Byte_SPI(arg>>24);
	ldi R24,24
	ldi R25,0
	movw R30,R28
	ldd R2,z+10
	ldd R3,z+11
	ldd R4,z+12
	ldd R5,z+13
	st -y,R24
	movw R16,R2
	movw R18,R4
	xcall lsr32
	xcall _Write_Byte_SPI
	.dbline 42
;    Write_Byte_SPI(arg>>16);     //send 6 Byte Command to MMC/SD-Card
	movw R30,R28
	ldd R2,z+10
	ldd R3,z+11
	ldd R4,z+12
	ldd R5,z+13
	movw R2,R4
	clr R4
	clr R5
	mov R16,R2
	xcall _Write_Byte_SPI
	.dbline 43
;    Write_Byte_SPI(arg>>8);
	ldi R24,8
	ldi R25,0
	movw R30,R28
	ldd R2,z+10
	ldd R3,z+11
	ldd R4,z+12
	ldd R5,z+13
	st -y,R24
	movw R16,R2
	movw R18,R4
	xcall lsr32
	xcall _Write_Byte_SPI
	.dbline 44
;    Write_Byte_SPI(arg&0xff);
	ldi R20,255
	ldi R21,0
	ldi R22,0
	ldi R23,0
	movw R30,R28
	ldd R2,z+10
	ldd R3,z+11
	ldd R4,z+12
	ldd R5,z+13
	and R2,R20
	and R3,R21
	and R4,R22
	and R5,R23
	mov R16,R2
	xcall _Write_Byte_SPI
	.dbline 45
;    Write_Byte_SPI(0x95);       //仅仅对RESET有效的CRC效验码
	ldi R16,149
	xcall _Write_Byte_SPI
L3:
	.dbline 50
;   
;    //get 8 bit response
;    //Read_Byte_MMC(); //read the first byte,ignore it. 
;    do 
;    {  //Only last 8 bit is used here.Read it out. 
	.dbline 51
;       tmp = Read_Byte_SPI();
	xcall _Read_Byte_SPI
	mov R10,R16
	.dbline 52
;       retry++;
	inc R12
	.dbline 53
;    }
L4:
	.dbline 54
;    while((tmp==0xff)&&(retry<100));  //当没有收到有效的命令的时候
	mov R24,R10
	cpi R24,255
	brne L6
	mov R24,R12
	cpi R24,100
	brlo L3
L6:
	.dbline 56
;    
;    if(reading==0)
	lds R2,_reading
	tst R2
	brne L7
	.dbline 57
;    MMC_PORT|=MMC_CS_PIN;            //MMC_CS_PIN=1;
	sbi 0x18,0
	xjmp L8
L7:
	.dbline 58
;    else MMC_PORT&=~MMC_CS_PIN;      //MMC_CS_PIN=0;   
	cbi 0x18,0
L8:
	.dbline 59
;    return(tmp);
	mov R16,R10
	.dbline -2
L2:
	xcall pop_gset5
	adiw R28,2
	.dbline 0 ; func end
	ret
	.dbsym r retry 12 c
	.dbsym r tmp 10 c
	.dbsym l arg 10 l
	.dbsym r cmd 14 c
	.dbend
	.dbfunc e SD_Init _SD_Init fc
;              i -> R10
;           temp -> R12
;          retry -> R14
	.even
_SD_Init::
	xcall push_gset5
	sbiw R28,2
	.dbline -1
	.dbline 65
; }
; //****************************************************************************
; //SD卡初始化(SPI-MODE)
; //****************************************************************************
; uchar SD_Init(void)
; {  
	.dbline 68
;    uchar retry,temp;
;    uchar i;
;    MMC_PORT&=~MMC_CS_PIN;      //SD卡使能
	cbi 0x18,0
	.dbline 70
;   
;   delay_nus(250);  //Wait MMC/SD ready...
	ldi R16,250
	ldi R17,0
	xcall _delay_nus
	.dbline 71
;    for (i=0;i<0x0f;i++) 
	clr R10
	xjmp L13
L10:
	.dbline 72
	.dbline 73
	ldi R16,255
	xcall _Write_Byte_SPI
	.dbline 74
L11:
	.dbline 71
	inc R10
L13:
	.dbline 71
	mov R24,R10
	cpi R24,15
	brlo L10
	.dbline 76
;    {
;       Write_Byte_SPI(0xff); //send 74 clock at least!!!
;    }
;    //Send Command CMD0 to MMC/SD Card
;    retry=0;
	clr R14
L14:
	.dbline 79
;    
;    do
;    { //retry 200 times to send CMD0 command 
	.dbline 80
;      temp=SD_Write_Command(0,0);
	ldi R20,0
	ldi R21,0
	ldi R22,0
	ldi R23,0
	std y+0,R22
	std y+1,R23
	movw R18,R20
	clr R16
	xcall _SD_Write_Command
	mov R12,R16
	.dbline 81
;      retry++;
	inc R14
	.dbline 82
;      if(retry==100) 
	mov R24,R14
	cpi R24,100
	brne L17
	.dbline 83
;      { 
	.dbline 84
;       ;//CMD0 Error!
	.dbline 85
;      }
L17:
	.dbline 86
;    } 
L15:
	.dbline 87
;    while(temp!=1);  
	mov R24,R12
	cpi R24,1
	brne L14
	.dbline 90
;    
;    //Send Command CMD1 to MMC/SD-Card
;    retry=0;
	clr R14
L19:
	.dbline 92
;    do
;    { //retry 100 times to send CMD1 command 
	.dbline 93
;      temp=SD_Write_Command(1,0);
	ldi R20,0
	ldi R21,0
	ldi R22,0
	ldi R23,0
	std y+0,R22
	std y+1,R23
	movw R18,R20
	ldi R16,1
	xcall _SD_Write_Command
	mov R12,R16
	.dbline 94
;      retry++;
	inc R14
	.dbline 95
;      if(retry==100) 
	mov R24,R14
	cpi R24,100
	brne L22
	.dbline 96
;      { 
	.dbline 97
;      ;
	.dbline 98
;      }
L22:
	.dbline 99
;    } 
L20:
	.dbline 100
;    while(temp!=0); 
	tst R12
	brne L19
	.dbline 101
;    retry=0; 
	clr R14
	.dbline 102
;     SD_Write_Command(16,512);     //设置一次读写BLOCK的长度为512个字节
	ldi R20,0
	ldi R21,2
	ldi R22,0
	ldi R23,0
	std y+0,R22
	std y+1,R23
	movw R18,R20
	ldi R16,16
	xcall _SD_Write_Command
	.dbline 104
;   
;    MMC_PORT|=MMC_CS_PIN;   //MMC_CS_PIN=1;  //set MMC_Chip_Select to high 
	sbi 0x18,0
	.dbline 105
;    return(0); //All commands have been taken.
	clr R16
	.dbline -2
L9:
	adiw R28,2
	xcall pop_gset5
	.dbline 0 ; func end
	ret
	.dbsym r i 10 c
	.dbsym r temp 12 c
	.dbsym r retry 14 c
	.dbend
	.dbfunc e SD_Read_Block _SD_Read_Block fc
;           temp -> R20
;              i -> R22,R23
;        address -> y+6
	.even
_SD_Read_Block::
	xcall push_arg4
	xcall push_gset2
	sbiw R28,2
	.dbline -1
	.dbline 111
; } 
; //****************************************************************************
; //从SD卡读一个扇区  Return 0 if no Error.
; //****************************************************************************
; uchar SD_Read_Block(unsigned long address)
; {  
	.dbline 112
;    uchar temp=0;uint i=0;
	clr R20
	.dbline 112
	clr R22
	clr R23
	.dbline 113
;    reading=1; 
	ldi R24,1
	sts _reading,R24
	.dbline 114
;    temp=SD_Write_Command(17,address);     //读出RESPONSE     
	movw R30,R28
	ldd R2,z+6
	ldd R3,z+7
	ldd R4,z+8
	ldd R5,z+9
	std y+0,R4
	std y+1,R5
	movw R18,R2
	ldi R16,17
	xcall _SD_Write_Command
	mov R20,R16
L25:
	.dbline 116
	.dbline 116
	.dbline 116
L26:
	.dbline 115
;    while (Read_Byte_SPI()!= 0xfe)
	xcall _Read_Byte_SPI
	cpi R16,254
	brne L25
	.dbline 117
;    {;}  //直到读取到了数据的开始头0XFE,才继续
;    for(i=0; i<512; i++)
	clr R22
	clr R23
	xjmp L31
L28:
	.dbline 118
	.dbline 119
	xcall _Read_Byte_SPI
	ldi R24,<_BUFFER
	ldi R25,>_BUFFER
	movw R30,R22
	add R30,R24
	adc R31,R25
	std z+0,R16
	.dbline 120
L29:
	.dbline 117
	subi R22,255  ; offset = 1
	sbci R23,255
L31:
	.dbline 117
	cpi R22,0
	ldi R30,2
	cpc R23,R30
	brlo L28
	.dbline 121
; 	{
; 	BUFFER[i]=Read_Byte_SPI();
; 	}
;    Read_Byte_SPI();//CRC - Byte 
	xcall _Read_Byte_SPI
	.dbline 122
;    Read_Byte_SPI();//CRC - Byte
	xcall _Read_Byte_SPI
	.dbline 123
;    reading=0; 
	clr R2
	sts _reading,R2
	.dbline 124
;    MMC_PORT|=MMC_CS_PIN;        //关闭SD卡
	sbi 0x18,0
	.dbline 125
;    return(temp);
	mov R16,R20
	.dbline -2
L24:
	adiw R28,2
	xcall pop_gset2
	adiw R28,4
	.dbline 0 ; func end
	ret
	.dbsym r temp 20 c
	.dbsym r i 22 i
	.dbsym l address 6 l
	.dbend
	.area bss(ram, con, rel)
	.dbfile E:\V3U~1\sd\M64-SD卡MP3程序\sd.c
_BUFFER::
	.blkb 512
	.dbsym e BUFFER _BUFFER A[512:512]c

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -