久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 1181|回復: 0
打印 上一主題 下一主題
收起左側

HK32F030M單片機FASH讀寫程序

[復制鏈接]
跳轉到指定樓層
樓主
ID:302293 發表于 2024-3-4 17:09 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
    Demo例程
  1. int main(void)
  2. {
  3.   /*!< At this stage the microcontroller clock setting is already configured,
  4.        this is done through SystemInit() function which is called from startup
  5.        file (KEIL_startup_hk32f030m.s) before to branch to application main.
  6.        To reconfigure the default setting of SystemInit() function, refer to
  7.        system_hk32f030m.c file
  8.      */
  9.   
  10.   uint16_t i;
  11.   
  12.   /* Inser delay time for debug purpose */
  13.   Delay(0xFFFFF);
  14.   
  15.   HK_EVAL_LEDInit(LED1);
  16.   HK_EVAL_LEDToggle(LED1);
  17.   
  18.   for(i=0; i<512; i++)
  19.   {
  20.     Write_Data[i] = 0xAB;
  21.   }
  22.   
  23.   Write_Data_To_Flash(FLASH_USER_START_ADDR, Write_Data, 512);
  24.   
  25.   Read_Data_From_Flash(FLASH_USER_START_ADDR, Read_Data, 512);


  26.   /* Infinite Loop */
  27.   while (1)
  28.   {
  29.    
  30.     HK_EVAL_LEDToggle(LED1);
  31.     Delay(0xFFFFF);
  32.         
  33.   }
  34. }


  35. //從指定地址寫入數據
  36. void Write_Data_To_Flash(uint32_t address, uint8_t* data, uint16_t size)
  37. {
  38.   
  39.   uint8_t Temp;
  40.   
  41.   /* Unlock the Flash to enable the flash control register access *************/
  42.   FLASH_Unlock();

  43.   /* Erase the user Flash area
  44.      (area defined by FLASH_USER_START_ADDR and FLASH_USER_END_ADDR) *********/

  45.   /* Clear pending flags (if any) */
  46.   FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_WRPERR);

  47.   /* Define the number of page to be erased */
  48.   NbrOfPage = size / FLASH_PAGE_SIZE;

  49.   /* Erase the FLASH pages */
  50.   for(EraseCounter = 0; (EraseCounter <= NbrOfPage) && (FLASHStatus == FLASH_COMPLETE); EraseCounter++)
  51.   {
  52.     if(FLASH_ErasePage(FLASH_USER_START_ADDR + (FLASH_PAGE_SIZE * EraseCounter)) != FLASH_COMPLETE)
  53.     {
  54.       /* Error occurred while sector erase.
  55.           User can add here some code to deal with this error */
  56.       while(1)
  57.       {
  58.       }
  59.     }
  60.   }

  61.   /* Program the user Flash area half-word by half-word
  62.     (area defined by FLASH_USER_START_ADDR and FLASH_USER_END_ADDR) ***********/  
  63.   uint16_t i=0;  
  64.   FLASH_USER_END_ADDR = address + size;
  65.   while (address < FLASH_USER_END_ADDR)
  66.   {
  67.    
  68.     Temp = data[i];
  69.    
  70.     if (FLASH_ProgramByte(address, Temp) == FLASH_COMPLETE)
  71.     {
  72.       address = address + 1;
  73.     }
  74.     else
  75.     {
  76.       /* Error occurred while writing data in Flash memory.
  77.          User can add here some code to deal with this error */
  78.       while (1)
  79.       {
  80.       }
  81.     }
  82.    
  83.     i++;        
  84.   }

  85.   /* Lock the Flash to disable the flash control register access (recommended
  86.      to protect the FLASH memory against possible unwanted operation) *********/
  87.   FLASH_Lock();  
  88.   
  89.   
  90. }





  91. //從指定地址讀取數據
  92. void Read_Data_From_Flash(uint32_t address, uint8_t* data, uint16_t size)
  93. {
  94.   uint16_t i=0;  
  95.   FLASH_USER_END_ADDR = address + size;
  96.   while (address < FLASH_USER_END_ADDR)
  97.   {
  98.     data[i] = *(uint32_t*)address;
  99.     address = address + 1;
  100.    
  101.     i++;
  102.   }
  103.       
  104.   for(i=0; i<512; i++)
  105.   {
  106.     if( Write_Data[i] != Read_Data[i] )
  107.     {      
  108.       //讀取錯誤處理
  109.       MemoryProgramStatus = FAILED;
  110.       while(1);            
  111.     }      
  112.   }      
  113. }
復制代碼

原理圖: 無
仿真: 無
代碼: HK32F030M-FLASH.7z (1.03 MB, 下載次數: 4)

評分

參與人數 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎勵!

查看全部評分

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏1 分享淘帖 頂 踩
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 精品欧美一区二区三区久久久 | 久久国产亚洲 | 91精品久久久久久久久 | 午夜精品网站 | 日韩免费一区 | 欧洲成人午夜免费大片 | 国产无人区一区二区三区 | 欧美在线 | 欧美精品一区二区在线观看 | www.788.com色淫免费 | 成人一区二区视频 | 午夜成人免费视频 | 国产精品久久久久久久久久了 | 在线免费观看亚洲 | 人人爽人人草 | 不卡一区二区三区四区 | 羞羞午夜| 亚洲国产aⅴ成人精品无吗 亚洲精品久久久一区二区三区 | 欧美国产视频一区二区 | 亚州精品天堂中文字幕 | 可以免费看的毛片 | 国产激情精品视频 | 午夜在线小视频 | 视频一区在线观看 | 在线视频a | 999精彩视频 | 亚洲香蕉 | 国产精品久久久久久久久久免费看 | 五月激情综合网 | 亚洲一二视频 | 中国91av | 乳色吐息在线观看 | 久久久久电影 | 久久久久国产精品一区二区 | a级免费观看视频 | 国产日韩精品久久 | 成人欧美一区二区三区在线播放 | 羞羞的视频免费在线观看 | 国产精品自拍一区 | 日本亚洲欧美 | 爱爱小视频 |