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

📄 sd.s

📁 基于ATmega64的MP3程序
💻 S
📖 第 1 页 / 共 2 页
字号:
	.module SD.c
	.area text(rom, con, rel)
	.dbfile D:\TDDownload\MP3BOA~1.8\SD.c
	.dbfunc e Read_Byte_SD _Read_Byte_SD fc
	.even
_Read_Byte_SD::
	.dbline -1
	.dbline 13
; //ICC-AVR application builder : 2005-11-12 17:11:59
; // Target : M16
; // Crystal: 8.0000Mhz
; // copyright:鲁军波(endylu)
; // www.shop34612283.taobao.com
; // www.adembed.com
; #include <iom16v.h>
; #include <macros.h>
; #include "main.h"
; 
; //=======================================================================
; uint8 Read_Byte_SD(void) 
; { 
	.dbline 15
;  //char Byte; 
;  SPDR=0xff; 
	ldi R24,255
	out 0xf,R24
L2:
	.dbline 16
L3:
	.dbline 16
;  while(!(SPSR&(1<<SPIF)));
	sbis 0xe,7
	rjmp L2
	.dbline 19
;  
;  //Byte=SPDR;
;  return(SPDR); 
	in R16,0xf
	.dbline -2
L1:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e Write_Byte_SD _Write_Byte_SD fV
;           Byte -> R16
	.even
_Write_Byte_SD::
	.dbline -1
	.dbline 24
; }
; 
; //=======================================================================
; void Write_Byte_SD(uint8 Byte) 
; { 
	.dbline 25
;  SPDR=Byte; 
	out 0xf,R16
L6:
	.dbline 26
L7:
	.dbline 26
;  while(!(SPSR&(1<<SPIF)));
	sbis 0xe,7
	rjmp L6
	.dbline -2
L5:
	.dbline 0 ; func end
	ret
	.dbsym r Byte 16 c
	.dbend
	.dbfunc e Write_Command_SD1 _Write_Command_SD1 fc
;        Timeout -> R20
;              a -> R22
;            tmp -> R10
;            CMD -> R12,R13
	.even
_Write_Command_SD1::
	xcall push_gset4
	movw R12,R16
	.dbline -1
	.dbline 31
; } 
; 
; //=======================================================================
; uint8 Write_Command_SD1(uint8*CMD) 
; { 
	.dbline 33
;  uint8 a; 
;  uint8 tmp=0xff; 
	ldi R24,255
	mov R10,R24
	.dbline 34
;  uint8 Timeout=0; 
	clr R20
	.dbline 37
; 
;  // Raise chip select 
;  SD_Disable(); 
	sbi 0x18,4
	.dbline 37
	.dbline 40
; 
;  // Send an 8 bit pulse 
;  Write_Byte_SD(0xFF); 
	ldi R16,255
	xcall _Write_Byte_SD
	.dbline 43
;  
;  // Lower chip select 
;  SD_Enable(); 
	cbi 0x18,4
	.dbline 43
	.dbline 46
; 
;  //Send the 6 byte command 
;  for(a=0;a<0x06;a++) 
	clr R22
	xjmp L13
L10:
	.dbline 47
	.dbline 48
	movw R30,R12
	ld R16,Z+
	movw R12,R30
	xcall _Write_Byte_SD
	.dbline 49
L11:
	.dbline 46
	inc R22
L13:
	.dbline 46
	cpi R22,6
	brlo L10
	xjmp L15
L14:
	.dbline 53
;     {
;      Write_Byte_SD(*CMD++); 
;     } 
; 
;  //Wait for the response 
;  while(tmp==0xff)
;       {
	.dbline 54
;        tmp=Read_Byte_SD(); 
	xcall _Read_Byte_SD
	mov R10,R16
	.dbline 55
;        if(Timeout++>100) 
	mov R2,R20
	clr R3
	subi R20,255    ; addi 1
	ldi R24,100
	cp R24,R2
	brsh L17
	.dbline 56
;          { 
	.dbline 57
;           break; 
	xjmp L16
L17:
	.dbline 59
L15:
	.dbline 52
	mov R24,R10
	cpi R24,255
	breq L14
L16:
	.dbline 62
;          } 
;       } 
;  //SD_Disable(); 
;  //for some reason we need to delay  10here 
;  return(tmp); 
	mov R16,R10
	.dbline -2
L9:
	xcall pop_gset4
	.dbline 0 ; func end
	ret
	.dbsym r Timeout 20 c
	.dbsym r a 22 c
	.dbsym r tmp 10 c
	.dbsym r CMD 12 pc
	.dbend
	.dbfunc e Write_Command_SD _Write_Command_SD fc
;        Timeout -> R20
;            tmp -> R22
;        address -> y+8
;            CMD -> R22
	.even
_Write_Command_SD::
	st -y,r19
	st -y,r18
	xcall push_gset4
	mov R22,R16
	.dbline -1
	.dbline 67
; }
; 
; //=======================================================================
; uint8 Write_Command_SD(uint8 CMD,uint32 address) 
; { 
	.dbline 70
;  
;  uint8 tmp; 
;  uint8 Timeout=0; 
	clr R20
	.dbline 73
;  
;  // Raise chip select 
;  SD_Disable(); 
	sbi 0x18,4
	.dbline 73
	.dbline 76
; 
;  // Send an 8 bit pulse 
;  Write_Byte_SD(0xFF); 
	ldi R16,255
	xcall _Write_Byte_SD
	.dbline 79
;  
;  // Lower chip select 
;  SD_Enable(); 
	cbi 0x18,4
	.dbline 79
	.dbline 81
;  //Send the 6 byte command  
;   Write_Byte_SD(CMD);
	mov R16,R22
	xcall _Write_Byte_SD
	.dbline 82
;   Write_Byte_SD(address>>24);
	ldi R24,24
	ldi R25,0
	movw R30,R28
	ldd R2,z+8
	ldd R3,z+9
	ldd R4,z+10
	ldd R5,z+11
	st -y,R24
	movw R16,R2
	movw R18,R4
	xcall lsr32
	xcall _Write_Byte_SD
	.dbline 83
;   Write_Byte_SD(address>>16);
	movw R30,R28
	ldd R2,z+8
	ldd R3,z+9
	ldd R4,z+10
	ldd R5,z+11
	movw R2,R4
	clr R4
	clr R5
	mov R16,R2
	xcall _Write_Byte_SD
	.dbline 84
;   Write_Byte_SD(address>>8);
	ldi R24,8
	ldi R25,0
	movw R30,R28
	ldd R2,z+8
	ldd R3,z+9
	ldd R4,z+10
	ldd R5,z+11
	st -y,R24
	movw R16,R2
	movw R18,R4
	xcall lsr32
	xcall _Write_Byte_SD
	.dbline 85
;   Write_Byte_SD(address);
	movw R30,R28
	ldd R16,z+8
	xcall _Write_Byte_SD
	.dbline 86
;   Write_Byte_SD(0xff);
	ldi R16,255
	xcall _Write_Byte_SD
	.dbline 90
;   
; 
;  //Wait for the response 
;  tmp=Read_Byte_SD();
	xcall _Read_Byte_SD
	mov R22,R16
	xjmp L21
L20:
	.dbline 92
	.dbline 93
	xcall _Read_Byte_SD
	mov R22,R16
	.dbline 94
L21:
	.dbline 91
;  while((tmp==0xff)&(Timeout++<8)) 
	cpi R22,255
	brne L23
	ldi R24,1
	ldi R25,0
	movw R12,R24
	xjmp L24
L23:
	clr R12
	clr R13
L24:
	mov R2,R20
	clr R3
	subi R20,255    ; addi 1
	mov R24,R2
	cpi R24,8
	brsh L25
	ldi R24,1
	ldi R25,0
	movw R10,R24
	xjmp L26
L25:
	clr R10
	clr R11
L26:
	movw R2,R12
	and R2,R10
	and R3,R11
	tst R2
	brne L20
	tst R3
	brne L20
X0:
	.dbline 96
;       {
;        tmp=Read_Byte_SD();  
;       } 
;  //SD_Disable(); 
;  return(tmp); 
	mov R16,R22
	.dbline -2
L19:
	xcall pop_gset4
	adiw R28,2
	.dbline 0 ; func end
	ret
	.dbsym r Timeout 20 c
	.dbsym r tmp 22 c
	.dbsym l address 8 l
	.dbsym r CMD 22 c
	.dbend
	.area lit(rom, con, rel)
L28:
	.byte 64,0
	.byte 0,0
	.byte 0,149
	.area text(rom, con, rel)
	.dbfile D:\TDDownload\MP3BOA~1.8\SD.c
	.dbfunc e SDInit _SDInit fc
;              b -> R10
;              a -> R20
;          retry -> R22
;            CMD -> y+0
	.even
_SDInit::
	xcall push_gset3
	sbiw R28,6
	.dbline -1
	.dbline 101
; }
; 
; //=======================================================================
; uint8 SDInit(void)
; { 
	.dbline 103
;  uint8 a,b,retry; 
;  uint8 CMD[]={0x40,0x00,0x00,0x00,0x00,0x95}; 
	ldi R24,<L28
	ldi R25,>L28
	movw R30,R28
	ldi R16,6
	ldi R17,0
	st -y,R31
	st -y,R30
	st -y,R25
	st -y,R24
	xcall asgncblk
	.dbline 105
;  
;  asm("cli"); //clear all interrupt.
	cli
	.dbline 108
;  // Set certain pins to inputs and others to outputs 
;  // Only SPI_DI (data in) is an input 
;  SD_Direction_REG&=~(1<<SPI_DI); 
	cbi 0x17,6
	.dbline 109
;  SD_Direction_REG|=(1<<SPI_Clock); 
	sbi 0x17,7
	.dbline 110
;  SD_Direction_REG|=(1<<SPI_DO); 
	sbi 0x17,5
	.dbline 111
;  SD_Direction_REG|=(1<<SD_Chip_Select); 
	sbi 0x17,4
	.dbline 112
;  SD_Write|=(1<<SD_Chip_Select); 
	sbi 0x18,4
	.dbline 113
;  SD_Write|=(1<<SPI_DI); 
	sbi 0x18,6
	.dbline 116
; 
;  //We need to wait for the SD_Direction_REG to be ready 
;  for(a=0;a<200;a++) 
	clr R20
	xjmp L32
L29:
	.dbline 117
	.dbline 118
	nop
	.dbline 119
L30:
	.dbline 116
	inc R20
L32:
	.dbline 116
	cpi R20,200
	brlo L29
	.dbline 119
;     {
;      nop();
;     }; 
	.dbline 121
;  //Enable SPI in Master Mode with IDLE low and clock at 8M/128 
; SPCR=(1<<SPE)|(1<<MSTR)|(1<<SPR0)|(1<<SPR1); 
	ldi R24,83
	out 0xd,R24
	.dbline 122
; SPSR&=~(1<<SPI2X); 
	cbi 0xe,0
	.dbline 125
;   
;  // We need to give the card about a Hundred cycles to load 
;  for (b=0;b<0x0f;++b) 
	clr R10
	xjmp L36
L33:
	.dbline 126
	.dbline 127
	ldi R16,255
	xcall _Write_Byte_SD
	.dbline 128
L34:
	.dbline 125
	inc R10
L36:
	.dbline 125
	mov R24,R10
	cpi R24,15
	brlo L33
	.dbline 131
;      {
;       Write_Byte_SD(0xff); 
;      } 
; 
;  //Send the initialization commands to the card 
;  retry=0; 
	clr R22
	xjmp L38
L37:
	.dbline 134
;   
;  while(Write_Command_SD1(CMD)!=0X01)
;  {
	.dbline 135
;   Delay_ms(10);              //很重要,要不然就要REST才可以
	ldi R16,10
	ldi R17,0
	xcall _Delay_ms
	.dbline 137
;  //fail and return 
;  if(retry++>50) 

⌨️ 快捷键说明

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