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

📄 sst25vf016b_soft.c

📁 SST25VF016B_SOFT.C.H.rar
💻 C
📖 第 1 页 / 共 2 页
字号:
	}
	CE =1;				/* 禁止芯片 */
}
/************************************************************************/
/* 名称: HighSpeed_Read						*/	
/* 功能: 高速读取一个字节  */
/* 输入: Dst(目标地址 000000H - 1FFFFFH)		*/
/* 返回: byte							*/
/************************************************************************/
uchar HighSpeed_Read(ulong Dst) 
{
	uchar byte = 0;	
	CE =0;			/*  使能芯片  */
	Send_Byte(0x0B); 		/* 发送指令 */
	Send_Byte(((Dst & 0xFFFFFF) >> 16));	/* 发送3字节的地址*/
	Send_Byte(((Dst & 0xFFFF) >> 8));
	Send_Byte(Dst & 0xFF);
	Send_Byte(0xFF);		/*虚拟字节*/
	byte = Get_Byte();
	CE =1;			/* 禁止芯片 */
	return byte;			/* 返回读取的一个字节 */
}
/************************************************************************/
/* 名称:  HighSpeed_Read_Cont					*/
/* 功能:  高速读取芯片连续地址的内容,最大可读取128字节	*/
/* 输入:  Dst:(目标地址 000000H - 1FFFFFH)*/
/*        no_bytes:	读取字节数	(最大128字节)	*/
/* 返回:  Nothing							*/
/************************************************************************/
void HighSpeed_Read_Cont(ulong Dst, ulong no_bytes)
{
	ulong i = 0;
	CE =0;				/* 芯片使能 */
	Send_Byte(0x0B); 			/* 发送读取指令 */
	Send_Byte(((Dst & 0xFFFFFF) >> 16)); 	/* 发送3字节的地址 */
	Send_Byte(((Dst & 0xFFFF) >> 8));
	Send_Byte(Dst & 0xFF);
	Send_Byte(0xFF);			/*虚拟字节*/
	for (i = 0; i < no_bytes; i++)		/* 读取no_bytes字节*/
	{
		upper_128[i] = Get_Byte();	/*接收数据存入 80H - FFH */
	}
	CE =1;				/* 禁止芯片*/
}
/************************************************************************/
/* 名称: Byte_Program						*/
/* 功能: 写一个字节数据,被写的地址必须被擦除及未被保护		*/				
/* 输入:								*/
/*		Dst:		(目标地址 000000H - 1FFFFFH)	*/
/*		byte:		数据			*/
/* 返回:								*/
/*		Nothing							*/
/************************************************************************/
void Byte_Program(ulong Dst, uchar byte)
{
	CE =0;				/* 芯片使能 */
//	WREN_Check();
	Send_Byte(0x02); 			/* 发送写操作指令 */
	Send_Byte(((Dst & 0xFFFFFF) >> 16));	/* 发送3字节地址 */
	Send_Byte(((Dst & 0xFFFF) >> 8));
	Send_Byte(Dst & 0xFF);
	Send_Byte(byte);			/*发送要写的数据*/
//	Wait_Busy();
	CE =1;				
}
/************************************************************************/
/* 名称: Auto_Add_IncA		 				*/
/* 功能: 写连续地址*/
/* 输入:								*/
/*		Dst:	  (目标地址 000000H - 1FFFFFH)		*/
/*		byte1:		第1字节数据	*/
/*      byte1:		第2字节数据	 */
/* 返回:								*/
/*		Nothing							*/
/************************************************************************/
void Auto_Add_IncA(ulong Dst, uchar byte1, uchar byte2)
{
	CE =0;				
	Send_Byte(0xAD);			/* 发送AAI命令*/
	Send_Byte(((Dst & 0xFFFFFF) >> 16)); 	/* 发送地址*/
	Send_Byte(((Dst & 0xFFFF) >> 8));
	Send_Byte(Dst & 0xFF);
	Send_Byte(byte1);			/* 发送第一个字节 */	
	Send_Byte(byte2);			/* 发送第二个字节 */
	CE =1;			
}
/************************************************************************/
/* 名称: 工作Auto_Add_IncB						*/
/* 功能: 连续写入2字节,使用在Auto_Address_IncA之后 					*/
/*       进入AAI模式后仅WRDI及AAI操作指令能被执行,因为SO作为RY/BY#状态输出.*/
/* 输入:								*/
/*		byte1:		1st byte to be programmed		*/
/*		byte2:		2nd byte to be programmed		*/
/* 返回:								*/
/*		Nothing							*/
/************************************************************************/
void Auto_Add_IncB(uchar byte1, uchar byte2)
{
	CE =0;			 
	Send_Byte(0xAD);			/* 发送AAI命令*/
	Send_Byte(byte1);			/* 发送第一个字节 */
	Send_Byte(byte2);			/* 发送第二个字节*/
	CE =1;			
}
/************************************************************************/
/*名称:	Auto_Add_IncA_EBSY					*/
/*功能: 像Auto_Add_IncA一样使用EBSY 和Poll_SO  检查RY/BY.	*/
/*输入:								*/
/*		Dst:		(目标地址 000000H - 1FFFFFH)	*/
/*		byte1,	 byte1;		*/
/*返回:								*/
/*		Nothing							*/
/************************************************************************/
void Auto_Add_IncA_EBSY(ulong Dst, uchar byte1, uchar byte2)
{
	EBSY();					/* 使用SO作为RY/BY#状态输出 */	
	CE =0;				/* 使能芯片 */
	Send_Byte(0xAD);			/* 发送AAI命令*/
	Send_Byte(((Dst & 0xFFFFFF) >> 16)); 	/* 发送地址*/
	Send_Byte(((Dst & 0xFFFF) >> 8));
	Send_Byte(Dst & 0xFF);
	Send_Byte(byte1);			/* 发送第一个字节 */	
	Send_Byte(byte2);			/* 发送第二个字节*/
	CE =1;			
	Poll_SO();				/* 使用SO作为RY/BY#输出*/
}
/************************************************************************/
/* 名称:	Auto_Add_IncB_EBSY					*/
/* 功能: 
/* 输入:								*/
/*		byte1,byte2		*/
/* 返回:								*/
/*		Nothing							*/
/************************************************************************/
void Auto_Add_IncB_EBSY(uchar byte1, uchar byte2)
{
	CE =0;			
	Send_Byte(0xAD);			/* 发送AAI命令 */
	Send_Byte(byte1);			/* 发送第一个字节 */
	Send_Byte(byte2);			/* 发送第二个字节 */
	CE =1;			
	Poll_SO();				/* 用SO传送RY/BY#   */
	WRDI(); 				/* 在DBSY前退出 */
	DBSY();					/* 在AAI下禁止 SO 作为RY/BY#输出*/
}
/************************************************************************/
/* 名称: Chip_Erase						*/
/* 功能: 擦除整个芯片				*/
/* 输入:		None							*/
/* 返回:		Nothing							*/
/************************************************************************/
void Chip_Erase()
{						
	WREN_Check();
	CE =0;			
	Send_Byte(0x60);			/* 发送 Chip Erase命令 (60h or C7h) */
	CE =1;
	Wait_Busy();
	//CE =1;			
}
/************************************************************************/
/* 名称: Sector_Erase						*/
/* 功能: Sector Erases the Chip.				*/
/* 输入:		Dst:		目标地址000000H - 1FFFFFH	*/
/* 返回:		Nothing							*/
/************************************************************************/
void Sector_Erase(ulong Dst)
{
	uchar i;
	WREN_Check();
	init();
	CE =0;				
	Send_Byte(0x20);			/* 发送Sector Erase 命令 */
	Send_Byte(((Dst & 0xFFFFFF) >> 16)); 	/* 发送地址 */
	Send_Byte(((Dst & 0xFFFF) >> 8));
	Send_Byte(Dst & 0xFF);
	for(i=100;i>0;i--);
	CE =1;
	Wait_Busy();			
}
/************************************************************************/
/* 名称: Block_Erase_32K						*/
/* 功能: Block Erases 32 KByte of the Chip.			*/
/* 输入:		Dst:		目标地址 000000H - 1FFFFFH	*/
/* 返回:		Nothing							*/
/************************************************************************/
void Block_Erase_32K(ulong Dst)
{
	WREN_Check();
	CE =0;				
	Send_Byte(0x52);			/* 发送32 KByte Block Erase命令*/
	Send_Byte(((Dst & 0xFFFFFF) >> 16)); 	/* 发送3bytes地址*/
	Send_Byte(((Dst & 0xFFFF) >> 8));
	Send_Byte(Dst & 0xFF);
	CE =1;
	Wait_Busy();		
}
/************************************************************************/
/* 名称: Block_Erase_64K						*/
/* 功能: Block Erases 64 KByte	*/
/* 输入:		Dst:		目标地址000000H - 1FFFFFH	*/
/* 返回:		Nothing							*/
/************************************************************************/
void Block_Erase_64K(ulong Dst)
{
	WREN_Check();
	CE =0;			
	Send_Byte(0xD8);			/* 发送64KByte Block Erase 命令 */
	Send_Byte(((Dst & 0xFFFFFF) >> 16)); 	/* 发送3 bytes地址 */
	Send_Byte(((Dst & 0xFFFF) >> 8));
	Send_Byte(Dst & 0xFF);
	CE =1;
	Wait_Busy();		
}
/************************************************************************/
/* 名称: Wait_Busy							*/
/* 功能: 等待芯片空闲(在执行Byte-Program, Sector-Erase, Block-Erase, Chip-Erase操作后)*/
/* 输入:		None							*/
/* 返回:		Nothing							*/
/************************************************************************/
void Wait_Busy()
{
	while ((Read_Status_Register())&0x01 == 0x01)	/* waste time until not busy */
		Read_Status_Register();
}
/************************************************************************/
/* 名称: Wait_Busy_AAI						*/
/* 功能:  在AAI模式下等待芯片空闲	*/
/* 输入:		None							*/
/* 返回:		Nothing							*/
/************************************************************************/
void Wait_Busy_AAI()
{
	while (Read_Status_Register() == 0x43)	/* 等待空闲 */
		Read_Status_Register();
}
/************************************************************************/
/* 名称: WREN_Check						*/
/* 功能: 检查擦写操作前WEL位是否为1	*/
/* 输入:		None							*/
/* 返回:		Nothing							*/
/************************************************************************/
void WREN_Check()
{
	uchar byte;
	byte = Read_Status_Register();	/* 读取状态register */
	if ((byte&0x02) != 0x02)		/* 检查WEL位置位 */
	{
		WREN();
			//如果未置1进行相应处理,如对其进行写使得操作
	}
}
/************************************************************************/
/* 名称: WREN_AAI_Check						*/
/* 功能: 在AAI模式下检查AAI和WEL位	*/
/************************************************************************/
void WREN_AAI_Check()
{
	uchar byte;
	byte = Read_Status_Register();	/*读取状态寄存器*/
	if (byte != 0x42)		/* 核实AAI 和 WEL位被置1 */
	{
		while(1);		
				/*如果发生错误进行相应处理*/
	}
}
/************************************************************************/
/* 名称: Verify							*/
/* 功能: 检查是否读取正确	*/
/* 输入:								*/
/*		byte:		byte read				*/
/*		cor_byte:	应被读取的字节	*/
/* 返回:								*/
/*		Nothing							*/
/************************************************************************/
void Verify(uchar byte, uchar cor_byte)
{
	if (byte != cor_byte)
	{
		while(1); 
			/*加入显示错误 */
	}
}
void SPI_ISR() interrupt 6
{
	if(WCOL){WCOL =0;}  //写冲突
	if(MODF){P5 &=0x7f;MODF =0;}  //模式错误
	if(RXOVRN){;};
	SPIF=0;
}

⌨️ 快捷键说明

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