📄 flashcode1.lst
字号:
430 1 unsigned char done;
431 1 unsigned char poll;
432 1 unsigned char error;
433 1 unsigned char err;
434 1
435 1 done = FALSE;
436 1 err = FALSE;
437 1
438 1 // Note: the following constants (FLASH_COMMON_XXXX)
439 1 // are declared type volatile in the header file
440 1 // so they are not optimized away by the compiler
441 1
442 1 *(FLASH_BOOT_X555) = 0xAA; // unlock main flash, write 0xAA to addess 0xX555
443 1 *(FLASH_BOOT_XAAA) = 0x55; // unlock main flash, write 0x55 to addess 0xXAAA
444 1 *(FLASH_BOOT_X555) = 0x80; // write 0x80 command to erase entire chip
445 1 *(FLASH_BOOT_X555) = 0xAA; // continue unlock sequence
446 1 *(FLASH_BOOT_XAAA) = 0x55; // continue unlock sequence
447 1 // *(FLASH_BOOT_X555) = 0x10; // write 0x10 command to complete erase command
448 1 *(flash_bulk_erase_address) = 0x30; // write 0x30 to sector address to erase
449 1
450 1 do // now use dat polling method to verify successful erase
451 1 {
452 2 poll = *(flash_bulk_erase_address); // read flash status from any address
453 2 // within the defined flash address space
454 2 error = poll & NVM_ERROR; // save timeout error bit at DQ5
455 2 poll = poll & NVM_DATA_POLL; // look at D7
456 2 if (poll == NVM_DATA_POLL) // compare DQ7
457 2 {
458 3 done = TRUE; // bulk erase OK, indicate successful exit criteria
459 3 }
460 2 else if (error == NVM_ERROR) // check for timeout error
461 2 {
462 3 err = TRUE; // indicate timeout error occurred
463 3 }
464 2
465 2 }
466 1 while((done == FALSE) && (err == FALSE));
467 1
468 1
469 1 if (err == TRUE) // make sure timeout error and dat poll didn't
470 1 // occur simultaneously
471 1 {
472 2 poll = *(flash_bulk_erase_address); // Read flash status again
473 2 poll = poll & NVM_DATA_POLL; // get DQ7 of poll byte read from flash
474 2 if (poll == NVM_DATA_POLL) // compare DQ7
475 2 {
476 3 done = TRUE; // the flash erased OK at the same
477 3 // time timout error occured, indicate successful exit criteria
478 3 }
479 2 *(FLASH_BOOT_X555) = 0xF0; // reset the flash array (short reset instruction)
480 2 // now delay 3 msec per dat sheet
481 2 }
482 1
483 1 return(done); // a successful flash erase returns 1, timeout error returns 0
484 1
485 1 }
486
487 #endif
488
489
C51 COMPILER V7.06 FLASHCODE1 10/15/2004 20:55:30 PAGE 9
490
491
492
493
494
495 #ifdef _F_R
496
497
498
499
500
501
502
503 void flash_reset()
504 /******************************************************************************
505 Function : void flash_reset()
506 Parameters : none
507 Description: Resets the main Flash memory to Read Array mode.
508
509 After this reset, the Flash memory may be read like a ROM device.
510 You'll need to include the header files generated by PSDsoft
511 Express.
512 ******************************************************************************/
513 {
514 1 // Note: the following constants (FLASH_COMMON_XXXX)
515 1 // are declared type volatile in the header file
516 1 // so they are not optimized away by the compiler
517 1
518 1 *(FLASH_COMMON_X555) = 0xAA; // unlock main flash, write 0xAA to addess 0xX555
519 1 *(FLASH_COMMON_XAAA) = 0x55; // unlock main flash, write 0x55 to addess 0xXAAA
520 1 *(FLASH_COMMON_X555) = 0xF0; // write 0xF0 command to reset
521 1 // Flash memory to Read Array Mode
522 1 // now delay 3 msec per dat sheet
523 1 }
524
525
526
527 void flash_boot_reset()
528 /******************************************************************************
529 Function : void flash_boot_reset()
530 Parameters : none
531 Description: reset boot flash, read array mode
532 ******************************************************************************/
533 {
534 1 // Note: the following constants (FLASH_BOOT_XXXX)
535 1 // are declared type volatile in the header file
536 1 // so they are not optimized away by the compiler
537 1
538 1 *(FLASH_BOOT_X555) = 0xAA; // unlock main flash, write 0xAA to addess 0xX555
539 1 *(FLASH_BOOT_XAAA) = 0x55; // unlock main flash, write 0x55 to addess 0xXAAA
540 1 *(FLASH_BOOT_X555) = 0xF0; // write 0xF0 command to reset
541 1 // Flash memory to Read Array Mode
542 1 // now delay 3 msec per dat sheet
543 1 }
544
545 #endif
546
547
548
549
550
551
C51 COMPILER V7.06 FLASHCODE1 10/15/2004 20:55:30 PAGE 10
552 #ifdef _F_R_I
unsigned char flash_read_id(flash_id_address)
/******************************************************************************
Function : unsigned char flash_read_id()
Parameters : (flash_id_address)
Description: Reads the Flash Identifier byte from main Flash memory.
You'll need to include the header files generated by PSDsoft Express.
Important: The address passed to this function should be independent
of memory paging or else the PSD page register value should be set to
the correct page prior to calling this function.
Note: The flash memory in the boot area of a PSD813F2 or PSD813F4 does
not provide an ID. Only the main Flash memory in all PSD813FX provides
an ID.
******************************************************************************/
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
591
592
593
594
595
596 #ifdef _F_R_S_P
unsigned char flash_read_sector_protect(void)
/******************************************************************************
Function : unsigned char flash_read_sector_protect()
Parameters : (void)
Description: Reads main Flash sector protection status.
An unsigned char byte value is returned that contains the status
for all eight sectors of main Flash memory. This byte value can
be decoded as follows:
BitD7 BitD6 BitD5 BitD4 BitD3 BitD2 BitD1 BitD0
fs7 fs6 fs5 fs4 fs3 fs2 fs1 fs0
fsx >> 1 = Flash sector is write protected
fsx >> 0 = Flash sector is not write protected
C51 COMPILER V7.06 FLASHCODE1 10/15/2004 20:55:30 PAGE 11
The protection bits may only be read by the microcontroller. They
can be set or cleared only through the JTAG channel or a device
programmer, not the microcontroller.
******************************************************************************/
{
return (MAINPROTECT.byte); // This is a register inside the PSD
// For reference, see the header file
// uPSD3200.h for the location of
// the PSD register, MAINPROTECT.
}
#endif
626
627
628
629 /* *************************************************************************
630 *** ***
631 ** *** End of File *** **
632 *** ***
633 ************************************************************************* */
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 458 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- 4
PDATA SIZE = ---- ----
DATA SIZE = ---- ----
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -