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

📄 sst25vf016b.c

📁 SST 的SPI FLASH 驱动程序,给大家在做SPI是做参考用,
💻 C
📖 第 1 页 / 共 3 页
字号:
/*									*//* Returns:								*//*		Nothing							*//*									*//************************************************************************/void Auto_Add_IncA(unsigned long Dst, unsigned char byte1, unsigned char byte2){	CE_Low();				/* enable device */	Send_Byte(0xAD);			/* send AAI command */	Send_Byte(((Dst & 0xFFFFFF) >> 16)); 	/* send 3 address bytes */	Send_Byte(((Dst & 0xFFFF) >> 8));	Send_Byte(Dst & 0xFF);	Send_Byte(byte1);			/* send 1st byte to be programmed */		Send_Byte(byte2);			/* send 2nd byte to be programmed */	CE_High();				/* disable device */}/************************************************************************//* PROCEDURE:	Auto_Add_IncB						*//*									*//* This procedure programs consecutive addresses of 2 bytes of data into*//* the device:  1st data byte will be programmed into the initial 	*//* address [A23-A1] and with A0 = 0.  The 2nd data byte will be be 	*//* programmed into initial address [A23-A1] and with A0  = 1.    This  	*//* is used after Auto_Address_IncA.					*//* Assumption:  Address being programmed is already erased and is NOT	*//*		block protected.					*//*									*//* Note: Only WRDI and AAI command can be executed once in AAI mode 	*//*	 with SO enabled as RY/BY# status.  When the device is busy 	*//*	 asserting CE# will output the status of RY/BY# on SO.  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:								*//*									*//*		byte1:		1st byte to be programmed		*//*		byte2:		2nd byte to be programmed		*//*      								*//*									*//* Returns:								*//*		Nothing							*//*									*//************************************************************************/void Auto_Add_IncB(unsigned char byte1, unsigned char byte2){	CE_Low();				/* enable device */	Send_Byte(0xAD);			/* send AAI command */	Send_Byte(byte1);			/* send 1st byte to be programmed */	Send_Byte(byte2);			/* send 2nd byte to be programmed */	CE_High();				/* disable device */}/************************************************************************//* PROCEDURE:	Auto_Add_IncA_EBSY					*//*									*//* This procedure is the same as procedure Auto_Add_IncA except that it *//* uses EBSY and Poll_SO functions to check for RY/BY. It programs 	*//* consecutive addresses of the device.  The 1st data byte will be 	*//* programmed into the initial address [A23-A1] and with A0 = 0.  The 	*//* 2nd data byte will be programmed into initial address [A23-A1] and 	*//* with A0  = 1.  This is used to to start the AAI process.  It should  *//* be followed by Auto_Add_IncB_EBSY.					*//* Assumption:  Address being programmed is already erased and is NOT	*//*		block protected.					*//*									*//*									*//* Note: Only WRDI and AAI command can be executed once in AAI mode 	*//*	 with SO enabled as RY/BY# status.  When the device is busy 	*//*	 asserting CE# will output the status of RY/BY# on SO.  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 - 1FFFFFH	*//*		byte1:		1st byte to be programmed		*//*      	byte1:		2nd byte to be programmed		*//*									*//* Returns:								*//*		Nothing							*//*									*//************************************************************************/void Auto_Add_IncA_EBSY(unsigned long Dst, unsigned char byte1, unsigned char byte2){	EBSY();					/* enable RY/BY# status for SO in AAI */		CE_Low();				/* enable device */	Send_Byte(0xAD);			/* send AAI command */	Send_Byte(((Dst & 0xFFFFFF) >> 16)); 	/* send 3 address bytes */	Send_Byte(((Dst & 0xFFFF) >> 8));	Send_Byte(Dst & 0xFF);	Send_Byte(byte1);			/* send 1st byte to be programmed */		Send_Byte(byte2);			/* send 2nd byte to be programmed */	CE_High();				/* disable device */		Poll_SO();				/* polls RY/BY# using SO line */}/************************************************************************//* PROCEDURE:	Auto_Add_IncB_EBSY					*//*									*//* This procedure is the same as Auto_Add_IncB excpet that it uses 	*//* Poll_SO to poll for RY/BY#.  It demonstrate on how to use DBSY after	*//* AAI programmming is completed.  It programs consecutive addresses of *//* the device.  The 1st data byte will be programmed into the initial   *//* address [A23-A1] and with A0 = 0.  The 2nd data byte will be 	*//* programmed into initial address [A23-A1] and with A0  = 1.  This is 	*//* used after Auto_Address_IncA.					*//* Assumption:  Address being programmed is already erased and is NOT	*//*		block protected.					*//*									*//* Note: Only WRDI and AAI command can be executed once in AAI mode 	*//*	 with SO enabled as RY/BY# status.  When the device is busy 	*//*	 asserting CE# will output the status of RY/BY# on SO.  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:								*//*									*//*		byte1:		1st byte to be programmed		*//*		byte2:		2nd byte to be programmed		*//*      								*//*									*//* Returns:								*//*		Nothing							*//*									*//************************************************************************/void Auto_Add_IncB_EBSY(unsigned char byte1, unsigned char byte2){	CE_Low();				/* enable device */	Send_Byte(0xAD);			/* send AAI command */	Send_Byte(byte1);			/* send 1st byte to be programmed */	Send_Byte(byte2);			/* send 2nd byte to be programmed */	CE_High();				/* disable device */	Poll_SO();				/* polls RY/BY# using SO line */	WRDI(); 				/* Exit AAI before executing DBSY */	DBSY();					/* disable SO as RY/BY# output if in AAI */}/************************************************************************//* 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 (60h or C7h) */	CE_High();				/* disable device */}/************************************************************************//* PROCEDURE: Sector_Erase						*//*									*//* This procedure Sector Erases the Chip.				*//*									*//* Input:								*//*		Dst:		Destination Address 000000H - 1FFFFFH	*//*									*//* 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_32K						*//*									*//* This procedure Block Erases 32 KByte of the Chip.			*//*									*//* Input:								*//*		Dst:		Destination Address 000000H - 1FFFFFH	*//*									*//* Returns:								*//*		Nothing							*//************************************************************************/void Block_Erase_32K(unsigned long Dst){	CE_Low();				/* enable device */	Send_Byte(0x52);			/* send 32 KByte 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: Block_Erase_64K						*//*									*//* This procedure Block Erases 64 KByte of the Chip.			*//*									*//* Input:								*//*		Dst:		Destination Address 000000H - 1FFFFFH	*//*									*//* Returns:								*//*		Nothing							*//************************************************************************/void Block_Erase_64K(unsigned long Dst){	CE_Low();				/* enable device */	Send_Byte(0xD8);			/* send 64KByte 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? */		 	/* 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? */		    	/* 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? */						/* option: insert a display to view error on LED? */	}}int main(){return 0;}

⌨️ 快捷键说明

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