📄 flashcode1.lst
字号:
215 1
216 1 dat = dat & NVM_DATA_POLL; // get bit DQ7 of original dat
217 1
218 1 do // now use dat polling method to verify successful write
219 1 {
220 2
221 2 poll = *(addr); // Read the location that was just programmed
222 2
223 2 error = poll & NVM_ERROR; // save timeout error bit at DQ5
224 2
225 2 poll = poll & NVM_DATA_POLL; // get DQ7 of poll byte read from flash
226 2
227 2 if (dat == poll) // compare DQ7
228 2
229 2 done = TRUE; // dat byte programmed into flash OK,
230 2 // indicate successful exit criteria
231 2
232 2 else if (error == NVM_ERROR ) // check for timeout error
233 2 err = TRUE; // indicate timeout error occurred
234 2
235 2 } while((done == FALSE) && (err == FALSE));
236 1
237 1
238 1 if (err == TRUE) // make sure timeout error and dat poll didn't
239 1 // occur simultaneously
240 1 {
241 2 poll = *(addr); // Read location in flash again
C51 COMPILER V7.00 Beta 6 FLASHCODE1 02/19/2003 15:59:28 PAGE 5
242 2
243 2 poll = poll & NVM_DATA_POLL; // get DQ7 of poll byte read from flash
244 2
245 2 if (dat == poll) // compare DQ7
246 2
247 2 done = TRUE; // dat byte programmed into flash OK at the same
248 2 // time timout error occured, indicate successful
249 2 // exit criteria
250 2
251 2 *(FLASH_BOOT_X555) = 0xF0; // reset the flash array (short reset instruction)
252 2 // now delay 3 msec per dat sheet
253 2 }
254 1
255 1 return(done); // a successful flash write returns 1, timeout error returns 0
256 1 }
257
258
259 #endif
260
261
262
263 /*
264 Module: flash_write_with_toggle
265 Programs a single byte, checks status using toggle method.
266 You'll need to include the header files generated by PSDsoft
267 Express. Important: if memory paging is used, the correct page
268 value must be set in the PSD page register prior to calling this
269 function.
270 */
271
272 #ifdef _F_W_W_T
unsigned char flash_write_with_toggle(addr,dat)
volatile unsigned char *addr;
unsigned char dat;
{
unsigned char done;
unsigned char error;
unsigned char err;
volatile unsigned char toggle_A;
volatile unsigned char toggle_B;
done = FALSE;
err = FALSE;
// 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) = 0xA0; // write 0xA0 command to program
*(addr) = dat; // write byte to flash
// now use toggling method to verify successful write
toggle_A = *(addr); // Read the location that was just programmed
toggle_A = toggle_A & NVM_DATA_TOGGLE; // mask toggle bit at DQ6
C51 COMPILER V7.00 Beta 6 FLASHCODE1 02/19/2003 15:59:28 PAGE 6
do
{
toggle_B = *(addr); // Again read the location that was just programmed
error = toggle_B & NVM_ERROR; // save timeout error flag at DQ5
toggle_B = toggle_B & NVM_DATA_TOGGLE; // mask toggle bit at DQ6
if (toggle_A == toggle_B) // compare toggle bit DQ6
done = TRUE; // bit did not toggle, dat byte programmed into
// flash OK, indicate successful exit criteria
else
{
if (error == NVM_ERROR ) // check for timeout error
err = TRUE; // indicate timeout error occurred
toggle_A = toggle_B; // save most recent sample of toggle bit
// to compare with next sample
}
} while((done == FALSE) && (err == FALSE));
if (err == TRUE) // make sure timeout error and dat toggle didn't
// occur simultaneously
{
toggle_B = *(addr); // Read location in flash again
toggle_B = toggle_B & NVM_DATA_TOGGLE; // mask toggle bit at DQ6
if (toggle_A == toggle_B) // compare toggle bit DQ6
done = TRUE; // dat byte programmed into flash 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 write returns 1, timeout error returns 0
}
#endif
349
350
351
352 /*
353 Module: flash_erase_sector
354 Erases the entire main Flash memory (all sectors).
355 You'll need to include the header files generated by PSDsoft
356 Express. Important: The address passed to this function should
357 be independent of memory paging or else the PSD page
358 register value should be set to the correct page prior to calling this
359 function.
360
361 Note: The address that is passed in this function can be an address that
362 resides in any Flash segment that has a chip select. For example, if
363 fs0 and fs5 are used in the design, passing an address in this function
364 that resides in either fs0 or fs5 will invoke the bulk erase operation.
365 */
C51 COMPILER V7.00 Beta 6 FLASHCODE1 02/19/2003 15:59:28 PAGE 7
366
367 #ifdef _F_E_B
368
369 unsigned char flash_erase_sector(
370 volatile unsigned char xdata* flash_bulk_erase_address)
371 {
372 1 unsigned char done;
373 1 unsigned char poll;
374 1 unsigned char error;
375 1 unsigned char err;
376 1
377 1 done = FALSE;
378 1 err = FALSE;
379 1
380 1 // Note: the following constants (FLASH_COMMON_XXXX)
381 1 // are declared type volatile in the header file
382 1 // so they are not optimized away by the compiler
383 1
384 1 *(FLASH_COMMON_X555) = 0xAA; // unlock main flash, write 0xAA to addess 0xX555
385 1 *(FLASH_COMMON_XAAA) = 0x55; // unlock main flash, write 0x55 to addess 0xXAAA
386 1 *(FLASH_COMMON_X555) = 0x80; // write 0x80 command to erase entire chip
387 1 *(FLASH_COMMON_X555) = 0xAA; // continue unlock sequence
388 1 *(FLASH_COMMON_XAAA) = 0x55; // continue unlock sequence
389 1 //*(FLASH_COMMON_X555) = 0x10; // write 0x10 command to complete erase command
390 1 *(flash_bulk_erase_address) = 0x30; // write 0x30 to sector address to erase
391 1
392 1 do // now use dat polling method to verify successful erase
393 1 {
394 2 poll = *(flash_bulk_erase_address); // read flash status from any address
395 2 // within the defined flash address space
396 2
397 2 error = poll & NVM_ERROR; // save timeout error bit at DQ5
398 2
399 2 poll = poll & NVM_DATA_POLL; // look at D7
400 2
401 2 if (poll == NVM_DATA_POLL) // compare DQ7
402 2
403 2 done = TRUE; // bulk erase OK,
404 2 // indicate successful exit criteria
405 2
406 2 else if (error == NVM_ERROR) // check for timeout error
407 2 err = TRUE; // indicate timeout error occurred
408 2
409 2 } while((done == FALSE) && (err == FALSE));
410 1
411 1
412 1 if (err == TRUE) // make sure timeout error and dat poll didn't
413 1 // occur simultaneously
414 1 {
415 2 poll = *(flash_bulk_erase_address); // Read flash status again
416 2
417 2 poll = poll & NVM_DATA_POLL; // get DQ7 of poll byte read from flash
418 2
419 2 if (poll == NVM_DATA_POLL) // compare DQ7
420 2
421 2 done = TRUE; // the flash erased OK at the same
422 2 // time timout error occured, indicate successful
423 2 // exit criteria
424 2
425 2 *(FLASH_COMMON_X555) = 0xF0; // reset the flash array (short reset instruction)
426 2 // now delay 3 msec per dat sheet
427 2 }
C51 COMPILER V7.00 Beta 6 FLASHCODE1 02/19/2003 15:59:28 PAGE 8
428 1
429 1 return(done); // a successful flash erase returns 1, timeout error returns 0
430 1
431 1 }
432
433 unsigned char flash_boot_erase_sector(
434 volatile unsigned char xdata* flash_bulk_erase_address)
435 {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -