[Atmel] 跑一下XMEGA-B1程序(6)EEPROM

[复制链接]
 楼主| ddllxxrr 发表于 2015-12-24 21:57 | 显示全部楼层 |阅读模式
EEPROM在NVM (Non Volatile Memory模块中。
所以要加入NVM模块:



以下程序,分两个数组,第一个数组装用户定义的,第二个数组先清零然后再用API函数往里装。

以下是程序:

  1. #include <asf.h>

  2. #define EXAMPLE_PAGE 2
  3. #define EXAMPLE_ADDR EXAMPLE_PAGE * EEPROM_PAGE_SIZE
  4. uint8_t write_page[EEPROM_PAGE_SIZE];
  5. uint8_t read_page[EEPROM_PAGE_SIZE];

  6. fill_page_with_known_data(uint8_t * ppp);
  7. fill_page_with_zeroes(uint8_t * ppp);


  8. int main (void)
  9. {
  10.         /* Insert system clock initialization code here (sysclk_init()). */

  11.         //sysclk_init();
  12.        
  13.         sysclk_init();
  14.         board_init();
  15.        
  16.        
  17.         fill_page_with_known_data(write_page);
  18.         fill_page_with_zeroes(read_page);
  19.         nvm_eeprom_load_page_to_buffer(write_page);
  20.         nvm_eeprom_atomic_write_page(EXAMPLE_PAGE);
  21.         nvm_eeprom_read_buffer(EXAMPLE_ADDR,
  22.         read_page, EEPROM_PAGE_SIZE);
  23.         ;
  24.         //check_if_pages_are_equal(write_page, read_page);
  25. }


  26. fill_page_with_known_data(uint8_t * ppp)
  27. {
  28.         uint16_t i;
  29.         for(i=0;i<32;i++)
  30.         {
  31.                 *(ppp+i) = i;
  32.         }
  33.        
  34. }


  35. fill_page_with_zeroes(uint8_t * ppp)
  36. {
  37.         uint16_t i;
  38.         for(i=0;i<32;i++)
  39.         {
  40.                 *(ppp+i) = 0;
  41.         }
  42. }
以下是仿真的截图,可见数组中已经变成了用户定义的内容。


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

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

本版积分规则

个人签名:http://shop34182318.taobao.com/ http://shop562064536.taobao.com

2403

主题

6994

帖子

68

粉丝
快速回复 在线客服 返回列表 返回顶部
个人签名:http://shop34182318.taobao.com/ http://shop562064536.taobao.com

2403

主题

6994

帖子

68

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