📄 at45db161.lst
字号:
01EF 4F5F SBCI R21,0xFF
01F0 3A42 CPI R20,0xA2
01F1 ECED LDI R30,0xCD
01F2 075E CPC R21,R30
01F3 F3D0 BCS 0x01EE
01F4 5001 SUBI R16,1
01F5 4010 SBCI R17,0
01F6 2422 CLR R2
01F7 2433 CLR R3
01F8 1620 CP R2,R16
01F9 0631 CPC R3,R17
01FA F384 BLT 0x01EB
01FB 940E04E1 CALL pop_gset1
01FD 9508 RET
FILE: D:\ICC_H\dataflash_.h
(0001) /******** Example Code : Accessing Atmel AT45Dxxx dataflash on STK500 *******
(0002)
(0003) Device : AT90S8515
(0004)
(0005) File name : dataflash.c
(0006)
(0007) Description : Functions to access the Atmel AT45Dxxx dataflash series
(0008) Supports 512Kbit - 64Mbit
(0009)
(0010) Last change: 16 Aug 2001 AS
(0011)
(0012) ****************************************************************************/
(0013)
(0014) #define __IAR_SYSTEMS_ASM__
(0015)
(0016) // Includes
(0017) //#include <INA90.H>
(0018) //#include <io8515.h>
(0019)
(0020) #include "D:\ICC_H\dataflash.h"
(0021)
(0022) // Constants
(0023) //Look-up table for these sizes -> 512k, 1M, 2M, 4M, 8M, 16M, 32M, 64M
(0024) flash unsigned char DF_pagebits[] ={ 9, 9, 9, 9, 9, 10, 10, 11}; //index of internal page address bits
(0025)
(0026) // Globals
(0027) unsigned char PageBits;
(0028)
(0029) // Functions
(0030)
(0031) /*****************************************************************************
(0032) *
(0033) * Function name : DF_SPI_init
(0034) *
(0035) * Returns : None
(0036) *
(0037) * Parameters : None
(0038) *
(0039) * Purpose : Sets up the HW SPI in Master mode, Mode 3
(0040) * Note -> Uses the SS line to control the DF CS-line.
(0041) *
(0042) ******************************************************************************/
(0043) void DF_SPI_init (void)
(0044) {
(0045) //PORTB= (1<<PORTB); //Set SS high
(0046) //DDRB = (1<<PB4) | (1<<PB5)| (1<<PB7); //Set SS, MOSI and SCK as outputs
(0047)
(0048) SPCR = (1<<SPE) | (1<<MSTR) | (1<<CPHA) | (1<<CPOL); //Enable SPI in Master mode, mode 3
_DF_SPI_init:
01FE E58C LDI R24,0x5C
01FF B98D OUT 0x0D,R24
0200 9508 RET
_DF_SPI_RW:
input --> R20
output --> R16
0201 940E04DE CALL push_gset1
(0049) //SPCR=0x51;
(0050) }
(0051)
(0052)
(0053) /*****************************************************************************
(0054) *
(0055) * Function name : DF_SPI_RW
(0056) *
(0057) * Returns : Byte read from SPI data register (any value)
(0058) *
(0059) * Parameters : Byte to be written to SPI data register (any value)
(0060) *
(0061) * Purpose : Read and writes one byte from/to SPI master
(0062) *
(0063) ******************************************************************************/
(0064) unsigned char DF_SPI_RW (unsigned char output)
(0065) {
(0066) unsigned char input;
(0067)
(0068) SPDR = output; //put byte 'output' in SPI data register
0203 B90F OUT 0x0F,R16
(0069) while(!(SPSR & 0x80)); //wait for transfer complete, poll SPIF-flag
0204 9B77 SBIS 0x0E,7
0205 CFFE RJMP 0x0204
(0070) input = SPDR; //read value in SPI data reg.
0206 B14F IN R20,0x0F
(0071)
(0072) return input; //return the byte clocked in from SPI slave
0207 2F04 MOV R16,R20
0208 940E04E1 CALL pop_gset1
020A 9508 RET
_Read_DF_status:
index_copy --> R22
result --> R20
020B 940E04DC CALL push_gset2
(0073) }
(0074)
(0075)
(0076) /*****************************************************************************
(0077) *
(0078) * Function name : Read_DF_status
(0079) *
(0080) * Returns : One status byte. Consult Dataflash datasheet for further
(0081) * decoding info
(0082) *
(0083) * Parameters : None
(0084) *
(0085) * Purpose : Status info concerning the Dataflash is busy or not.
(0086) * Status info concerning compare between buffer and flash page
(0087) * Status info concerning size of actual device
(0088) *
(0089) ******************************************************************************/
(0090) unsigned char Read_DF_status (void)
(0091) {
(0092) unsigned char result,index_copy;
(0093)
(0094) DF_CS_inactive; //make sure to toggle CS signal in order
020D 9A96 SBI 0x12,6
(0095) DF_CS_active; //to reset dataflash command decoder
020E 9896 CBI 0x12,6
(0096) result = DF_SPI_RW(StatusReg); //send status register read op-code
020F E507 LDI R16,0x57
0210 DFF0 RCALL _DF_SPI_RW
(0097) result = DF_SPI_RW(0x00); //dummy write to get result
0211 2700 CLR R16
0212 DFEE RCALL _DF_SPI_RW
0213 2F40 MOV R20,R16
(0098)
(0099) index_copy = ((result & 0x38) >> 3); //get the size info from status register
0214 2F64 MOV R22,R20
0215 7368 ANDI R22,0x38
0216 9566 LSR R22
0217 9566 LSR R22
0218 9566 LSR R22
(0100) PageBits = DF_pagebits[index_copy]; //get number of internal page address bits from look-up table
0219 E584 LDI R24,0x54
021A E090 LDI R25,0
021B 2FE6 MOV R30,R22
021C 27FF CLR R31
021D 0FE8 ADD R30,R24
021E 1FF9 ADC R31,R25
021F 91E4 LPM R30,0(Z)
0220 93E00060 STS PageBits,R30
(0101)
(0102) return result; //return the read status register value
0222 940E04CA CALL pop_gset2
0224 9508 RET
_Page_To_Buffer:
BufferNo --> R22
PageAdr --> R20
0225 940E04DC CALL push_gset2
0227 2F62 MOV R22,R18
0228 01A8 MOVW R20,R16
(0103) }
(0104)
(0105)
(0106) /*****************************************************************************
(0107) *
(0108) * Function name : Page_To_Buffer
(0109) *
(0110) * Returns : None
(0111) *
(0112) * Parameters : BufferNo -> Decides usage of either buffer 1 or 2
(0113) * PageAdr -> Address of page to be transferred to buffer
(0114) *
(0115) * Purpose : Transfers a page from flash to dataflash SRAM buffer
(0116) *
(0117) ******************************************************************************/
(0118) void Page_To_Buffer (unsigned int PageAdr, unsigned char BufferNo)
(0119) {
(0120) DF_CS_inactive; //make sure to toggle CS signal in order
0229 9A96 SBI 0x12,6
(0121) DF_CS_active; //to reset dataflash command decoder
022A 9896 CBI 0x12,6
(0122)
(0123) if (1 == BufferNo) //transfer flash page to buffer 1
022B 3061 CPI R22,1
022C F4C9 BNE 0x0246
(0124) {
(0125) DF_SPI_RW(FlashToBuf1Transfer); //transfer to buffer 1 op-code
022D E503 LDI R16,0x53
022E DFD2 RCALL _DF_SPI_RW
(0126) DF_SPI_RW((unsigned char)(PageAdr >> (16 - PageBits))); //upper part of page address
022F 90200060 LDS R2,PageBits
0231 2433 CLR R3
0232 E120 LDI R18,0x10
0233 E030 LDI R19,0
0234 1922 SUB R18,R2
0235 0933 SBC R19,R3
0236 018A MOVW R16,R20
0237 940E0521 CALL lsr16
0239 DFC7 RCALL _DF_SPI_RW
(0127) DF_SPI_RW((unsigned char)(PageAdr << (PageBits - 8))); //lower part of page address
023A 91200060 LDS R18,PageBits
023C 2733 CLR R19
023D 5028 SUBI R18,0x8
023E 4030 SBCI R19,0
023F 018A MOVW R16,R20
0240 940E051A CALL lsl16
0242 DFBE RCALL _DF_SPI_RW
(0128) DF_SPI_RW(0x00); //don't cares
0243 2700 CLR R16
0244 DFBC RCALL _DF_SPI_RW
(0129) }
0245 C01A RJMP 0x0260
(0130) else
(0131) if (2 == BufferNo) //transfer flash page to buffer 2
0246 3062 CPI R22,2
0247 F4C1 BNE 0x0260
(0132) {
(0133) DF_SPI_RW(FlashToBuf2Transfer); //transfer to buffer 2 op-code
0248 E505 LDI R16,0x55
0249 DFB7 RCALL _DF_SPI_RW
(0134) DF_SPI_RW((unsigned char)(PageAdr >> (16 - PageBits))); //upper part of page address
024A 90200060 LDS R2,PageBits
024C 2433 CLR R3
024D E120 LDI R18,0x10
024E E030 LDI R19,0
024F 1922 SUB R18,R2
0250 0933 SBC R19,R3
0251 018A MOVW R16,R20
0252 940E0521 CALL lsr16
0254 DFAC RCALL _DF_SPI_RW
(0135) DF_SPI_RW((unsigned char)(PageAdr << (PageBits - 8))); //lower part of page address
0255 91200060 LDS R18,PageBits
0257 2733 CLR R19
0258 5028 SUBI R18,0x8
0259 4030 SBCI R19,0
025A 018A MOVW R16,R20
025B 940E051A CALL lsl16
025D DFA3 RCALL _DF_SPI_RW
(0136) DF_SPI_RW(0x00); //don't cares
025E 2700 CLR R16
025F DFA1 RCALL _DF_SPI_RW
(0137) }
(0138)
(0139) DF_CS_inactive; //initiate the transfer
0260 9A96 SBI 0x12,6
(0140) DF_CS_active;
0261 9896 CBI 0x12,6
(0141)
(0142) while(!(Read_DF_status() & 0x80)); //monitor the status register, wait until busy-flag is high
0262 DFA8 RCALL _Read_DF_status
0263 FF07 SBRS R16,7
0264 CFFD RJMP 0x0262
0265 940E04CA CALL pop_gset2
0267 9508 RET
_Buffer_Read_Byte:
data --> R20
IntPageAdr --> R22
BufferNo --> R10
0268 940E04DA CALL push_gset3
026A 01B9 MOVW R22,R18
026B 2EA0 MOV R10,R16
(0143) }
(0144)
(0145)
(0146)
(0147) /*****************************************************************************
(0148) *
(0149) * Function name : Buffer_Read_Byte
(0150) *
(0151) * Returns : One read byte (any value)
(0152) *
(0153) * Parameters : BufferNo -> Decides usage of either buffer 1 or 2
(0154) * IntPageAdr -> Internal page address
(0155) *
(0156) * Purpose : Reads one byte from one of the dataflash
(0157) * internal SRAM buffers
(0158) *
(0159) ******************************************************************************/
(0160) unsigned char Buffer_Read_Byte (unsigned char BufferNo, unsigned int IntPageAdr)
(0161) {
(0162) unsigned char data;
(0163)
(0164) DF_CS_inactive; //make sure to toggle CS signal in order
026C 9A96 SBI 0x12,6
(0165) DF_CS_active; //to reset dataflash command decoder
026D 9896 CBI 0x12,6
(0166)
(0167) if (1 == BufferNo) //read byte from buffer 1
026E 2D8A MOV R24,R10
026F 3081 CPI R24,1
0270 F481 BNE 0x0281
(0168) {
(0169) DF_SPI_RW(Buf1Read); //buffer 1 read op-code
0271 E504 LDI R16,0x54
0272 DF8E RCALL _DF_SPI_RW
(0170) DF_SPI_RW(0x00); //don't cares
0273 2700 CLR R16
0274 DF8C RCALL _DF_SPI_RW
(0171) DF_SPI_RW((unsigned char)(IntPageAdr>>8));//upper part of internal buffer address
0275 018B MOVW R16,R22
0276 2F01 MOV R16,R17
0277 2711 CLR R17
0278 DF88 RCALL _DF_SPI_RW
(0172) DF_SPI_RW((unsigned char)(IntPageAdr)); //lower part of internal buffer address
0279 2F06 MOV R16,R22
027A DF86 RCALL _DF_SPI_RW
(0173) DF_SPI_RW(0x00); //don't cares
027B 2700 CLR R16
027C DF84 RCALL _DF_SPI_RW
(0174) data = DF_SPI_RW(0x00); //read byte
027D 2700 CLR R16
027E DF82 RCALL _DF_SPI_RW
027F 2F40 MOV R20,R16
(0175) }
0280 C012 RJMP 0x0293
(0176) else
(0177) if (2 == BufferNo) //read byte from buffer 2
0281 2D8A MOV R24,R10
0282 3082 CPI R24,2
0283 F479 BNE 0x0293
(0178) {
(0179) DF_SPI_RW(Buf2Read); //buffer 2 read op-code
0284 E506 LDI R16,0x56
0285 DF7B RCALL _DF_SPI_RW
(0180) DF_SPI_RW(0x00); //don't cares
0286 2700 CLR R16
0287 DF79 RCALL _DF_SPI_RW
(0181) DF_SPI_RW((unsigned char)(IntPageAdr>>8));//upper part of internal buffer address
0288 018B MOVW R16,R22
0289 2F01 MOV R16,R17
028A 2711 CLR R17
028B DF75 RCALL _DF_SPI_RW
(0182) DF_SPI_RW((unsigned char)(IntPageAdr)); //lower part of internal buffer address
028C 2F06 MOV R16,R22
028D DF73 RCALL _DF_SPI_RW
(0183) DF_SPI_RW(0x00); //don't cares
028E 2700 CLR R16
028F DF71 RCALL _DF_SPI_RW
(0184) data = DF_SPI_RW(0x00); //read byte
0290 2700 CLR R16
0291 DF6F RCALL _DF_SPI_RW
0292 2F40 MOV R20,R16
(0185) }
(0186)
(0187) return data; //return the read data byte
0293 2F04 MOV R16,R20
0294 940E04CD CALL pop_gset3
0296 9508 RET
_Buffer_Read_Str:
i --> R20
BufferPtr --> R22
No_of_bytes --> R10
IntPageAdr --> R12
BufferNo --> R14
0297 940E04D6 CALL push_gset5
0299 0169 MOVW R12,R18
029A 2EE0 MOV R14,R16
029B 84AA LDD R10,Y+10
029C 84BB LDD R11,Y+11
029D 856C LDD R22,Y+12
029E 857D LDD R23,Y+13
(0188) }
(0189)
(0190)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -