?? sd.s
字號:
mov R2,R22
clr R3
subi R22,255 ; addi 1
ldi R24,50
cp R24,R2
brsh L40
.dbline 138
; {
.dbline 139
; return 1;
ldi R16,1
xjmp L27
L40:
.dbline 141
L38:
.dbline 133
movw R16,R28
xcall _Write_Command_SD1
cpi R16,1
brne L37
.dbline 144
; }
; }
;
; //Send the 2nd command
; retry=0;
clr R22
.dbline 145
; CMD[0]=0x41;
ldi R24,65
std y+0,R24
.dbline 146
; CMD[5]=0xFF;
ldi R24,255
std y+5,R24
xjmp L44
L43:
.dbline 149
;
; while(Write_Command_SD1(CMD)!=0)
; {
.dbline 150
; Delay_ms(10);
ldi R16,10
ldi R17,0
xcall _Delay_ms
.dbline 151
; if (retry++>50)
mov R2,R22
clr R3
subi R22,255 ; addi 1
ldi R24,50
cp R24,R2
brsh L46
.dbline 152
; {
.dbline 153
; return 2;
ldi R16,2
xjmp L27
L46:
.dbline 155
L44:
.dbline 148
movw R16,R28
xcall _Write_Command_SD1
tst R16
brne L43
.dbline 158
; }
; }
;
; //Set the SPI bus to full speed 8M/2
; SPCR&=~((1<<SPR0)|(1<<SPR1));
in R24,0xd
andi R24,252
out 0xd,R24
.dbline 159
; SPSR|=(1<<SPI2X);
sbi 0xe,0
.dbline 163
;
; //Raise Chip Select
;
; SD_Disable();
sbi 0x18,4
.dbline 163
.dbline 164
; asm("sei");
sei
.dbline 165
; return 0;
clr R16
.dbline -2
L27:
adiw R28,6
xcall pop_gset3
.dbline 0 ; func end
ret
.dbsym r b 10 c
.dbsym r a 20 c
.dbsym r retry 22 c
.dbsym l CMD 0 A[6:6]c
.dbend
.dbfunc e SD_set_length _SD_set_length fc
; retry -> R20
; length -> R22,R23
.even
_SD_set_length::
xcall push_gset2
movw R22,R16
sbiw R28,2
.dbline -1
.dbline 170
; }
;
; //=======================================================================
; uint8 SD_set_length(uint16 length)
; {
xjmp L50
L49:
.dbline 175
; uint8 retry;
; //Command to set the block length;
;
; while(Write_Command_SD(0x50,length)!=0)
; {
.dbline 176
; if (retry++>10)
mov R2,R20
clr R3
subi R20,255 ; addi 1
ldi R24,10
cp R24,R2
brsh L52
.dbline 177
; {
.dbline 178
; return 1;
ldi R16,1
xjmp L48
L52:
.dbline 180
L50:
.dbline 174
movw R2,R22
clr R4
clr R5
std y+0,R4
std y+1,R5
movw R18,R2
ldi R16,80
xcall _Write_Command_SD
tst R16
brne L49
.dbline 181
; }
; }
; SD_Disable();
sbi 0x18,4
.dbline 181
.dbline 182
; return 0;
clr R16
.dbline -2
L48:
adiw R28,2
xcall pop_gset2
.dbline 0 ; func end
ret
.dbsym r retry 20 c
.dbsym r length 22 i
.dbend
.dbfunc e SD_start_read _SD_start_read fc
; retry -> R20
; addr -> y+4
.even
_SD_start_read::
xcall push_arg4
xcall push_gset1
sbiw R28,2
.dbline -1
.dbline 187
; }
;
; //=======================================================================
; uint8 SD_start_read(uint32 addr)
; {
xjmp L56
L55:
.dbline 191
; uint8 retry;
; // Send the read command
; while(Write_Command_SD(0x51,addr<<9)!=0)
; {
.dbline 192
; if (retry++>10)
mov R2,R20
clr R3
subi R20,255 ; addi 1
ldi R24,10
cp R24,R2
brsh L58
.dbline 193
; {
.dbline 194
; return 1;
ldi R16,1
xjmp L54
L58:
.dbline 196
L56:
.dbline 190
ldi R24,9
ldi R25,0
movw R30,R28
ldd R2,z+4
ldd R3,z+5
ldd R4,z+6
ldd R5,z+7
st -y,R24
movw R16,R2
movw R18,R4
xcall lsl32
std y+0,R18
std y+1,R19
movw R18,R16
ldi R16,81
xcall _Write_Command_SD
tst R16
brne L55
L60:
.dbline 199
L61:
.dbline 199
; }
; }
; //SD_Enable();
; //Send the start byte
; while(Read_Byte_SD()!=0xfe);
xcall _Read_Byte_SD
cpi R16,254
brne L60
.dbline 201
;
; SD_Disable();
sbi 0x18,4
.dbline 201
.dbline 202
; return 0; //open successfully!
clr R16
.dbline -2
L54:
adiw R28,2
xcall pop_gset1
adiw R28,4
.dbline 0 ; func end
ret
.dbsym r retry 20 c
.dbsym l addr 4 l
.dbend
.dbfunc e SD_get_date _SD_get_date fV
; a -> R20,R21
; Number -> R22,R23
; Buffer -> R10,R11
.even
_SD_get_date::
xcall push_gset3
movw R22,R18
movw R10,R16
.dbline -1
.dbline 207
; }
;
; //=======================================================================
; void SD_get_date(uint8 *Buffer,uint16 Number)
; {
.dbline 209
; uint16 a;
; SD_Enable();
cbi 0x18,4
.dbline 209
.dbline 211
;
; for(a=0;a<Number;a++)
clr R20
clr R21
xjmp L67
L64:
.dbline 212
.dbline 213
xcall _Read_Byte_SD
movw R30,R10
st Z+,R16
movw R10,R30
.dbline 215
L65:
.dbline 211
subi R20,255 ; offset = 1
sbci R21,255
L67:
.dbline 211
cp R20,R22
cpc R21,R23
brlo L64
.dbline 216
; {
; *Buffer++=Read_Byte_SD();
;
; }
; SD_Disable(); // Set SD_Chip_Select to high
sbi 0x18,4
.dbline 216
.dbline -2
L63:
xcall pop_gset3
.dbline 0 ; func end
ret
.dbsym r a 20 i
.dbsym r Number 22 i
.dbsym r Buffer 10 pc
.dbend
.dbfunc e SD_read_sector2 _SD_read_sector2 fc
; i -> <dead>
; retry -> R20
; a -> R22,R23
; Bytes -> R10,R11
; Buffer -> R12,R13
; addr -> y+10
.even
_SD_read_sector2::
xcall push_arg4
xcall push_gset4
sbiw R28,2
ldd R12,y+14
ldd R13,y+15
ldd R10,y+16
ldd R11,y+17
.dbline -1
.dbline 221
; }
;
; //=======================================================================
; uint8 SD_read_sector2(uint32 addr,uint8*Buffer,uint16 Bytes)
; {
.dbline 224
; uint8 i;
; uint16 a;
; uint8 retry=0;
clr R20
.dbline 226
;
; if(SD_set_length(Bytes))
movw R16,R10
xcall _SD_set_length
tst R16
breq L72
.dbline 227
; {
.dbline 228
; return 1;
ldi R16,1
xjmp L68
L71:
.dbline 233
; }
;
; // Send the read command
; while(Write_Command_SD(0x51,addr)!=0)
; {
.dbline 234
; if (retry++>10)
mov R2,R20
clr R3
subi R20,255 ; addi 1
ldi R24,10
cp R24,R2
brsh L74
.dbline 235
; {
.dbline 236
; return 2;
ldi R16,2
xjmp L68
L74:
.dbline 238
L72:
.dbline 232
movw R30,R28
ldd R2,z+10
ldd R3,z+11
ldd R4,z+12
ldd R5,z+13
std y+0,R4
std y+1,R5
movw R18,R2
ldi R16,81
xcall _Write_Command_SD
tst R16
brne L71
L76:
.dbline 244
L77:
.dbline 244
; }
; }
;
; // Raise chip select
;
; //SD_Enable();
; //receive the start byte
; while(Read_Byte_SD()!=0xfe);
xcall _Read_Byte_SD
cpi R16,254
brne L76
.dbline 247
;
; //Read off all the bytes in the block
; for(a=0;a<Bytes;a++)
clr R22
clr R23
xjmp L82
L79:
.dbline 248
.dbline 249
xcall _Read_Byte_SD
movw R30,R12
st Z+,R16
movw R12,R30
.dbline 250
L80:
.dbline 247
subi R22,255 ; offset = 1
sbci R23,255
L82:
.dbline 247
cp R22,R10
cpc R23,R11
brlo L79
.dbline 252
; {
; *Buffer++=Read_Byte_SD();
; }
; //Read CRC byte
xcall _Read_Byte_SD
.dbline 253
; Read_Byte_SD();
xcall _Read_Byte_SD
.dbline 255
;
; SD_set_length(512);
ldi R16,512
ldi R17,2
xcall _SD_set_length
.dbline 257
; // Set SD_Chip_Select to high
; SD_Disable();
sbi 0x18,4
.dbline 257
.dbline 259
;
; return 0;
clr R16
.dbline -2
L68:
adiw R28,2
xcall pop_gset4
adiw R28,4
.dbline 0 ; func end
ret
.dbsym l i 3 c
.dbsym r retry 20 c
.dbsym r a 22 i
.dbsym r Bytes 10 i
.dbsym r Buffer 12 pc
.dbsym l addr 10 l
.dbend
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -