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

📄 flash.c

📁 本程序是一个RS232转网口的。是一个透明传输的模块
💻 C
📖 第 1 页 / 共 2 页
字号:
	*(FLASH_COMMON_X555) = 0x80;		// write 0x80 command to erase entire chip
	*(FLASH_COMMON_X555) = 0xAA;        	// continue unlock sequence
	*(FLASH_COMMON_XAAA) = 0x55;		// continue unlock sequence
	//*(FLASH_COMMON_X555) = 0x10;		// write 0x10 command to complete erase command
    *(flash_bulk_erase_address) = 0x30; // write 0x30 to sector address to erase

	do		  			// now use dat polling method to verify successful erase
    {  
		poll = *(flash_bulk_erase_address); 	// read flash status from any address
		                                // within the defined flash address space

		error = poll & NVM_ERROR;	// save timeout error bit at DQ5

		poll = poll & NVM_DATA_POLL;	// look at D7   

		if (poll == NVM_DATA_POLL)	// compare DQ7 

			done = TRUE;		// bulk erase OK,
						// indicate successful exit criteria

		else if (error == NVM_ERROR)	// check for timeout error   
			err = TRUE;		// indicate timeout error occurred

    } while((done == FALSE) && (err == FALSE)); 


	if (err == TRUE)			// make sure timeout error and dat poll didn't 
						// occur simultaneously
    {
		poll = *(flash_bulk_erase_address); 	// Read flash status again

		poll = poll & NVM_DATA_POLL;	// get DQ7 of poll byte read from flash  

		if (poll == NVM_DATA_POLL)	// compare DQ7 

			done = TRUE;		// the flash erased OK at the same
						// time timout error occured, indicate successful 
						// exit criteria

		*(FLASH_COMMON_X555) = 0xF0;  // reset the flash array (short reset instruction) 
		        // now delay 3 msec per dat sheet
    }

   	return(done);		// a successful flash erase returns 1, timeout error returns 0

}
#endif


/*
*****************************************************************************************************
* 
*****************************************************************************************************
*/
#ifdef _F_B_E_B

unsigned char flash_boot_erase_sector(
    volatile unsigned char xdata* flash_bulk_erase_address)
{
	unsigned char done;
 	unsigned char poll;
 	unsigned char error;
 	unsigned char err;

	done = FALSE;
   	err = FALSE;

	//  Note:  the following constants (FLASH_COMMON_XXXX)
	//     are declared type volatile in the header file 
	//	   so they are not optimized away by the compiler

	*(FLASH_BOOT_X555) = 0xAA;		// unlock main flash, write 0xAA to addess 0xX555
	*(FLASH_BOOT_XAAA) = 0x55;		// unlock main flash, write 0x55 to addess 0xXAAA
	*(FLASH_BOOT_X555) = 0x80;		// write 0x80 command to erase entire chip
	*(FLASH_BOOT_X555) = 0xAA;        	// continue unlock sequence
	*(FLASH_BOOT_XAAA) = 0x55;		// continue unlock sequence
	// *(FLASH_BOOT_X555) = 0x10;		// write 0x10 command to complete erase command
    *(flash_bulk_erase_address) = 0x30; // write 0x30 to sector address to erase

	do		  			// now use dat polling method to verify successful erase
    {  
		poll = *(flash_bulk_erase_address); 	// read flash status from any address
		                                // within the defined flash address space

		error = poll & NVM_ERROR;	// save timeout error bit at DQ5

		poll = poll & NVM_DATA_POLL;	// look at D7   

		if (poll == NVM_DATA_POLL)	// compare DQ7 

			done = TRUE;		// bulk erase OK,
						// indicate successful exit criteria

		else if (error == NVM_ERROR)	// check for timeout error   
			err = TRUE;		// indicate timeout error occurred

    } while((done == FALSE) && (err == FALSE)); 


	if (err == TRUE)			// make sure timeout error and dat poll didn't 
						// occur simultaneously
    {
		poll = *(flash_bulk_erase_address); 	// Read flash status again

		poll = poll & NVM_DATA_POLL;	// get DQ7 of poll byte read from flash  

		if (poll == NVM_DATA_POLL)	// compare DQ7 

			done = TRUE;		// the flash erased OK at the same
						// time timout error occured, indicate successful 
						// exit criteria

		*(FLASH_BOOT_X555) = 0xF0;  // reset the flash array (short reset instruction) 
		        // now delay 3 msec per dat sheet
    }

   	return(done);		// a successful flash erase returns 1, timeout error returns 0

}

#endif

/*
*****************************************************************************************************
* 
*****************************************************************************************************
*/
#ifdef _F_R

void flash_reset()	// reset flash, read array mode

	{

	//  Note:  the following constants (FLASH_COMMON_XXXX)
	//     are declared type volatile in the header file 
	//	   so they are not optimized away by the compiler

	*(FLASH_COMMON_X555) = 0xAA;		// unlock main flash, write 0xAA to addess 0xX555
	*(FLASH_COMMON_XAAA) = 0x55;		// unlock main flash, write 0x55 to addess 0xXAAA
	*(FLASH_COMMON_X555) = 0xF0;		// write 0xF0 command to reset 
						// Flash memory to Read Array Mode
                      // now delay 3 msec per dat sheet
	}

void flash_boot_reset()	// reset boot flash, read array mode

	{

	//  Note:  the following constants (FLASH_BOOT_XXXX)
	//     are declared type volatile in the header file 
	//	   so they are not optimized away by the compiler

	*(FLASH_BOOT_X555) = 0xAA;		// unlock main flash, write 0xAA to addess 0xX555
	*(FLASH_BOOT_XAAA) = 0x55;		// unlock main flash, write 0x55 to addess 0xXAAA
	*(FLASH_BOOT_X555) = 0xF0;		// write 0xF0 command to reset 
						// Flash memory to Read Array Mode
                      // now delay 3 msec per dat sheet
	}

#endif


/*
*****************************************************************************************************
* 
*****************************************************************************************************
*/
#ifdef _F_R_I

unsigned char flash_read_id(flash_id_address)	// read flash identifier
volatile unsigned char *flash_id_address;  

  	{
	unsigned char id;

	//  Note:  the following constants (FLASH_COMMON_XXXX)
	//     are declared type volatile in the header file 
	//	   so they are not optimized away by the compiler

	*(FLASH_COMMON_X555) = 0xAA;		// unlock main flash, write 0xAA to addess 0xX555
	*(FLASH_COMMON_XAAA) = 0x55;		// unlock main flash, write 0x55 to addess 0xXAAA
	*(FLASH_COMMON_X555) = 0x90;		// write 0x90 command to get ID

	id = *(flash_id_address);		// read flash status, address bit A6 = 0
						//				  A1 = 0
						//				  A0 = 1
	*(FLASH_COMMON_X555) = 0xF0;  // reset the flash array (short reset instruction) 
		        // now delay 3 msec per dat sheet

	return (id);				// return byte ID value
	}

#endif


/*
*****************************************************************************************************
* 
*****************************************************************************************************
*/
#ifdef _F_R_S_P

extern xdata PSD_REGS PSD_reg;// _at_ PSD_REG_ADDR;	// Define PSD registers at address "csiop" space

unsigned char flash_read_sector_protect()	

	{
 
 	return (PSD_reg.MAINPROTECT);   //This is a register inside the PSD
					// For reference, see the header file 
					// upsd3200.h for the location of 
					// the PSD register, MAINPROTECT.
	}

#endif




/*
*****************************************************************************************************
*FUNC: 
*NOTE:  
*****************************************************************************************************
*/
unsigned char xdata bootdptr _at_ 0x7E00;

void ReadFlash(unsigned char xdata *dest,unsigned int length)
{
	 unsigned int i=0;
     unsigned char xdata *read_add = bootdptr;

	 for (i=0; i<length; i++) {
         *dest++ = *read_add++;
	 }
}

void WriteFlash(unsigned char xdata *source,unsigned int length)
{
	 unsigned int i=0;
     unsigned char xdata *write_add = bootdptr;

	 flash_boot_erase_sector(write_add);
	 for (i=0; i<length; i++) {
         flash_boot_write_with_poll(write_add++,*source++);
	 }
}


⌨️ 快捷键说明

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