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

📄 flash.txt

📁 PSD813F2的FLASH区操作的一个很有用的程序
💻 TXT
字号:

unsigned char WRITE_FLASH(unsigned char xdata *addr,unsigned char mydata)reentrant
 {
	unsigned char done;
	unsigned char error;
	unsigned char err;
	unsigned char poll;

	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_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) = 0xA0;     // write 0xA0 command to program

	*(addr) = mydata;                  // write byte to flash   
	
	mydata = mydata & NVM_DATA_POLL;     // get bit DQ7 of original data   
	
	do                               // now use data polling method to verify successful write
		{ WATCHDOG(); 
   		poll = *(addr);          // Read the location that was just programmed
   		  								
		error = poll & NVM_ERROR;   // save timeout error bit at DQ5

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

		if (mydata == poll)        // compare DQ7 

			done = TRUE;     // data byte programmed into flash 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 data poll didn't 
                                         // occur simultaneously
		{
		poll = *(addr);          // Read location in flash again

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

		if (mydata == poll)        // compare DQ7 

			done = TRUE;     // data byte programmed into flash 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 data sheet
		}

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


void FLASH_RESET()reentrant	// 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 data sheet
	}

unsigned char FLASH_ERASE(unsigned char xdata *flash_bulk_erase_address)reentrant	

	{
	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_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) = 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
   do		  			// now use data polling method to verify successful erase
		{  WATCHDOG();
		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 data 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 data sheet
		}
   	return(done);		// a successful flash erase returns 1, timeout error returns 0
	}

⌨️ 快捷键说明

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