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

📄 at45db041b.c

📁 C语言写的关于AT45DB041B存储芯片的51驱动程序,压缩包内还有AT45DB041B存储芯片的说明书,以及芯片和51单片机的连接方式.
💻 C
📖 第 1 页 / 共 2 页
字号:
    	case 1 : SPI_HostWriteByte(Buffer1_To_MainMemory_PageProgram_WithBuilt_inErase);//#define Buffer1_To_MainMemory_PageProgram_WithBuilt_inErase x083
			break; 
    	case 2 : SPI_HostWriteByte(Buffer2_To_MainMemory_PageProgram_WithBuilt_inErase);//#define Buffer2_To_MainMemory_PageProgram_WithBuilt_inErase x086
			break; 
  	} 
  	SPI_HostWriteByte((unsigned char)(PA >> 7)); 
    SPI_HostWriteByte((unsigned char)(PA << 1)); 
  	SPI_HostWriteByte(0x00);
    for(i = 0; i < len; i++) {
		SPI_HostWriteByte(pHeader[i]);
	}
  	SPI_CS = 1; 
} 

/****************************************************************************** 
描述:                                                
   与上一个函数的唯一区别是不带预擦除。                          
/******************************************************************************/ 
void AT45DB041B_BufferToMainMemoryPageProgramWithoutBuilt_inErase(UCHAR buffer, UINT PA, UINT BFA, UCHAR *pHeader, UINT len){ 
  	unsigned int i = 0; 
  	AT45DB041B_BufferWrite(buffer, BFA, pHeader, len); 
  	while(i++ < 1000) { 
		if(AT45DB041B_StatusRegisterRead() & 0x80) {
			break;
		}
	} 
  	SPI_CS = 0; 
  	SPI_HostWriteByte(0x87 + buffer);//当buffer=1,则写入0x88命令.当buffer=2则写入0x89命令,效果和下面注释代码功能一样 
	/*switch(buffer){ 
    	case 1 : SPI_HostWriteByte(Buffer1_To_MainMemory_PageProgram_WithoutBuilt_inErase);//#define Buffer1_To_MainMemory_PageProgram_WithoutBuilt_inErase x088
			break; 
    	case 2 : SPI_HostWriteByte(Buffer2_To_MainMemory_PageProgram_WithoutBuilt_inErase);//#define Buffer2_To_MainMemory_PageProgram_WithoutBuilt_inErase x089
			break; 
  	}*/ 
  	SPI_HostWriteByte((unsigned char)(PA >> 7)); 
  	SPI_HostWriteByte((unsigned char)(PA << 1)); 
  	SPI_HostWriteByte(0x00); 
  	for(i = 0; i < len; i++) {
		SPI_HostWriteByte(pHeader[i]);
	} 
  	SPI_CS = 1; 
} 

/****************************************************************************** 
描述:                                               
	When a low-to-high transition occurs on the /C/S pin,the part will erase the
   	selected page to 1s.The erase operation is internally self-timed and should
   	take place in a maximum time of tPE.During this time,the status register will
   	indicate that the part is busy.                             
参数:                                                             
   	PA     - 页地址,0~2047                                                                  
/******************************************************************************/
void AT45DB041B_PageErase(UINT PA) {
	unsigned int i = 0; 
  	while(i++ < 255) {
		if(AT45DB041B_StatusRegisterRead() & 0x80) { 
			break;
		}
	} 
  	SPI_CS = 0;	
	SPI_HostWriteByte(Page_Erase);
	SPI_HostWriteByte((unsigned char)(PA >> 7));//页地址高4位和4为无关位
	SPI_HostWriteByte((unsigned char)(PA << 1));//页地址低7位和1位无关位
	SPI_HostWriteByte(0x00);//8位无关位
	SPI_CS = 1;
	while(!(AT45DB041B_StatusRegisterRead() & 0x80));//等待擦除完毕
}

/****************************************************************************** 
描述:                                               
	When a low-to-high transition occurs on the /C/S pin,the part will erase the
   	selected block of eight pages to 1s.The erase operation is internally self-t-
	imed and should take place in a maximum time of tBE.During this time,the sta-
	tus register will indicate that the part is busy.                             
参数:                                                             
   	BLKA     - 块地址,0~255                                                                  
/******************************************************************************/
void AT45DB041B_BlockErase(UCHAR BLKA) {
	unsigned int i = 0; 
  	while(i++ < 255) {
		if(AT45DB041B_StatusRegisterRead() & 0x80) { 
			break;
		}
	} 
  	SPI_CS = 0;	
	SPI_HostWriteByte(Block_Erase);
	SPI_HostWriteByte((unsigned char)(BLKA >> 4));//块地址高4位和4为无关位
	SPI_HostWriteByte((unsigned char)(BLKA << 4));//块地址低4位和4位无关位
	SPI_HostWriteByte(0x00);//8位无关位
	SPI_CS = 1;
	while(!(AT45DB041B_StatusRegisterRead() & 0x80));//等待擦除完毕
}

/****************************************************************************** 
描述:                                               
	When a low-to-high transition occurs on the /C/S pin,the part will erase the
   	selected block of eight pages to 1s.The erase operation is internally self-t-
	imed and should take place in a maximum time of tBE.During this time,the sta-
	tus register will indicate that the part is busy.                             
参数:                                                             
   	buffer     - 选择BUFFER,01H选择BUFFER1,02H选择BUFFER2
    PA		- 页地址,0~2047                                                              
/******************************************************************************/
void AT45DB041B_MainMemoryPageToBufferTransfer(UCHAR buffer, UINT PA) {
	unsigned int i = 0; 
  	while(i++ < 255) {
		if(AT45DB041B_StatusRegisterRead() & 0x80) { 
			break;
		}
	} 
  	SPI_CS = 0;
	switch(buffer){ 
    	case 1 : SPI_HostWriteByte(Main_Memory_Page_To_Buffer1_Transfer);
			break; 
    	case 2 : SPI_HostWriteByte(Main_Memory_Page_To_Buffer2_Transfer);
			break; 
  	}
    SPI_HostWriteByte((unsigned char)(PA >> 7)); 
    SPI_HostWriteByte((unsigned char)(PA << 1)); 
  	SPI_HostWriteByte(0x00);
	SPI_CS = 1;
	while(!(AT45DB041B_StatusRegisterRead() & 0x80));//等待传送完毕
}

/****************************************************************************** 
描述:                                               
	When a low-to-high transition occurs on the /C/S pin,the part will erase the
   	selected block of eight pages to 1s.The erase operation is internally self-t-
	imed and should take place in a maximum time of tBE.During this time,the sta-
	tus register will indicate that the part is busy.                             
参数:                                                             
   	buffer     - 选择BUFFER,01H选择BUFFER1,02H选择BUFFER2
    PA		- 页地址,0~2047                                                              
/******************************************************************************/
UCHAR AT45DB041B_MainMemoryPageToBufferCompare(UCHAR buffer, UINT PA) {
	unsigned int i = 0; 
  	while(i++ < 255) {
		if(AT45DB041B_StatusRegisterRead() & 0x80) { 
			break;
		}
	} 
  	SPI_CS = 0;
	switch(buffer){ 
    	case 1 : SPI_HostWriteByte(Main_Memory_Page_To_Buffer1_Compare);
			break; 
    	case 2 : SPI_HostWriteByte(Main_Memory_Page_To_Buffer2_Compare);
			break; 
  	}
	SPI_HostWriteByte((unsigned char)(PA >> 7)); 
    SPI_HostWriteByte((unsigned char)(PA << 1)); 
  	SPI_HostWriteByte(0x00);
	SPI_CS = 1;
	while(!(AT45DB041B_StatusRegisterRead() & 0x80));
	return(((AT45DB041B_StatusRegisterRead() & 0x40) ? 0 : 1));//返回比较结果,if StatusRegister's bit6 is 0,then match, is 1,then not match
}

/****************************************************************************** 
描述:                                               
	When a low-to-high transition occurs on the /C/S pin,the part will erase the
   	selected block of eight pages to 1s.The erase operation is internally self-t-
	imed and should take place in a maximum time of tBE.During this time,the sta-
	tus register will indicate that the part is busy.                             
参数:                                                             
   	buffer  - 选择BUFFER,01H选择BUFFER1,02H选择BUFFER2
    PA		- 页地址,0~2047 
    BFA     - buffer地址,0~263
    pHeader - 待写入数据的首地址
    len     - 写入数据的长度                                                 
/******************************************************************************/
void AT45DB041B_MainMemoryPageProgramThroughBuffer(UCHAR buffer, UINT PA, UINT BFA, UCHAR *pHeader, UINT len) { 
  	unsigned int i = 0; 
  	AT45DB041B_BufferWrite(buffer, BFA, pHeader, len); 
 	while(i++ < 1000) {
		if(AT45DB041B_StatusRegisterRead() & 0x80) {
			break;
		}
	} 
    SPI_CS = 0;       
  	switch(buffer){ 
    	case 1 : SPI_HostWriteByte(Main_Memory_Page_Program_Through_Buffer1);
			break; 
    	case 2 : SPI_HostWriteByte(Main_Memory_Page_Program_Through_Buffer2);
			break; 
  	}
	SPI_HostWriteByte((unsigned char)(PA >> 7)); 
    SPI_HostWriteByte((unsigned char)(PA << 1 | BFA >> 8)); 
  	SPI_HostWriteByte((unsigned char)BFA);
    for(i = 0; i < len; i++) {
		SPI_HostWriteByte(pHeader[i]);
	}
  	SPI_CS = 1;
}

/****************************************************************************** 
描述:                                               
	When a low-to-high transition occurs on the /C/S pin,the part will erase the
   	selected block of eight pages to 1s.The erase operation is internally self-t-
	imed and should take place in a maximum time of tBE.During this time,the sta-
	tus register will indicate that the part is busy.                             
参数:                                                             
   	buffer  - 选择BUFFER,01H选择BUFFER1,02H选择BUFFER2
    PA		- 页地址,0~2047 
    BFA     - buffer地址,0~263
    pHeader - 待写入数据的首地址
    len     - 写入数据的长度                                                 
/******************************************************************************/
void AT45DB041B_AutoPageRewrite(UCHAR buffer, UINT PA) {
	unsigned int i = 0;
	AT45DB041B_MainMemoryPageToBufferTransfer(buffer, PA);
	while(i++ < 1000) { 
		if(AT45DB041B_StatusRegisterRead() & 0x80) {
			break;
		}
	}
	SPI_CS = 0;
	switch(buffer){ 
    	case 1 : SPI_HostWriteByte(Auto_Page_Rewrite_With_Buffer1);
			break; 
    	case 2 : SPI_HostWriteByte(Auto_Page_Rewrite_With_Buffer2);
			break; 
  	}
	SPI_HostWriteByte((unsigned char)(PA >> 7)); 
    SPI_HostWriteByte((unsigned char)(PA << 1)); 
  	SPI_HostWriteByte(0x00);
	SPI_CS = 1;
	while(!(AT45DB041B_StatusRegisterRead() & 0x80));
}

⌨️ 快捷键说明

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