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

📄 at45db161.lst

📁 ATmega16应用例子
💻 LST
📖 第 1 页 / 共 5 页
字号:
(0191) 
(0192) /*****************************************************************************
(0193) *
(0194) *	Function name : Buffer_Read_Str
(0195) *
(0196) *	Returns :		None
(0197) *
(0198) *	Parameters :	BufferNo	->	Decides usage of either buffer 1 or 2
(0199) *					IntPageAdr	->	Internal page address
(0200) *					No_of_bytes	->	Number of bytes to be read
(0201) *					*BufferPtr	->	address of buffer to be used for read bytes
(0202) *
(0203) *	Purpose :		Reads one or more bytes from one of the dataflash
(0204) *					internal SRAM buffers, and puts read bytes into
(0205) *					buffer pointed to by *BufferPtr
(0206) *
(0207) ******************************************************************************/
(0208) void Buffer_Read_Str (unsigned char BufferNo, unsigned int IntPageAdr, unsigned int No_of_bytes, unsigned char *BufferPtr)
(0209) {
(0210) 	unsigned int i;
(0211) 
(0212) 	DF_CS_inactive;								//make sure to toggle CS signal in order
    029F 9A96      SBI	0x12,6
(0213) 	DF_CS_active;								//to reset dataflash command decoder
    02A0 9896      CBI	0x12,6
(0214) 	
(0215) 	if (1 == BufferNo)							//read byte(s) from buffer 1
    02A1 2D8E      MOV	R24,R14
    02A2 3081      CPI	R24,1
    02A3 F4D9      BNE	0x02BF
(0216) 	{
(0217) 		DF_SPI_RW(Buf1Read);					//buffer 1 read op-code
    02A4 E504      LDI	R16,0x54
    02A5 DF5B      RCALL	_DF_SPI_RW
(0218) 		DF_SPI_RW(0x00);						//don't cares
    02A6 2700      CLR	R16
    02A7 DF59      RCALL	_DF_SPI_RW
(0219) 		DF_SPI_RW((unsigned char)(IntPageAdr>>8));//upper part of internal buffer address
    02A8 0186      MOVW	R16,R12
    02A9 2F01      MOV	R16,R17
    02AA 2711      CLR	R17
    02AB DF55      RCALL	_DF_SPI_RW
(0220) 		DF_SPI_RW((unsigned char)(IntPageAdr));	//lower part of internal buffer address
    02AC 2D0C      MOV	R16,R12
    02AD DF53      RCALL	_DF_SPI_RW
(0221) 		DF_SPI_RW(0x00);						//don't cares
    02AE 2700      CLR	R16
    02AF DF51      RCALL	_DF_SPI_RW
(0222) 		for( i=0; i<No_of_bytes; i++)
    02B0 2744      CLR	R20
    02B1 2755      CLR	R21
    02B2 C008      RJMP	0x02BB
(0223) 		{
(0224) 			*(BufferPtr) = DF_SPI_RW(0x00);		//read byte and put it in AVR buffer pointed to by *BufferPtr
    02B3 2700      CLR	R16
    02B4 DF4C      RCALL	_DF_SPI_RW
    02B5 01FB      MOVW	R30,R22
    02B6 8300      STD	Z+0,R16
(0225) 			BufferPtr++;						//point to next element in AVR buffer
    02B7 5F6F      SUBI	R22,0xFF
    02B8 4F7F      SBCI	R23,0xFF
    02B9 5F4F      SUBI	R20,0xFF
    02BA 4F5F      SBCI	R21,0xFF
    02BB 154A      CP	R20,R10
    02BC 055B      CPC	R21,R11
    02BD F3A8      BCS	0x02B3
(0226) 		}
(0227) 	}
    02BE C01D      RJMP	0x02DC
(0228) 	else
(0229) 	if (2 == BufferNo)							//read byte(s) from buffer 2
    02BF 2D8E      MOV	R24,R14
    02C0 3082      CPI	R24,2
    02C1 F4D1      BNE	0x02DC
(0230) 	{
(0231) 		DF_SPI_RW(Buf2Read);					//buffer 2 read op-code
    02C2 E506      LDI	R16,0x56
    02C3 DF3D      RCALL	_DF_SPI_RW
(0232) 		DF_SPI_RW(0x00);						//don't cares
    02C4 2700      CLR	R16
    02C5 DF3B      RCALL	_DF_SPI_RW
(0233) 		DF_SPI_RW((unsigned char)(IntPageAdr>>8));//upper part of internal buffer address
    02C6 0186      MOVW	R16,R12
    02C7 2F01      MOV	R16,R17
    02C8 2711      CLR	R17
    02C9 DF37      RCALL	_DF_SPI_RW
(0234) 		DF_SPI_RW((unsigned char)(IntPageAdr));	//lower part of internal buffer address
    02CA 2D0C      MOV	R16,R12
    02CB DF35      RCALL	_DF_SPI_RW
(0235) 		DF_SPI_RW(0x00);						//don't cares
    02CC 2700      CLR	R16
    02CD DF33      RCALL	_DF_SPI_RW
(0236) 		for( i=0; i<No_of_bytes; i++)
    02CE 2744      CLR	R20
    02CF 2755      CLR	R21
    02D0 C008      RJMP	0x02D9
(0237) 		{
(0238) 			*(BufferPtr) = DF_SPI_RW(0x00);		//read byte and put it in AVR buffer pointed to by *BufferPtr
    02D1 2700      CLR	R16
    02D2 DF2E      RCALL	_DF_SPI_RW
    02D3 01FB      MOVW	R30,R22
    02D4 8300      STD	Z+0,R16
(0239) 			BufferPtr++;						//point to next element in AVR buffer
    02D5 5F6F      SUBI	R22,0xFF
    02D6 4F7F      SBCI	R23,0xFF
    02D7 5F4F      SUBI	R20,0xFF
    02D8 4F5F      SBCI	R21,0xFF
    02D9 154A      CP	R20,R10
    02DA 055B      CPC	R21,R11
    02DB F3A8      BCS	0x02D1
(0240) 		}
(0241) 	}
    02DC 940E04D3  CALL	pop_gset5
    02DE 9508      RET
_Buffer_Write_Enable:
  IntPageAdr           --> R20
  BufferNo             --> R22
    02DF 940E04DC  CALL	push_gset2
    02E1 01A9      MOVW	R20,R18
    02E2 2F60      MOV	R22,R16
(0242) }
(0243) //NB : Sjekk at (IntAdr + No_of_bytes) < buffersize, hvis ikke blir det bare ball..
(0244) 
(0245) 
(0246) 
(0247) /*****************************************************************************
(0248) *
(0249) *	Function name : Buffer_Write_Enable
(0250) *
(0251) *	Returns :		None
(0252) *
(0253) *	Parameters :	IntPageAdr	->	Internal page address to start writing from
(0254) *					BufferAdr	->	Decides usage of either buffer 1 or 2
(0255) *					
(0256) *	Purpose :		Enables continous write functionality to one of the dataflash buffers
(0257) *					buffers. NOTE : User must ensure that CS goes high to terminate
(0258) *					this mode before accessing other dataflash functionalities 
(0259) *
(0260) ******************************************************************************/
(0261) void Buffer_Write_Enable (unsigned char BufferNo, unsigned int IntPageAdr)
(0262) {
(0263) 	DF_CS_inactive;								//make sure to toggle CS signal in order
    02E3 9A96      SBI	0x12,6
(0264) 	DF_CS_active;								//to reset dataflash command decoder
    02E4 9896      CBI	0x12,6
(0265) 	
(0266) 	if (1 == BufferNo)							//write enable to buffer 1
    02E5 3061      CPI	R22,1
    02E6 F459      BNE	0x02F2
(0267) 	{
(0268) 		DF_SPI_RW(Buf1Write);					//buffer 1 write op-code
    02E7 E804      LDI	R16,0x84
    02E8 DF18      RCALL	_DF_SPI_RW
(0269) 		DF_SPI_RW(0x00);						//don't cares
    02E9 2700      CLR	R16
    02EA DF16      RCALL	_DF_SPI_RW
(0270) 		DF_SPI_RW((unsigned char)(IntPageAdr>>8));//upper part of internal buffer address
    02EB 018A      MOVW	R16,R20
    02EC 2F01      MOV	R16,R17
    02ED 2711      CLR	R17
    02EE DF12      RCALL	_DF_SPI_RW
(0271) 		DF_SPI_RW((unsigned char)(IntPageAdr));	//lower part of internal buffer address
    02EF 2F04      MOV	R16,R20
    02F0 DF10      RCALL	_DF_SPI_RW
(0272) 	}
    02F1 C00C      RJMP	0x02FE
(0273) 	else
(0274) 	if (2 == BufferNo)							//write enable to buffer 2
    02F2 3062      CPI	R22,2
    02F3 F451      BNE	0x02FE
(0275) 	{
(0276) 		DF_SPI_RW(Buf2Write);					//buffer 2 write op-code
    02F4 E807      LDI	R16,0x87
    02F5 DF0B      RCALL	_DF_SPI_RW
(0277) 		DF_SPI_RW(0x00);						//don't cares
    02F6 2700      CLR	R16
    02F7 DF09      RCALL	_DF_SPI_RW
(0278) 		DF_SPI_RW((unsigned char)(IntPageAdr>>8));//upper part of internal buffer address
    02F8 018A      MOVW	R16,R20
    02F9 2F01      MOV	R16,R17
    02FA 2711      CLR	R17
    02FB DF05      RCALL	_DF_SPI_RW
(0279) 		DF_SPI_RW((unsigned char)(IntPageAdr));	//lower part of internal buffer address
    02FC 2F04      MOV	R16,R20
    02FD DF03      RCALL	_DF_SPI_RW
(0280) 	}
    02FE 940E04CA  CALL	pop_gset2
    0300 9508      RET
_Buffer_Write_Byte:
  Data                 --> Y+4
  IntPageAdr           --> R20
  BufferNo             --> R22
    0301 940E04DC  CALL	push_gset2
    0303 01A9      MOVW	R20,R18
    0304 2F60      MOV	R22,R16
(0281) }
(0282) 
(0283) 
(0284) 
(0285) /*****************************************************************************
(0286) *
(0287) *	Function name : Buffer_Write_Byte
(0288) *
(0289) *	Returns :		None
(0290) *
(0291) *	Parameters :	IntPageAdr	->	Internal page address to write byte to
(0292) *					BufferAdr	->	Decides usage of either buffer 1 or 2
(0293) *					Data		->	Data byte to be written
(0294) *
(0295) *	Purpose :		Writes one byte to one of the dataflash
(0296) *					internal SRAM buffers
(0297) *
(0298) ******************************************************************************/
(0299) void Buffer_Write_Byte (unsigned char BufferNo, unsigned int IntPageAdr, unsigned char Data)
(0300) {
(0301) 	
(0302) 	DF_CS_inactive;								//make sure to toggle CS signal in order
    0305 9A96      SBI	0x12,6
(0303) 	DF_CS_active;								//to reset dataflash command decoder
    0306 9896      CBI	0x12,6
(0304) 	
(0305) 	if (1 == BufferNo)							//write byte to buffer 1
    0307 3061      CPI	R22,1
    0308 F469      BNE	0x0316
(0306) 	{
(0307) 		DF_SPI_RW(Buf1Write);					//buffer 1 write op-code
    0309 E804      LDI	R16,0x84
    030A DEF6      RCALL	_DF_SPI_RW
(0308) 		DF_SPI_RW(0x00);						//don't cares
    030B 2700      CLR	R16
    030C DEF4      RCALL	_DF_SPI_RW
(0309) 		DF_SPI_RW((unsigned char)(IntPageAdr>>8));//upper part of internal buffer address
    030D 018A      MOVW	R16,R20
    030E 2F01      MOV	R16,R17
    030F 2711      CLR	R17
    0310 DEF0      RCALL	_DF_SPI_RW
(0310) 		DF_SPI_RW((unsigned char)(IntPageAdr));	//lower part of internal buffer address
    0311 2F04      MOV	R16,R20
    0312 DEEE      RCALL	_DF_SPI_RW
(0311) 		DF_SPI_RW(Data);						//write data byte
    0313 810C      LDD	R16,Y+4
    0314 DEEC      RCALL	_DF_SPI_RW
(0312) 	}
    0315 C00E      RJMP	0x0324
(0313) 	else
(0314) 	if (2 == BufferNo)							//write byte to buffer 2
    0316 3062      CPI	R22,2
    0317 F461      BNE	0x0324
(0315) 	{
(0316) 		DF_SPI_RW(Buf2Write);					//buffer 2 write op-code
    0318 E807      LDI	R16,0x87
    0319 DEE7      RCALL	_DF_SPI_RW
(0317) 		DF_SPI_RW(0x00);						//don't cares
    031A 2700      CLR	R16
    031B DEE5      RCALL	_DF_SPI_RW
(0318) 		DF_SPI_RW((unsigned char)(IntPageAdr>>8));//upper part of internal buffer address
    031C 018A      MOVW	R16,R20
    031D 2F01      MOV	R16,R17
    031E 2711      CLR	R17
    031F DEE1      RCALL	_DF_SPI_RW
(0319) 		DF_SPI_RW((unsigned char)(IntPageAdr));	//lower part of internal buffer address
    0320 2F04      MOV	R16,R20
    0321 DEDF      RCALL	_DF_SPI_RW
(0320) 		DF_SPI_RW(Data);						//write data byte
    0322 810C      LDD	R16,Y+4
    0323 DEDD      RCALL	_DF_SPI_RW
(0321) 	}		
    0324 940E04CA  CALL	pop_gset2
    0326 9508      RET
_Buffer_Write_Str:
  i                    --> R20
  BufferPtr            --> R22
  No_of_bytes          --> R10
  IntPageAdr           --> R12
  BufferNo             --> R14
    0327 940E04D6  CALL	push_gset5
    0329 0169      MOVW	R12,R18
    032A 2EE0      MOV	R14,R16
    032B 84AA      LDD	R10,Y+10
    032C 84BB      LDD	R11,Y+11
    032D 856C      LDD	R22,Y+12
    032E 857D      LDD	R23,Y+13
(0322) }
(0323) 
(0324) 
(0325) /*****************************************************************************
(0326) *
(0327) *	Function name : Buffer_Write_Str
(0328) *
(0329) *	Returns :		None
(0330) *
(0331) *	Parameters :	BufferNo	->	Decides usage of either buffer 1 or 2
(0332) *					IntPageAdr	->	Internal page address
(0333) *					No_of_bytes	->	Number of bytes to be written
(0334) *					*BufferPtr	->	address of buffer to be used for copy of bytes
(0335) *									from AVR buffer to dataflash buffer 1 (or 2)
(0336) *
(0337) *	Purpose :		Copies one or more bytes to one of the dataflash
(0338) *					internal SRAM buffers from AVR SRAM buffer
(0339) *					pointed to by *BufferPtr
(0340) *
(0341) ******************************************************************************/
(0342) void Buffer_Write_Str (unsigned char BufferNo, unsigned int IntPageAdr, unsigned int No_of_bytes, unsigned char *BufferPtr)
(0343) {
(0344) 	unsigned int i;
(0345) 
(0346) 	DF_CS_inactive;								//make sure to toggle CS signal in order
    032F 9A96      SBI	0x12,6
(0347) 	DF_CS_active;								//to reset dataflash command decoder
    0330 9896      CBI	0x12,6
(0348) 	
(0349) 	if (1 == BufferNo)							//write byte(s) to buffer 1
    0331 2D8E      MOV	R24,R14
    0332 3081      CPI	R24,1
    0333 F4C1      BNE	0x034C
(0350) 	{
(0351) 		DF_SPI_RW(Buf1Write);					//buffer 1 write op-code
    0334 E804      LDI	R16,0x84
    0335 DECB      RCALL	_DF_SPI_RW
(0352) 		DF_SPI_RW(0x00);						//don't cares
    0336 2700      CLR	R16
    0337 DEC9      RCALL	_DF_SPI_RW
(0353) 		DF_SPI_RW((unsigned char)(IntPageAdr>>8));//upper part of internal buffer address
    0338 0186      MOVW	R16,R12
    0339 2F01      MOV	R16,R17
    033A 2711      CLR	R17
    033B DEC5      RCALL	_DF_SPI_RW
(0354) 		DF_SPI_RW((unsigned char)(IntPageAdr));	//lower part of internal buffer address
    033C 2D0C      MOV	R16,R12
    033D DEC3      RCALL	_DF_SPI_RW
(0355) 		for( i=0; i<No_of_bytes; i++)
    033E 2744      CLR	R20
    033F 2755      CLR	R21
    0340 C007      RJMP	0x0348
(0356) 		{
(0357) 			DF_SPI_RW(BufferPtr[i]);			//write byte pointed at by *BufferPtr to dataflash buffer 1 location
    0341 01FA      MOVW	R30,R20
    0342 0FE6      ADD	R30,R22
    0343 1FF7      ADC	R31,R23
    0344 8100      LDD	R16,Z+0
    0345 DEBB      RCALL	_DF_SPI_RW
    0346 5F4F      SUBI	R20,0xFF
    0347 4F5F      SBCI	R21,0xFF
    0348 154A      CP	R20,R10
    0349 055B      CPC	R21,R11
    034A F3B0      BCS	0x0341
(0358) 			//BufferPtr++;						//point to next element in AVR buffer
(0359) 		}
(0360) 	}
    034B C01A      RJMP	0x0366
(0361) 	else
(0362) 	if (2 == BufferNo)							//write byte(s) to buffer 2
    034C 2D8E      MOV	R24,R14
    034D 3082      CPI	R24,2
    034E F4B9      BNE	0x0366
(0363) 	{
(0364) 		DF_SPI_RW(Buf2Write);					//buffer 2 write op-code
    034F E807      LDI	R16,0x87
    0350 DEB0      RCALL	_DF_SPI_RW
(0365) 		DF_SPI_RW(0x00);						//don't cares
    0351 2700      CLR	R16
    0352 DEAE      RCALL	_DF_SPI_RW
(0366) 		DF_SPI_RW((unsigned char)(IntPageAdr>>8));//upper part of internal buffer address
    0353 0186      MOVW	R16,R12
    0354 2F01      MOV	R16,R17
    0355 2711      CLR	R17
    0356 DEAA      RCALL	_DF_SPI_RW
(0367) 		DF_SPI_RW((unsigned char)(IntPageAdr));	//lower part 

⌨️ 快捷键说明

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