📄 at45db021.s
字号:
.module AT45DB021.c
.area text(rom, con, rel)
.dbfile D:\Datasheet\Atmel\FROMJI~1\AVR_Demo\m8\SoftWare\AT45DB021.c
.dbfunc e SPI_MOSI _SPI_MOSI fV
; flag -> R16
.even
_SPI_MOSI::
.dbline -1
.dbline 8
; #include "AT45DB021.h"
; #include <iom8v.h>
; #include <macros.h>
; #include "M8Demo.h"
; #include "Uart.h"
;
; void SPI_MOSI(unsigned char flag)
; {
.dbline 9
; if(flag)
tst R16
breq L2
.dbline 10
; PORTC|=0x02;
sbi 0x15,1
rjmp L3
L2:
.dbline 12
in R24,0x15
andi R24,125
out 0x15,R24
L3:
.dbline -2
L1:
.dbline 0 ; func end
ret
.dbsym r flag 16 c
.dbend
.dbfunc e SPI_MISO _SPI_MISO fc
.even
_SPI_MISO::
.dbline -1
.dbline 15
; else
; PORTC&=0x7D;
; }
; unsigned char SPI_MISO(void)
; {
.dbline 16
; if ((PINC & 0x04))
sbis 0x13,2
rjmp L5
.dbline 18
;
; return 1;
ldi R16,1
rjmp L4
L5:
.dbline 20
; else
; return 0;
clr R16
.dbline -2
L4:
.dbline 0 ; func end
ret
.dbend
.dbfunc e SPI_SCK _SPI_SCK fV
; flag -> R16
.even
_SPI_SCK::
.dbline -1
.dbline 24
;
; }
; void SPI_SCK(unsigned char flag)
; {
.dbline 25
; if(flag)
tst R16
breq L8
.dbline 26
; PORTC|=0x08;
sbi 0x15,3
rjmp L9
L8:
.dbline 28
in R24,0x15
andi R24,119
out 0x15,R24
L9:
.dbline -2
L7:
.dbline 0 ; func end
ret
.dbsym r flag 16 c
.dbend
.dbfunc e SPI_CS _SPI_CS fV
; flag -> R16
.even
_SPI_CS::
.dbline -1
.dbline 31
; else
; PORTC&=0x77;
; }
; void SPI_CS(unsigned char flag)
; {
.dbline 32
; if(flag)
tst R16
breq L11
.dbline 33
; PORTC|=0x01;
sbi 0x15,0
rjmp L12
L11:
.dbline 35
in R24,0x15
andi R24,126
out 0x15,R24
L12:
.dbline -2
L10:
.dbline 0 ; func end
ret
.dbsym r flag 16 c
.dbend
.dbfunc e SPI_Start _SPI_Start fV
.even
_SPI_Start::
.dbline -1
.dbline 39
; else
; PORTC&=0x7E;
; }
;
; void SPI_Start(void)
; {
.dbline 40
; DDRC|=0x7F;
in R24,0x14
ori R24,127
out 0x14,R24
.dbline 41
; DDRC&=0x7B;
in R24,0x14
andi R24,123
out 0x14,R24
.dbline 42
; PORTC=0x7F;
ldi R24,127
out 0x15,R24
.dbline 44
; //Delay(100);
; SPI_CS(1);
ldi R16,1
rcall _SPI_CS
.dbline 45
; SPI_SCK(1);
ldi R16,1
rcall _SPI_SCK
.dbline 46
; SPI_MOSI(1);
ldi R16,1
rcall _SPI_MOSI
.dbline 47
; SPI_CS(0);
clr R16
rcall _SPI_CS
.dbline -2
L13:
.dbline 0 ; func end
ret
.dbend
.dbfunc e SPI_End _SPI_End fV
.even
_SPI_End::
.dbline -1
.dbline 50
; }
; void SPI_End(void)
; {
.dbline 51
; DDRC|=0x7F;
in R24,0x14
ori R24,127
out 0x14,R24
.dbline 52
; DDRC&=0x79;
in R24,0x14
andi R24,121
out 0x14,R24
.dbline 53
; Delay(100);
ldi R16,100
ldi R17,0
rcall _Delay
.dbline 54
; SPI_CS(1);
ldi R16,1
rcall _SPI_CS
.dbline 55
; SPI_SCK(1);
ldi R16,1
rcall _SPI_SCK
.dbline 56
; SPI_MOSI(1);
ldi R16,1
rcall _SPI_MOSI
.dbline 57
; SPI_CS(1);
ldi R16,1
rcall _SPI_CS
.dbline -2
L14:
.dbline 0 ; func end
ret
.dbend
.dbfunc e SPI_Send8BitData _SPI_Send8BitData fV
; i -> R20
; Send_data -> R22
.even
_SPI_Send8BitData::
rcall push_gset2
mov R22,R16
.dbline -1
.dbline 60
; }
; void SPI_Send8BitData(unsigned char Send_data)
; {
.dbline 63
; unsigned char i;
;
; for(i=8;i>0;i--)
ldi R20,8
rjmp L19
L16:
.dbline 64
; { Delay(DELAYTIMER );
.dbline 64
ldi R16,3
ldi R17,0
rcall _Delay
.dbline 65
; SPI_SCK(0);
clr R16
rcall _SPI_SCK
.dbline 66
; Delay(DELAYTIMER );
ldi R16,3
ldi R17,0
rcall _Delay
.dbline 67
; if((Send_data&0x80)==0x80)
mov R24,R22
andi R24,128
cpi R24,128
brne L20
.dbline 68
; SPI_MOSI(1);
ldi R16,1
rcall _SPI_MOSI
rjmp L21
L20:
.dbline 70
; else
; SPI_MOSI(0);
clr R16
rcall _SPI_MOSI
L21:
.dbline 71
lsl R22
.dbline 72
ldi R16,3
ldi R17,0
rcall _Delay
.dbline 73
ldi R16,1
rcall _SPI_SCK
.dbline 74
L17:
.dbline 63
dec R20
L19:
.dbline 63
clr R2
cp R2,R20
brlo L16
.dbline 75
; Send_data=Send_data<<1;
; Delay(DELAYTIMER );
; SPI_SCK(1);
; }
; Delay(DELAYTIMER );
ldi R16,3
ldi R17,0
rcall _Delay
.dbline -2
L15:
rcall pop_gset2
.dbline 0 ; func end
ret
.dbsym r i 20 c
.dbsym r Send_data 22 c
.dbend
.dbfunc e SPI_Receive8BitData _SPI_Receive8BitData fc
; i -> R22
; receivedata -> R20
.even
_SPI_Receive8BitData::
rcall push_gset2
.dbline -1
.dbline 78
; }
; unsigned char SPI_Receive8BitData(void)
; {
.dbline 80
; unsigned char i,receivedata;
; receivedata=0;
clr R20
.dbline 81
; for(i=0;i<7;i++)
clr R22
rjmp L26
L23:
.dbline 82
; {
.dbline 83
; Delay(DELAYTIMER );
ldi R16,3
ldi R17,0
rcall _Delay
.dbline 84
; SPI_SCK(0);
clr R16
rcall _SPI_SCK
.dbline 85
; Delay(DELAYTIMER );
ldi R16,3
ldi R17,0
rcall _Delay
.dbline 86
; SPI_SCK(1);
ldi R16,1
rcall _SPI_SCK
.dbline 87
; Delay(DELAYTIMER );
ldi R16,3
ldi R17,0
rcall _Delay
.dbline 88
; if(SPI_MISO())
rcall _SPI_MISO
tst R16
breq L27
.dbline 89
; receivedata|=0x01;
ori R20,1
L27:
.dbline 90
lsl R20
.dbline 92
L24:
.dbline 81
inc R22
L26:
.dbline 81
cpi R22,7
brlo L23
.dbline 93
; receivedata=receivedata<<1;
;
; }
; Delay(DELAYTIMER );
ldi R16,3
ldi R17,0
rcall _Delay
.dbline 94
; SPI_SCK(0);
clr R16
rcall _SPI_SCK
.dbline 95
; Delay(DELAYTIMER );
ldi R16,3
ldi R17,0
rcall _Delay
.dbline 96
; SPI_SCK(1);
ldi R16,1
rcall _SPI_SCK
.dbline 97
; Delay(DELAYTIMER );
ldi R16,3
ldi R17,0
rcall _Delay
.dbline 98
; if(SPI_MISO())
rcall _SPI_MISO
tst R16
breq L29
.dbline 99
; receivedata|=0x01;
ori R20,1
L29:
.dbline 100
; Delay(DELAYTIMER );
ldi R16,3
ldi R17,0
rcall _Delay
.dbline 102
;
; return receivedata;
mov R16,R20
.dbline -2
L22:
rcall pop_gset2
.dbline 0 ; func end
ret
.dbsym r i 22 c
.dbsym r receivedata 20 c
.dbend
.dbfunc e erasing_flash _erasing_flash fV
; Block_Add -> R20,R21
.even
_erasing_flash::
rcall push_gset1
.dbline -1
.dbline 107
; }
;
;
; void erasing_flash(void)
; {
.dbline 108
; unsigned int Block_Add = 0;
clr R20
clr R21
.dbline 110
;
; for (Block_Add=0;Block_Add<Block_Size;Block_Add++)
rjmp L35
L32:
.dbline 111
.dbline 111
mov R16,R20
rcall _EasingBlock
.dbline 112
ldi R16,5000
ldi R17,19
rcall _Delay
.dbline 113
L33:
.dbline 110
subi R20,255 ; offset = 1
sbci R21,255
L35:
.dbline 110
cpi R20,128
ldi R30,0
cpc R21,R30
brlo L32
.dbline -2
L31:
rcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r Block_Add 20 i
.dbend
.dbfunc e EasingBlock _EasingBlock fV
; Block_Add -> R20
.even
_EasingBlock::
rcall push_gset1
mov R20,R16
.dbline -1
.dbline 119
; {EasingBlock( Block_Add);
; Delay(5000);
; }
;
; }
;
;
; void EasingBlock(unsigned char Block_Add)
; {
.dbline 120
; SPI_Start();//enable spi
rcall _SPI_Start
.dbline 121
; SPI_Send8BitData(BLOCK_ERASE ); //send block erase command
ldi R16,80
rcall _SPI_Send8BitData
.dbline 122
; SPI_Send8BitData((char)(Block_Add>>4) );//send block address MSB PA9 PA8 PA7
mov R16,R20
clr R17
asr R17
ror R16
asr R17
ror R16
asr R17
ror R16
asr R17
ror R16
rcall _SPI_Send8BitData
.dbline 123
; SPI_Send8BitData((char)(Block_Add<<4 ));//send block address LSB PA6 ... PA3
mov R16,R20
clr R17
lsl R16
rol R17
lsl R16
rol R17
lsl R16
rol R17
lsl R16
rol R17
rcall _SPI_Send8BitData
.dbline 124
; SPI_Send8BitData(0x00); //do not care
clr R16
rcall _SPI_Send8BitData
.dbline 125
; Delay(100);
ldi R16,100
ldi R17,0
rcall _Delay
.dbline 126
; SPI_End();//disable spi
rcall _SPI_End
.dbline -2
L36:
rcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r Block_Add 20 c
.dbend
.dbfunc e EasingPage _EasingPage fV
; Page_Add -> R20,R21
.even
_EasingPage::
rcall push_gset1
movw R20,R16
.dbline -1
.dbline 130
; }
;
; void EasingPage(unsigned int Page_Add)
; {
.dbline 132
;
; SPI_Start();//enable spi
rcall _SPI_Start
.dbline 133
; SPI_Send8BitData(PAGE_ERASE ); //send page erase command
ldi R16,129
rcall _SPI_Send8BitData
.dbline 134
; SPI_Send8BitData((char)(Page_Add>>7));//send block address MSB PA9 PA8 PA7
ldi R18,7
ldi R19,0
movw R16,R20
rcall lsr16
rcall _SPI_Send8BitData
.dbline 135
; SPI_Send8BitData((char)(Page_Add<<1));//send block address LSB PA6 ... PA0
mov R16,R20
lsl R16
rol R17
rcall _SPI_Send8BitData
.dbline 136
; SPI_Send8BitData(0x00); //do not care
clr R16
rcall _SPI_Send8BitData
.dbline 137
; Delay(100);
ldi R16,100
ldi R17,0
rcall _Delay
.dbline 138
; SPI_End();//disable spi
rcall _SPI_End
.dbline -2
L37:
rcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r Page_Add 20 i
.dbend
.dbfunc e WriteToBuffer _WriteToBuffer fV
; i -> R20,R21
; Buff_add -> y+8
; BufferSelect -> y+6
; datalength -> R10,R11
; write_data -> R22,R23
.even
_WriteToBuffer::
rcall push_gset3
movw R10,R18
movw R22,R16
.dbline -1
.dbline 142
; }
;
; void WriteToBuffer(unsigned char * write_data,unsigned int datalength,unsigned char BufferSelect,unsigned int Buff_add)
; {
.dbline 144
; unsigned int i;
; SPI_Start();//enable spi
rcall _SPI_Start
.dbline 145
; switch( BufferSelect )
ldd R20,y+6
clr R21
cpi R20,0
cpc R20,R21
breq L42
X0:
cpi R20,3
ldi R30,0
cpc R21,R30
breq L43
rjmp L38
X1:
.dbline 146
; {
L42:
.dbline 147
; case BUFFER_1: SPI_Send8BitData(BUFFER_1_WRITE );break;
ldi R16,132
rcall _SPI_Send8BitData
.dbline 147
rjmp L40
L43:
.dbline 148
; case BUFFER_2: SPI_Send8BitData(BUFFER_2_WRITE );break;
ldi R16,135
rcall _SPI_Send8BitData
.dbline 148
.dbline 149
; default: return;
L40:
.dbline 151
; }
; SPI_Send8BitData(0x00); //do not care
clr R16
rcall _SPI_Send8BitData
.dbline 152
; SPI_Send8BitData((char)(Buff_add>>8));//send block address MSB BA8
ldd R16,y+8
ldd R17,y+9
mov R16,R17
clr R17
rcall _SPI_Send8BitData
.dbline 153
; SPI_Send8BitData((char)(Buff_add));//send block address LSB BA7 ... BA0
ldd R16,y+8
ldd R17,y+9
rcall _SPI_Send8BitData
.dbline 154
; for(i=0;i<datalength;i++)
clr R20
clr R21
rjmp L47
L44:
.dbline 155
movw R30,R20
add R30,R22
adc R31,R23
ldd R16,z+0
rcall _SPI_Send8BitData
L45:
.dbline 154
subi R20,255 ; offset = 1
sbci R21,255
L47:
.dbline 154
cp R20,R10
cpc R21,R11
brlo L44
.dbline 156
; SPI_Send8BitData(write_data[i]); //write data
; Delay(100);
ldi R16,100
ldi R17,0
rcall _Delay
.dbline 157
; SPI_End();//disable spi
rcall _SPI_End
.dbline -2
L38:
rcall pop_gset3
.dbline 0 ; func end
ret
.dbsym r i 20 i
.dbsym l Buff_add 8 i
.dbsym l BufferSelect 6 c
.dbsym r datalength 10 i
.dbsym r write_data 22 pc
.dbend
.dbfunc e WriteToMemory _WriteToMemory fV
; WriteFlag -> R22
; Page_Add -> R20,R21
.even
_WriteToMemory::
rcall push_gset2
mov R22,R18
movw R20,R16
.dbline -1
.dbline 162
; }
;
;
; void WriteToMemory(unsigned int Page_Add,unsigned char WriteFlag)
; {
.dbline 164
;
; SPI_Start();//enable spi
rcall _SPI_Start
.dbline 165
; switch(WriteFlag)
clr R23
cpi R22,131
ldi R30,0
cpc R23,R30
breq L52
cpi R22,134
ldi R30,0
cpc R23,R30
breq L53
cpi R22,136
ldi R30,0
cpc R23,R30
breq L54
cpi R22,137
ldi R30,0
cpc R23,R30
breq L55
rjmp L50
X2:
.dbline 166
; {case B1_TO_MM_PAGE_PROG_WITH_ERASE:
L52:
.dbline 167
; SPI_Send8BitData(B1_TO_MM_PAGE_PROG_WITH_ERASE );
ldi R16,131
rcall _SPI_Send8BitData
.dbline 168
; break;
rjmp L50
L53:
.dbline 170
; case B2_TO_MM_PAGE_PROG_WITH_ERASE:
; SPI_Send8BitData(B2_TO_MM_PAGE_PROG_WITH_ERASE );
ldi R16,134
rcall _SPI_Send8BitData
.dbline 171
; break;
rjmp L50
L54:
.dbline 173
; case B1_TO_MM_PAGE_PROG_WITHOUT_ERASE:
; SPI_Send8BitData(B1_TO_MM_PAGE_PROG_WITHOUT_ERASE );
ldi R16,136
rcall _SPI_Send8BitData
.dbline 174
; break;
rjmp L50
L55:
.dbline 176
; case B2_TO_MM_PAGE_PROG_WITHOUT_ERASE:
; SPI_Send8BitData(B2_TO_MM_PAGE_PROG_WITHOUT_ERASE );
ldi R16,137
rcall _SPI_Send8BitData
.dbline 177
; break;
.dbline 178
; default:break;
L50:
.dbline 181
; }
;
; SPI_Send8BitData((char)(Page_Add>>7));//send block address MSB PA9 PA8 PA7
ldi R18,7
ldi R19,0
movw R16,R20
rcall lsr16
rcall _SPI_Send8BitData
.dbline 182
; SPI_Send8BitData((char)(Page_Add<<1));//send block address LSB PA6 ... PA0
mov R16,R20
lsl R16
rol R17
rcall _SPI_Send8BitData
.dbline 183
; SPI_Send8BitData(0x00); //do not care
clr R16
rcall _SPI_Send8BitData
.dbline 184
; SPI_End();//disable spi
rcall _SPI_End
.dbline 185
; Delay(100);
ldi R16,100
ldi R17,0
rcall _Delay
.dbline -2
L48:
rcall pop_gset2
.dbline 0 ; func end
ret
.dbsym r WriteFlag 22 c
.dbsym r Page_Add 20 i
.dbend
.dbfunc e ReadBuffer _ReadBuffer fV
; i -> R20,R21
; Buff_add -> y+8
; BufferSelect -> y+6
; datalength -> R10,R11
; Read_data -> R22,R23
.even
_ReadBuffer::
rcall push_gset3
movw R10,R18
movw R22,R16
.dbline -1
.dbline 189
;
; }
; void ReadBuffer(unsigned char * Read_data,unsigned int datalength,unsigned char BufferSelect,unsigned int Buff_add)
; {
.dbline 191
; unsigned int i;
; SPI_Start();//enable spi
rcall _SPI_Start
.dbline 192
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -