📄 at45db041d.s
字号:
; //判断扇区保护寄存器内容
; for(i=0;i<8;i++)
clr R22
clr R23
xjmp L102
L99:
.dbline 344
; {
.dbline 345
; if(Sector_Protection_Register_for_Read[i]!=0) j++;
movw R24,R28
movw R30,R22
add R30,R24
adc R31,R25
ldd R2,z+0
tst R2
breq L103
X20:
.dbline 345
inc R20
L103:
.dbline 346
; }
L100:
.dbline 343
subi R22,255 ; offset = 1
sbci R23,255
L102:
.dbline 343
cpi R22,8
ldi R30,0
cpc R23,R30
brlo L99
X21:
.dbline 348
; //禁止扇区保护
; DF_Disable_Sector_Protection();
xcall _DF_Disable_Sector_Protection
.dbline 350
;
; return j;
mov R16,R20
.dbline -2
L96:
.dbline 0 ; func end
adiw R28,16
xjmp pop_xgsetF000
.dbsym l Sector_Protection_Register_for_Write 8 A[8:8]c
.dbsym r j 20 c
.dbsym l Sector_Protection_Register_for_Read 0 A[8:8]c
.dbsym r i 22 i
.dbend
.area lit(rom, con, rel)
L106:
.byte 0,0
.byte 0,0
.area text(rom, con, rel)
.dbfile E:\item\car\AT45DB041D\AT45DB041D.c
.dbfunc e DF_Program_Sector_Lockdown _DF_Program_Sector_Lockdown fV
; Sector_Lockdown_Command -> y+0
; i -> R20
; Sector_Addr -> y+5
.even
_DF_Program_Sector_Lockdown::
xcall push_arg4
st -y,R20
sbiw R28,4
.dbline -1
.dbline 359
; }
; /************************************************************
; *设置扇区锁(被锁后不能再次解锁)
; *被设置的扇区就只能读不能写
; *非一般情况不要使用(除非数据不用再改)
; *Sector_Addr :地址在哪个扇区中就会锁上那个扇区
; ************************************************************/
; void DF_Program_Sector_Lockdown(unsigned long Sector_Addr)
; {
.dbline 361
; //unsigned char Sector_Lockdown_Command=[4]={0x3D,0x2A,0x7F,0x30};//加锁操作码
; unsigned char Sector_Lockdown_Command[4]={0x00,0x00,0x00,0x00};//防止写到,这里乱写
ldi R24,<L106
ldi R25,>L106
movw R30,R28
ldi R16,4
ldi R17,0
st -y,R31
st -y,R30
st -y,R25
st -y,R24
xcall asgncblk
.dbline 364
; unsigned char i;
;
; DF_Check_Busy_State();
xcall _DF_Check_Busy_State
.dbline 365
; Enable_DFLASH();
xcall _Enable_DFLASH
.dbline 367
;
; for(i=0;i<4;i++)//write
clr R20
xjmp L110
L107:
.dbline 368
; {
.dbline 369
; SPI_Write_Byte(Sector_Lockdown_Command[i]);
movw R24,R28
mov R30,R20
clr R31
add R30,R24
adc R31,R25
ldd R16,z+0
xcall _SPI_Write_Byte
.dbline 370
; }
L108:
.dbline 367
inc R20
L110:
.dbline 367
cpi R20,4
brlo L107
X22:
.dbline 373
;
; //write address
; SPI_Write_Byte((unsigned char)(Sector_Addr>>16));
ldd R2,y+5
ldd R3,y+6
ldd R4,y+7
ldd R5,y+8
movw R2,R4
clr R4
clr R5
mov R16,R2
xcall _SPI_Write_Byte
.dbline 374
; SPI_Write_Byte((unsigned char)(Sector_Addr>>8));
ldi R24,8
ldi R25,0
ldd R16,y+5
ldd R17,y+6
ldd R18,y+7
ldd R19,y+8
st -y,R24
xcall lsr32
xcall _SPI_Write_Byte
.dbline 375
; SPI_Write_Byte((unsigned char)Sector_Addr);
ldd R16,y+5
xcall _SPI_Write_Byte
.dbline 377
;
; Disable_DFLASH();
xcall _Disable_DFLASH
.dbline -2
L105:
.dbline 0 ; func end
adiw R28,4
ld R20,y+
adiw R28,4
ret
.dbsym l Sector_Lockdown_Command 0 A[4:4]c
.dbsym r i 20 c
.dbsym l Sector_Addr 5 l
.dbend
.area lit(rom, con, rel)
L112:
.byte 53,0
.byte 0,0
.area text(rom, con, rel)
.dbfile E:\item\car\AT45DB041D\AT45DB041D.c
.dbfunc e DF_Read_Sector_Lockdown_Register _DF_Read_Sector_Lockdown_Register fV
; Read_Sector_Lockdown_Register -> y+0
; i -> R20
; Sector_Lockdown_Register -> R10,R11
.even
_DF_Read_Sector_Lockdown_Register::
xcall push_xgset300C
movw R10,R16
sbiw R28,4
.dbline -1
.dbline 385
; }
; /************************************************************
; *读取扇区加锁寄存器(返回8个扇区的加锁寄存器值)
; *如果有读到不为0的表示已被加锁
; *(0扇区的高四位为0也表示没加锁,其它扇区一定要全为O)
; ************************************************************/
; void DF_Read_Sector_Lockdown_Register(unsigned char *Sector_Lockdown_Register)
; {
.dbline 386
; unsigned char Read_Sector_Lockdown_Register[4]={0x35,0x00,0x00,0x00};
ldi R24,<L112
ldi R25,>L112
movw R30,R28
ldi R16,4
ldi R17,0
st -y,R31
st -y,R30
st -y,R25
st -y,R24
xcall asgncblk
.dbline 389
; unsigned char i;
;
; DF_Check_Busy_State();
xcall _DF_Check_Busy_State
.dbline 390
; Enable_DFLASH();
xcall _Enable_DFLASH
.dbline 392
;
; for(i=0;i<4;i++)//write
clr R20
xjmp L116
L113:
.dbline 393
; {
.dbline 394
; SPI_Write_Byte(Read_Sector_Lockdown_Register[i]);
movw R24,R28
mov R30,R20
clr R31
add R30,R24
adc R31,R25
ldd R16,z+0
xcall _SPI_Write_Byte
.dbline 395
; }
L114:
.dbline 392
inc R20
L116:
.dbline 392
cpi R20,4
brlo L113
X23:
.dbline 396
; for(i=0;i<8;i++)//read
clr R20
xjmp L120
L117:
.dbline 397
; {
.dbline 398
; Sector_Lockdown_Register[i] = SPI_Read_Byte(0);
clr R16
xcall _SPI_Read_Byte
mov R30,R20
clr R31
add R30,R10
adc R31,R11
std z+0,R16
.dbline 399
; }
L118:
.dbline 396
inc R20
L120:
.dbline 396
cpi R20,8
brlo L117
X24:
.dbline 400
; Disable_DFLASH();
xcall _Disable_DFLASH
.dbline -2
L111:
.dbline 0 ; func end
adiw R28,4
xjmp pop_xgset300C
.dbsym l Read_Sector_Lockdown_Register 0 A[4:4]c
.dbsym r i 20 c
.dbsym r Sector_Lockdown_Register 10 pc
.dbend
.dbfunc e DF_Write_to_Buffer _DF_Write_to_Buffer fV
; i -> R20,R21
; wDataSize -> y+6
; wData -> y+4
; BFA -> R10,R11
; BufferX -> R20
.even
_DF_Write_to_Buffer::
xcall push_xgset300C
movw R10,R18
mov R20,R16
.dbline -1
.dbline 411
; }
; /************************************************************
; *写数据到缓冲器(Buffer1或Buffer2)(缓冲器大小为264 bytes)
; *BufferX :选择缓冲器(Buffer1或Buffer2)
; *BFA :Buffer内存地址 0~263
; *wData :要写入的数据
; *wDataSize :要写入的数据长度(1~264)
; ************************************************************/
; void DF_Write_to_Buffer(unsigned char BufferX,unsigned int BFA,
; unsigned char *wData,unsigned int wDataSize)
; {
.dbline 414
; unsigned int i;
;
; DF_Check_Busy_State(); //check busy bit
xcall _DF_Check_Busy_State
.dbline 416
;
; Enable_DFLASH();
xcall _Enable_DFLASH
.dbline 418
;
; if(BufferX == Buffer1) SPI_Write_Byte(Write_Data_to_Buffer1);//0x84
cpi R20,1
brne L122
X25:
.dbline 418
ldi R16,132
xcall _SPI_Write_Byte
xjmp L123
L122:
.dbline 419
; else SPI_Write_Byte(Write_Data_to_Buffer2);//0x87
ldi R16,135
xcall _SPI_Write_Byte
L123:
.dbline 423
;
; //Page Size (264 Bytes)
; //15 don't care bits + 9 addrress
; SPI_Write_Byte(0xFF); //8 can't care bits
ldi R16,255
xcall _SPI_Write_Byte
.dbline 424
; SPI_Write_Byte((unsigned char)(BFA>>8)); //7 can't care bits + 1 bit address
movw R16,R10
mov R16,R17
clr R17
xcall _SPI_Write_Byte
.dbline 425
; SPI_Write_Byte((unsigned char)BFA); //address
mov R16,R10
xcall _SPI_Write_Byte
.dbline 427
;
; for(i=0;i<wDataSize;i++) SPI_Write_Byte(wData[i]);//写入数据
clr R20
clr R21
xjmp L127
L124:
.dbline 427
movw R30,R20
ldd R0,y+4
ldd R1,y+5
add R30,R0
adc R31,R1
ldd R16,z+0
xcall _SPI_Write_Byte
L125:
.dbline 427
subi R20,255 ; offset = 1
sbci R21,255
L127:
.dbline 427
ldd R0,y+6
ldd R1,y+7
cp R20,R0
cpc R21,R1
brlo L124
X26:
.dbline 429
;
; Disable_DFLASH();
xcall _Disable_DFLASH
.dbline -2
L121:
.dbline 0 ; func end
xjmp pop_xgset300C
.dbsym r i 20 i
.dbsym l wDataSize 6 i
.dbsym l wData 4 pc
.dbsym r BFA 10 i
.dbsym r BufferX 20 c
.dbend
.dbfunc e DF_Read_from_Buffer _DF_Read_from_Buffer fV
; i -> R20,R21
; rDataLen -> y+6
; rData -> y+4
; BFA -> R10,R11
; BufferX -> R20
.even
_DF_Read_from_Buffer::
xcall push_xgset300C
movw R10,R18
mov R20,R16
.dbline -1
.dbline 441
; }
; /************************************************************
; *读取缓冲器(Buffer1或Buffer2)(缓冲器大小为264 bytes)中的数据
; *BufferX :选择缓冲器(Buffer1或Buffer2)
; *BFA :Buffer内存地址 0~263
; *wData :存放读到的数据
; *wDataSize :要写入的数据长度(1~264)
; *注意:高速和低速发的操作码和要发送的数据长度不同
; ************************************************************/
; void DF_Read_from_Buffer(unsigned char BufferX,unsigned int BFA,
; unsigned char *rData,unsigned int rDataLen)
; {
.dbline 444
; unsigned int i;
;
; DF_Check_Busy_State(); //check busy bit
xcall _DF_Check_Busy_State
.dbline 446
;
; Enable_DFLASH();
xcall _Enable_DFLASH
.dbline 448
;
; if(BufferX == Buffer1) SPI_Write_Byte(Read_Data_from_Buffer1);//0xD4 or 0xD1(lower frequency)
cpi R20,1
brne L129
X27:
.dbline 448
ldi R16,212
xcall _SPI_Write_Byte
xjmp L130
L129:
.dbline 449
; else SPI_Write_Byte(Read_Data_from_Buffer2);//0xD6 or 0xD3(lower frequency)
ldi R16,214
xcall _SPI_Write_Byte
L130:
.dbline 453
;
; //Page Size (264 Bytes)
; //15 don't care bits + 9 addrress
; SPI_Write_Byte(0xFF); //8 can't care bits
ldi R16,255
xcall _SPI_Write_Byte
.dbline 454
; SPI_Write_Byte((unsigned char)(BFA>>8)); //7 can't care bits
movw R16,R10
mov R16,R17
clr R17
xcall _SPI_Write_Byte
.dbline 455
; SPI_Write_Byte((unsigned char)BFA); //address
mov R16,R10
xcall _SPI_Write_Byte
.dbline 456
; SPI_Write_Byte(0xFF); //1 can't care byte (lower frequency 不用这个字节)
ldi R16,255
xcall _SPI_Write_Byte
.dbline 458
;
; for(i=0;i<rDataLen;i++) rData[i] = SPI_Read_Byte(0xFF);//读取数据
clr R20
clr R21
xjmp L134
L131:
.dbline 458
ldi R16,255
xcall _SPI_Read_Byte
movw R30,R20
ldd R0,y+4
ldd R1,y+5
add R30,R0
adc R31,R1
std z+0,R16
L132:
.dbline 458
subi R20,255 ; offset = 1
sbci R21,255
L134:
.dbline 458
ldd R0,y+6
ldd R1,y+7
cp R20,R0
cpc R21,R1
brlo L131
X28:
.dbline 460
;
; Disable_DFLASH();
xcall _Disable_DFLASH
.dbline -2
L128:
.dbline 0 ; func end
xjmp pop_xgset300C
.dbsym r i 20 i
.dbsym l rDataLen 6 i
.dbsym l rData 4 pc
.dbsym r BFA 10 i
.dbsym r BufferX 20 c
.dbend
.dbfunc e DF_Write_Buffer_to_Page _DF_Write_Buffer_to_Page fV
; PA -> R10,R11
; BufferX -> R20
.even
_DF_Write_Buffer_to_Page::
xcall push_xgset300C
movw R10,R18
mov R20,R16
.dbline -1
.dbline 469
; }
; /************************************************************
; *把缓冲器(Buffer1或Buffer2)中的数据写到内存的页中(写整页)
; *先擦除再写数据(硬件支持的带擦除写)
; *BufferX :选择缓冲器(Buffer1或Buffer2)
; *PA :内存中页的地址 0~2047
; ************************************************************/
; void DF_Write_Buffer_to_Page(unsigned char BufferX,unsigned int PA)
; {
.dbline 470
; DF_Check_Busy_State();
xcall _DF_Check_Busy_State
.dbline 472
;
; Enable_DFLASH();
xcall _Enable_DFLASH
.dbline 474
;
; if(BufferX == Buffer1) SPI_Write_Byte(Write_Buffer1_to_Page_whin_Erase);//0x83
cpi R20,1
brne L136
X29:
.dbline 474
ldi R16,131
xcall _SPI_Write_Byte
xjmp L137
L136:
.dbline 475
; else SPI_Write_Byte(Write_Buffer2_to_Page_whin_Erase);//0x86
ldi R16,134
xcall _SPI_Write_Byte
L137:
.dbline 479
;
; //Page Size (264 Bytes)
; //4 don't care bits + 11 address + 9 don't care bits
; SPI_Write_Byte((unsigned char)(PA>>7));
ldi R18,7
ldi R19,0
movw R16,R10
xcall lsr16
xcall _SPI_Write_Byte
.dbline 480
; SPI_Write_Byte((unsigned char)(PA<<1));
mov R16,R10
lsl R16
rol R17
xcall _SPI_Write_Byte
.dbline 481
; SPI_Write_Byte(0xFF); //8 don't care bits
ldi R16,255
xcall _SPI_Write_Byte
.dbline 483
;
; Disable_DFLASH();
xcall _Disable_DFLASH
.dbline -2
L135:
.dbline 0 ; func end
xjmp pop_xgset300C
.dbsym r PA 10 i
.dbsym r BufferX 20 c
.dbend
.dbfunc e DF_Read_Buffer_from_Page _DF_Read_Buffer_from_Page fV
; PA -> R10,R11
; BufferX -> R20
.even
_DF_Read_Buffer_from_Page::
xcall push_xgset300C
movw R10,R18
mov R20,R16
.dbline -1
.dbline 491
; }
; /************************************************************
; *读取内存的页(整页)的数据到缓冲器(Buffer1或Buffer2)中
; *BufferX :选择缓冲器(Buffer1或Buffer2)
; *PA :内存中页的地址 0~2047
; ************************************************************/
; void DF_Read_Buffer_from_Page(unsigned char BufferX,unsigned int PA)
; {
.dbline 492
; DF_Check_Busy_State();
xcall _DF_Check_Busy_State
.dbline 494
;
; Enable_DFLASH();
xcall _Enable_DFLASH
.dbline 496
;
; if(BufferX == Buffer1) SPI_Write_Byte(Read_Page_to_Buffer1);//0x53
cpi R20,1
brne L139
X30:
.dbline 496
ldi R16,83
xcall _SPI_Write_Byte
xjmp L140
L139:
.dbline 497
; else SPI_Write_Byte(Read_Page_to_Buffer2);//0x55
ldi R16,85
xcall _SPI_Write_Byte
L140:
.dbline 501
;
; //Page Size (264 Bytes)
; //4 don't care bits + 11 address + 9 don't care bits
; SPI_Write_Byte((unsigned char)(PA>>7));
ldi R18,7
ldi R19,0
movw R16,R10
xcall lsr16
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -