[DemoCode下载] N76E003 APROM程序DATAFLASH为EEPROM方式

[复制链接]
25|0
mnynt121 发表于 2026-5-12 15:36 | 显示全部楼层 |阅读模式



  1. #include <stdio.h>
  2. #include "N76E003.h"
  3. #include "Common.h"
  4. #include "Delay.h"
  5. #include "SFR_Macro.h"
  6. #include "Function_Define.h"

  7. bit BIT_TMP;

  8. //-------------------------------------------------------------------------
  9. UINT8 read_APROM_BYTE(UINT16 code *u16_addr)
  10. {
  11.     UINT8 rdata;
  12.     rdata = *u16_addr>>8;
  13.     return rdata;
  14. }
  15. //-------------------------------------------------------------------------


  16. /*****************************************************************************************************************
  17. write_DATAFLASH_BYTE :
  18. user can copy all this subroutine into project, then call this function in main.
  19. ******************************************************************************************************************/        
  20. void write_DATAFLASH_BYTE(UINT16 u16_addr,UINT8 u8_data)
  21. {
  22.     UINT8 looptmp=0,u8_addrl_r;
  23.     unsigned char code *cd_longaddr;
  24.     unsigned char xdata *xd_tmp;
  25.    
  26. //Check page start address
  27.     u8_addrl_r = u16_addr;
  28.     if (u8_addrl_r<0x80)
  29.     {
  30.         u8_addrl_r = 0;
  31.     }
  32.     else
  33.     {
  34.         u8_addrl_r = 0x80;
  35.     }
  36. //Save APROM data to XRAM
  37.     xd_tmp = 0x80;
  38.     cd_longaddr = (u16_addr&0xff00)+u8_addrl_r;   
  39.     while (xd_tmp !=0x100)
  40.     {
  41.         *xd_tmp = *cd_longaddr;
  42.         looptmp++;
  43.         xd_tmp++;
  44.         cd_longaddr++;
  45.     }
  46. // Modify customer data in XRAM
  47.     u8_addrl_r = u16_addr;
  48.     if (u8_addrl_r<0x80)
  49.     {
  50.         xd_tmp = u8_addrl_r+0x80;
  51.     }
  52.     else
  53.     {
  54.         xd_tmp = u8_addrl_r+0;
  55.     }
  56.     *xd_tmp = u8_data;
  57. //Erase APROM DATAFLASH page
  58.         IAPAL = u16_addr;
  59.         IAPAH = u16_addr>>8;
  60.         IAPFD = 0xFF;
  61.       set_IAPEN;
  62.         set_APUEN;
  63.     IAPCN = 0x22;         
  64.          set_IAPGO;
  65. //Save changed RAM data to APROM DATAFLASH
  66.     u8_addrl_r = u16_addr;
  67.     if (u8_addrl_r<0x80)
  68.     {
  69.         u8_addrl_r =0;
  70.     }
  71.     else
  72.     {
  73.         u8_addrl_r = 0x80;
  74.     }
  75.         xd_tmp = 0x80;
  76.       IAPAL = u8_addrl_r;
  77.     IAPAH = u16_addr>>8;
  78.         set_IAPEN;
  79.         set_APUEN;
  80.       IAPCN = 0x21;
  81.         while (xd_tmp !=0xFF)
  82.         {
  83.             IAPFD = *xd_tmp;
  84.             set_IAPGO;
  85.             IAPAL++;
  86.             xd_tmp++;
  87.         }
  88.         clr_APUEN;
  89.         clr_IAPEN;
  90. }   
  91. /******************************************************************************************************************/        


  92. void main (void)
  93. {
  94.         UINT8 datatemp;
  95. /* -------------------------------------------------------------------------*/
  96. /*  Dataflash use APROM area                                                                         */
  97. /*    APROM 0x3800~0x38FF demo as dataflash                                                         */
  98. /* Please use Memory window key in C:0x3800 to check earse result                      */         
  99. /* -------------------------------------------------------------------------*/
  100.    
  101. //call write byte
  102.         write_DATAFLASH_BYTE (0x3881,0x55);
  103.         write_DATAFLASH_BYTE (0x3882,0x56);
  104.         write_DATAFLASH_BYTE (0x3855,0xaa);
  105.         write_DATAFLASH_BYTE (0x3856,0x66);
  106. //call read byte
  107.         datatemp = read_APROM_BYTE(0x3882);
  108.     while(1);
  109. }
上面这个函数,是对DATAFLASH  EEPROM进行读写,有主函数给出地址和数据,由该函数进行处理


  1. void write_DATAFLASH_BYTE(UINT16 u16_addr,UINT8 u8_data)
  2. {
  3.     UINT8 looptmp=0,u8_addrl_r;
  4.     unsigned char code *cd_longaddr;
  5.     unsigned char xdata *xd_tmp;
  6.    
  7. //Check page start address
  8.     u8_addrl_r = u16_addr;
  9.     if (u8_addrl_r<0x80)
  10.     {
  11.         u8_addrl_r = 0;
  12.     }
  13.     else
  14.     {
  15.         u8_addrl_r = 0x80;
  16.     }
  17. //Save APROM data to XRAM
  18.     xd_tmp = 0x80;
  19.     cd_longaddr = (u16_addr&0xff00)+u8_addrl_r;   
  20.     while (xd_tmp !=0x100)
  21.     {
  22.         *xd_tmp = *cd_longaddr;
  23.         looptmp++;
  24.         xd_tmp++;
  25.         cd_longaddr++;
  26.     }
  27. // Modify customer data in XRAM
  28.     u8_addrl_r = u16_addr;
  29.     if (u8_addrl_r<0x80)
  30.     {
  31.         xd_tmp = u8_addrl_r+0x80;
  32.     }
  33.     else
  34.     {
  35.         xd_tmp = u8_addrl_r+0;
  36.     }
  37.     *xd_tmp = u8_data;
  38. //Erase APROM DATAFLASH page
  39.         IAPAL = u16_addr;
  40.         IAPAH = u16_addr>>8;
  41.         IAPFD = 0xFF;
  42.         set_IAPEN;
  43.         set_APUEN;
  44.     IAPCN = 0x22;         
  45.          set_IAPGO;
  46. //Save changed RAM data to APROM DATAFLASH
  47.     u8_addrl_r = u16_addr;
  48.     if (u8_addrl_r<0x80)
  49.     {
  50.         u8_addrl_r =0;
  51.     }
  52.     else
  53.     {
  54.         u8_addrl_r = 0x80;
  55.     }
  56.         xd_tmp = 0x80;
  57.       IAPAL = u8_addrl_r;
  58.     IAPAH = u16_addr>>8;
  59.         set_IAPEN;
  60.         set_APUEN;
  61.       IAPCN = 0x21;
  62.         while (xd_tmp !=0xFF)
  63.         {
  64.             IAPFD = *xd_tmp;
  65.             set_IAPGO;
  66.             IAPAL++;
  67.             xd_tmp++;
  68.         }
  69.         clr_APUEN;
  70.         clr_IAPEN;
  71. }


您需要登录后才可以回帖 登录 | 注册

本版积分规则

57

主题

3772

帖子

2

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