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

📄 sst25lf020a.c

📁 SST25LF020A存储器SPI驱动程序
💻 C
📖 第 1 页 / 共 2 页
字号:
	unsigned char byte;	CE_Low();			/* enable device */	Send_Byte(0x90);		/* send read ID command (90h or ABh) */    	Send_Byte(0x00);		/* send address */	Send_Byte(0x00);		/* send address */	Send_Byte(ID_addr);		/* send address - either 00H or 01H */	byte = Get_Byte();		/* receive byte */	CE_High();			/* disable device */	return byte;}/************************************************************************//* PROCEDURE:	Read							*//*									*/		/* This procedure reads one address of the device.  It will return the 	*//* byte read in variable byte.						*//*									*//*									*//*									*//* Input:								*//*		Dst:	Destination Address 000000H - 03FFFFH		*//*      								*//*									*//* Returns:								*//*		byte							*//*									*//************************************************************************/unsigned char Read(unsigned long Dst) {	unsigned char byte = 0;		CE_Low();			/* enable device */	Send_Byte(0x03); 		/* read command */	Send_Byte(((Dst & 0xFFFFFF) >> 16));	/* send 3 address bytes */	Send_Byte(((Dst & 0xFFFF) >> 8));	Send_Byte(Dst & 0xFF);	byte = Get_Byte();	CE_High();			/* disable device */	return byte;			/* return one byte read */}/************************************************************************//* PROCEDURE:	Read_Cont						*//*									*/		/* This procedure reads multiple addresses of the device and stores	*//* data into 128 byte buffer. Maximum byte that can be read is 128 bytes*//*									*//* Input:								*//*		Dst:		Destination Address 000000H - 03FFFFH	*//*      	no_bytes	Number of bytes to read	(max = 128)	*//*									*//* Returns:								*//*		Nothing							*//*									*//************************************************************************/void Read_Cont(unsigned long Dst, unsigned long no_bytes){	unsigned long i = 0;	CE_Low();				/* enable device */	Send_Byte(0x03); 			/* read command */	Send_Byte(((Dst & 0xFFFFFF) >> 16)); 	/* send 3 address bytes */	Send_Byte(((Dst & 0xFFFF) >> 8));	Send_Byte(Dst & 0xFF);	for (i = 0; i < no_bytes; i++)		/* read until no_bytes is reached */	{		upper_128[i] = Get_Byte();	/* receive byte and store at address 80H - FFH */	}	CE_High();				/* disable device */}/************************************************************************//* PROCEDURE:	HighSpeed_Read						*//*									*/		/* This procedure reads one address of the device.  It will return the 	*//* byte read in variable byte.						*//*									*//*									*//*									*//* Input:								*//*		Dst:	Destination Address 000000H - 03FFFFH		*//*      								*//*									*//* Returns:								*//*		byte							*//*									*//************************************************************************/unsigned char HighSpeed_Read(unsigned long Dst) {	unsigned char byte = 0;		CE_Low();			/* enable device */	Send_Byte(0x0B); 		/* read command */	Send_Byte(((Dst & 0xFFFFFF) >> 16));	/* send 3 address bytes */	Send_Byte(((Dst & 0xFFFF) >> 8));	Send_Byte(Dst & 0xFF);	Send_Byte(0xFF);		/*dummy byte*/	byte = Get_Byte();	CE_High();			/* disable device */	return byte;			/* return one byte read */}/************************************************************************//* PROCEDURE:	HighSpeed_Read_Cont					*//*									*/		/* This procedure reads multiple addresses of the device and stores	*//* data into 128 byte buffer. Maximum byte that can be read is 128 bytes*//*									*//* Input:								*//*		Dst:		Destination Address 000000H - 03FFFFH	*//*      	no_bytes	Number of bytes to read	(max = 128)	*//*									*//* Returns:								*//*		Nothing							*//*									*//************************************************************************/void HighSpeed_Read_Cont(unsigned long Dst, unsigned long no_bytes){	unsigned long i = 0;	CE_Low();				/* enable device */	Send_Byte(0x0B); 			/* read command */	Send_Byte(((Dst & 0xFFFFFF) >> 16)); 	/* send 3 address bytes */	Send_Byte(((Dst & 0xFFFF) >> 8));       	Send_Byte(Dst & 0xFF);	Send_Byte(0xFF);			/*dummy byte*/	for (i = 0; i < no_bytes; i++)		/* read until no_bytes is reached */	{		upper_128[i] = Get_Byte();	/* receive byte and store at address 80H - FFH */	}	CE_High();				/* disable device */}/************************************************************************//* PROCEDURE:	Byte_Program						*//*									*//* This procedure programs one address of the device.			*//* Assumption:  Address being programmed is already erased and is NOT	*//*		block protected.					*//*									*//*									*//*									*//* Input:								*//*		Dst:		Destination Address 000000H - 03FFFFH	*//*		byte:		byte to be programmed			*//*      								*//*									*//* Returns:								*//*		Nothing							*//*									*//************************************************************************/void Byte_Program(unsigned long Dst, unsigned char byte){	CE_Low();				/* enable device */	Send_Byte(0x02); 			/* send Byte Program command */	Send_Byte(((Dst & 0xFFFFFF) >> 16));	/* send 3 address bytes */	Send_Byte(((Dst & 0xFFFF) >> 8));	Send_Byte(Dst & 0xFF);	Send_Byte(byte);			/* send byte to be programmed */	CE_High();				/* disable device */}/************************************************************************//* PROCEDURE:	Auto_Add_IncA						*//*									*//* This procedure programs consecutive addresses of the device.  This  	*//* is used to to start the AAI process.  It should be followed by 	*//* Auto_Add_IncB.							*//* Assumption:  Address being programmed is already erased and is NOT	*//*		block protected.					*//*									*//*									*//* Note: Only RDSR command can be executed once in AAI mode.	 	*//* 	 Use WRDI to exit AAI mode unless AAI is programming the last	*//*	 address or last address of unprotected block, which 		*//*	 automatically exits AAI mode.					*//*									*//* Input:								*//*		Dst:		Destination Address 000000H - 03FFFFH	*//*		byte:		byte to be programmed			*//*      								*//*									*//* Returns:								*//*		Nothing							*//*									*//************************************************************************/void Auto_Add_IncA(unsigned long Dst, unsigned char byte){		CE_Low();				/* enable device */	Send_Byte(0xAF);			/* send AAI command */	Send_Byte(((Dst & 0xFFFFFF) >> 16)); 	/* send 3 address bytes */	Send_Byte(((Dst & 0xFFFF) >> 8));	Send_Byte(Dst & 0xFF);	Send_Byte(byte);			/* send byte to be programmed */	CE_High();				/* disable device */}/************************************************************************//* PROCEDURE:	Auto_Add_IncB						*//*									*//* This procedure programs consecutive addresses of the device.  This  	*//* is used after Auto_Address_IncA.					*//* Assumption:  Address being programmed is already erased and is NOT	*//*		block protected.					*//*									*//* Note: Only RDSR command can be executed once in AAI mode.	 	*//* 	 Use WRDI to exit AAI mode unless AAI is programming the last	*//*	 address or last address of unprotected block, which 		*//*	 automatically exits AAI mode.					*//*									*//* Input:								*//*									*//*		byte:		byte to be programmed			*//*      								*//*									*//* Returns:								*//*		Nothing							*//*									*//************************************************************************/void Auto_Add_IncB(unsigned char byte){	CE_Low();				/* enable device */	Send_Byte(0xAF);			/* send AAI command */	Send_Byte(byte);			/* send byte to be programmed */	CE_High();				/* disable device */}/************************************************************************//* PROCEDURE: Chip_Erase						*//*									*//* This procedure erases the entire Chip.				*//*									*//* Input:								*//*		None							*//*									*//* Returns:								*//*		Nothing							*//************************************************************************/void Chip_Erase(){	CE_Low();				/* enable device */	Send_Byte(0x60);			/* send Chip Erase command */	CE_High();				/* disable device */}/************************************************************************//* PROCEDURE: Sector_Erase						*//*									*//* This procedure Sector Erases the Chip.				*//*									*//* Input:								*//*		Dst:		Destination Address 000000H - 03FFFFH	*//*									*//* Returns:								*//*		Nothing							*//************************************************************************/void Sector_Erase(unsigned long Dst){	CE_Low();				/* enable device */	Send_Byte(0x20);			/* send Sector Erase command */	Send_Byte(((Dst & 0xFFFFFF) >> 16)); 	/* send 3 address bytes */	Send_Byte(((Dst & 0xFFFF) >> 8));	Send_Byte(Dst & 0xFF);	CE_High();				/* disable device */}/************************************************************************//* PROCEDURE: Block_Erase						*//*									*//* This procedure Block Erases the Chip.				*//*									*//* Input:								*//*		Dst:		Destination Address 000000H - 03FFFFH	*//*									*//* Returns:								*//*		Nothing							*//************************************************************************/void Block_Erase(unsigned long Dst){	CE_Low();				/* enable device */	Send_Byte(0x52);			/* send Block Erase command */	Send_Byte(((Dst & 0xFFFFFF) >> 16)); 	/* send 3 address bytes */	Send_Byte(((Dst & 0xFFFF) >> 8));	Send_Byte(Dst & 0xFF);	CE_High();				/* disable device */}/************************************************************************//* PROCEDURE: Wait_Busy							*//*									*//* This procedure waits until device is no longer busy (can be used by	*//* Byte-Program, Sector-Erase, Block-Erase, Chip-Erase).		*//*									*//* Input:								*//*		None							*//*									*//* Returns:								*//*		Nothing							*//************************************************************************/void Wait_Busy(){	while (Read_Status_Register() == 0x03)	/* waste time until not busy */		Read_Status_Register();}/************************************************************************//* PROCEDURE: Wait_Busy_AAI						*//*									*//* This procedure waits until device is no longer busy for AAI mode.	*//*									*//* Input:								*//*		None							*//*									*//* Returns:								*//*		Nothing							*//************************************************************************/void Wait_Busy_AAI(){	while (Read_Status_Register() == 0x43)	/* waste time until not busy */		Read_Status_Register();}/************************************************************************//* PROCEDURE: WREN_Check						*//*									*//* This procedure checks to see if WEL bit set before program/erase.	*//*									*//* Input:								*//*		None							*//*									*//* Returns:								*//*		Nothing							*//************************************************************************/void WREN_Check(){	unsigned char byte;	byte = Read_Status_Register();	/* read the status register */	if (byte != 0x02)		/* verify that WEL bit is set */	{		while(1)			/* add source code or statements for this file */			/* to compile   			       */			/* i.e. option: insert a display to view error on LED? */	}}/************************************************************************//* PROCEDURE: WREN_AAI_Check						*//*									*//* This procedure checks for AAI and WEL bit once in AAI mode.		*//*									*//* Input:								*//*		None							*//*									*//* Returns:								*//*		Nothing							*//************************************************************************/void WREN_AAI_Check(){	unsigned char byte;	byte = Read_Status_Register();	/* read the status register */	if (byte != 0x42)		/* verify that AAI and WEL bit is set */	{		while(1)					/* add source code or statements for this file */			/* to compile   			       */			/* i.e. option: insert a display to view error on LED? */	}}/************************************************************************//* PROCEDURE: Verify							*//*									*//* This procedure checks to see if the correct byte has be read.	*//*									*//* Input:								*//*		byte:		byte read				*//*		cor_byte:	correct_byte that should be read	*//*									*//* Returns:								*//*		Nothing							*//************************************************************************/void Verify(unsigned char byte, unsigned char cor_byte){	if (byte != cor_byte)	{		while(1)			/* add source code or statement for this file */			/* to compile   			       */			/* i.e. option: insert a display to view error on LED? */				}}int main(){return 0;}

⌨️ 快捷键说明

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