[DemoCode下载] N76E003如何操作配置字?

[复制链接]
856|2
 楼主| jiekou001 发表于 2019-9-29 23:42 | 显示全部楼层 |阅读模式
  1. /*---------------------------------------------------------------------------------------------------------*/
  2. /*                                                                                                         */
  3. /* Copyright(c) 2017 Nuvoton Technology Corp. All rights reserved.                                         */
  4. /*                                                                                                         */
  5. /*---------------------------------------------------------------------------------------------------------*/

  6. //***********************************************************************************************************
  7. //  Nuvoton Technoledge Corp.
  8. //  Website: http://www.nuvoton.com
  9. //  E-Mail : MicroC-8bit@nuvoton.com
  10. //  Date   : Apr/21/2017
  11. //***********************************************************************************************************

  12. //***********************************************************************************************************
  13. //  File Function: N76E003 CONFIG program demo code
  14. //***********************************************************************************************************

  15. #include "N76E003.h"
  16. #include "Common.h"
  17. #include "Delay.h"
  18. #include "SFR_Macro.h"
  19. #include "Function_define.h"

  20. /*
  21.         Since the DATAFLASH is in the APROM. Program command is same as program APROM
  22. */

  23. #define     PAGE_ERASE_CF       0xE2
  24. #define     BYTE_READ_CF        0xC0
  25. #define     BYTE_PROGRAM_CF     0xE1

  26. #define     ERASE_FAIL          0x70
  27. #define     PROGRAM_FAIL        0x71
  28. #define     IAPFF_FAIL          0x72
  29. #define     IAP_PASS            0x00

  30.                

  31. /********************************************************************************************
  32. Following IAP command register is also define in SFR_Macro.h

  33.         #define set_IAPEN   BIT_TMP=EA;EA=0;TA=0xAA;TA=0x55;CHPCON |= SET_BIT0 ;EA=BIT_TMP
  34.         #define clr_IAPEN   BIT_TMP=EA;EA=0;TA=0xAA;TA=0x55;CHPCON &= ~SET_BIT0;EA=BIT_TMP
  35.         #define set_CFUEN   BIT_TMP=EA;EA=0;TA=0xAA;TA=0x55;IAPUEN|=SET_BIT2;EA=BIT_TMP
  36.         #define clr_CFUEN   BIT_TMP=EA;EA=0;TA=0xAA;TA=0x55;IAPUEN&=~SET_BIT2;EA=BIT_TMP
  37. **********************************************************************************************/
  38. void IAP_ERROR_LED(void)
  39. {
  40.         while (1)
  41.         {
  42.                 clr_P03;
  43.                 Timer0_Delay1ms(100);
  44.                 set_P03;
  45.                 Timer0_Delay1ms(100);
  46.         }

  47. }

  48. //-----------------------------------------------------------------------------------------------------------/
  49. void Trigger_IAP(void)
  50. {   
  51.     set_IAPGO;                                                                                                                                        //trigger IAP
  52.     if((CHPCON&SET_BIT6)==SET_BIT6)             // if fail flag is set, toggle error LED and IAP stop
  53.                 {
  54.                         clr_IAPFF;
  55.                         IAP_ERROR_LED();
  56.                 }
  57. }
  58. /*
  59.                 WARNING:
  60.         No matter read or writer, when IAPFF is set 1,
  61.         this step process is fail. DATA should be ignore.
  62. */
  63. //-----------------------------------------------------------------------------------------------------------/

  64. /*****************************************************************************************************************
  65. Write CONFIG subroutine:
  66. ******************************************************************************************************************/               

  67. void Enable_WDT_Reset_Config(void)
  68. {
  69.           set_IAPEN;                                                                                                                                        // Enable IAP function
  70.     IAPAL = 0x04;
  71.     IAPAH = 0x00;
  72.     IAPFD = 0x0F;
  73.     IAPCN = BYTE_PROGRAM_CF;
  74.     set_CFUEN;                                                                                                                                        // Enable CONFIG writer bit
  75.     set_IAPGO;                                  //trigger IAP
  76.                 while((CHPCON&SET_BIT6)==SET_BIT6);          //check IAPFF (CHPCON.6)
  77.     clr_CFUEN;
  78.     clr_IAPEN;
  79. }
  80. //-----------------------------------------------------------------------------------------------------------

  81. //-----------------------------------------------------------------------------------------------------------
  82. void main (void)
  83. {

  84.   Set_All_GPIO_Quasi_Mode;
  85. //---------toggle GPIO1---------       
  86.         clr_GPIO1;
  87.         Timer0_Delay1ms(100);
  88.         set_GPIO1;
  89.         Timer0_Delay1ms(100);
  90.         clr_GPIO1;
  91.         Timer0_Delay1ms(100);
  92.         set_GPIO1;
  93.         Timer0_Delay1ms(100);
  94. //---------end toggle GPIO1---------
  95.        
  96.     Enable_WDT_Reset_Config();
  97.     while(1);
  98. }
  99. //-----------------------------------------------------------------------------------------------------------



 楼主| jiekou001 发表于 2019-9-29 23:43 | 显示全部楼层
这个精髓就是IAP编程。也就是对Flash的某个地址进行编程操作。
 楼主| jiekou001 发表于 2019-9-29 23:43 | 显示全部楼层
或者说是读写某个闪存的地址。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

148

主题

1542

帖子

2

粉丝
快速回复 在线客服 返回列表 返回顶部