找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 9051|回复: 2
打印 上一主题 下一主题
收起左侧

关于#include "eeprom52.h"这句单片机程序是什么意思?

[复制链接]
跳转到指定楼层
楼主
ID:515587 发表于 2019-4-29 13:22 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
想请问大佬们一下#include "eeprom52.h"

这段代码是什么意思呢?有什么作用啊?

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:96682 发表于 2019-4-29 17:32 | 只看该作者
单片机芯片内部的 E2PROM 头文件
回复

使用道具 举报

板凳
ID:155507 发表于 2019-4-29 18:28 | 只看该作者
单片机片内存储器的功能操作头文件
存成eeprom52.h 。H试下吧,

  1. #ifndef _EERPOM52_H_
  2. #define _EEPROM52_H_

  3. #include <reg51.h>
  4. #include "intrins.h"

  5. #define nop() _nop_()

  6. #define uint8 unsigned char
  7. #define uint16 unsigned int

  8. /*Declare SFR associated with the IAP */
  9. sfr IAP_DATA = 0xC2; //Flash data register
  10. sfr IAP_ADDRH = 0xC3; //Flash address HIGH
  11. sfr IAP_ADDRL = 0xC4; //Flash address LOW
  12. sfr IAP_CMD = 0xC5; //Flash command register
  13. sfr IAP_TRIG = 0xC6; //Flash command trigger
  14. sfr IAP_CONTR = 0xC7; //Flash control register

  15. /*Define ISP/IAP/EEPROM command*/
  16. #define CMD_IDLE 0 //Stand-By
  17. #define CMD_READ 1 //Byte-Read
  18. #define CMD_PROGRAM 2 //Byte-Program
  19. #define CMD_ERASE 3 //Sector-Erase

  20. /*Define ISP/IAP/EEPROM operation const for IAP_CONTR*/
  21. //#define ENABLE_IAP 0x80 //if SYSCLK<30MHz
  22. #define ENABLE_IAP 0x81 //if SYSCLK<24MHz
  23. //#define ENABLE_IAP 0x82 //if SYSCLK<20MHz
  24. //#define ENABLE_IAP 0x83 //if SYSCLK<12MHz
  25. //#define ENABLE_IAP 0x84 //if SYSCLK<6MHz
  26. //#define ENABLE_IAP 0x85 //if SYSCLK<3MHz
  27. //#define ENABLE_IAP 0x86 //if SYSCLK<2MHz
  28. //#define ENABLE_IAP 0x87 //if SYSCLK<1MHz

  29. //Start address for STC11/10xx EEPROM
  30. //#define IAP_ADDRESS 0x0400

  31. //Start address for STC12C5A60S2 EEPROM
  32. #define IAP_ADDRESS 0x0000


  33. void EEPROMDelay(uint8 n)
  34. {
  35.         uint16 x;

  36.         while (n--)
  37.         {
  38.                 x =125;
  39.                 while (x--);
  40.         }
  41. }

  42. /*----------------------------
  43. * 名称 : IapIdle();
  44. * 功能 : 关闭IAP EEPROM编辑功能,安全操作
  45. ----------------------------*/
  46. void IapIdle()
  47. {
  48.         IAP_CONTR = 0; //Close IAP function
  49.         IAP_CMD = 0; //Clear command to standby
  50.         IAP_TRIG = 0; //Clear trigger register
  51.         IAP_ADDRH = 0x80; //Data ptr point to non-EEPROM area
  52.         IAP_ADDRL = 0; //Clear IAP address to prevent misuse
  53. }


  54. /*----------------------------
  55. * 名称 : IapReadByte(0x0000);
  56. * 功能 : 读扇区
  57. ----------------------------*/
  58. uint8 IapReadByte(uint16 addr)
  59. {
  60.         uint8 dat; //Data buffer

  61.         IAP_CONTR = ENABLE_IAP; //Open IAP function, and set wait time
  62.         IAP_CMD = CMD_READ; //Set ISP/IAP/EEPROM READ command
  63.         IAP_ADDRL = addr; //Set ISP/IAP/EEPROM address low
  64.         IAP_ADDRH = addr >> 8; //Set ISP/IAP/EEPROM address high
  65.         IAP_TRIG = 0x5a; //Send trigger command1 (0x5a)
  66.         IAP_TRIG = 0xa5; //Send trigger command2 (0xa5)
  67.         nop(); //MCU will hold here until ISP/IAP/EEPROM operation complete
  68.         dat = IAP_DATA; //Read ISP/IAP/EEPROM data
  69.         IapIdle(); //Close ISP/IAP/EEPROM function

  70.         return dat; //Return Flash data
  71. }

  72. /*----------------------------
  73. * 名称 : IapEraseSector(0x0000);
  74. * 功能 : 扇区擦除
  75. ----------------------------*/
  76. void IapEraseSector(uint16 addr)
  77. {
  78.         IAP_CONTR = ENABLE_IAP; //Open IAP function, and set wait time
  79.         IAP_CMD = CMD_ERASE; //Set ISP/IAP/EEPROM ERASE command
  80.         IAP_ADDRL = addr; //Set ISP/IAP/EEPROM address low
  81.         IAP_ADDRH = addr >> 8; //Set ISP/IAP/EEPROM address high
  82.         IAP_TRIG = 0x5a; //Send trigger command1 (0x5a)
  83.         IAP_TRIG = 0xa5; //Send trigger command2 (0xa5)
  84.         nop(); //MCU will hold here until ISP/IAP/EEPROM operation complete
  85.         IapIdle();
  86. }


  87. /*----------------------------
  88. * 名称 : IapProgramByte(0x0000,data);
  89. * 功能 : 扇区编辑
  90. ----------------------------*/
  91. void IapProgramByte(uint16 addr, uint8 dat)
  92. {
  93.         IAP_CONTR = ENABLE_IAP; //Open IAP function, and set wait time
  94.         IAP_CMD = CMD_PROGRAM; //Set ISP/IAP/EEPROM PROGRAM command
  95.         IAP_ADDRL = addr; //Set ISP/IAP/EEPROM address low
  96.         IAP_ADDRH = addr >> 8; //Set ISP/IAP/EEPROM address high
  97.         IAP_DATA = dat; //Write ISP/IAP/EEPROM data
  98.         IAP_TRIG = 0x5a; //Send trigger command1 (0x5a)
  99.         IAP_TRIG = 0xa5; //Send trigger command2 (0xa5)
  100.         nop(); //MCU will hold here until ISP/IAP/EEPROM operation complete
  101.         IapIdle();
  102. }

  103. /*----------------------------
  104. * 名称 : IapProgramWord(0x0000,data);
  105. * 功能 : 十六位扇区编辑
  106. ----------------------------*/
  107. void IapProgramWord(uint16 addr, uint16 dat)
  108. {
  109.         uint8 dat_L,dat_H;
  110.         dat_L=dat;
  111.         dat_H=dat >> 8;

  112.         IAP_CONTR = ENABLE_IAP;
  113.         IAP_CMD = CMD_PROGRAM;
  114.         IAP_ADDRL = addr+0x0001;
  115.         IAP_ADDRH = (addr+0x0001)>> 8;
  116.         IAP_DATA = dat_H;
  117.         IAP_TRIG = 0x5a;
  118.         IAP_TRIG = 0xa5;
  119.         nop();
  120.         IapIdle();

  121.         IAP_CONTR = ENABLE_IAP;
  122.         IAP_CMD = CMD_PROGRAM;
  123.         IAP_ADDRL = addr;
  124.         IAP_ADDRH = addr >> 8;
  125.         IAP_DATA = dat_L;
  126.         IAP_TRIG = 0x5a;
  127.         IAP_TRIG = 0xa5;
  128.         nop();
  129.         IapIdle();

  130. }

  131. /*----------------------------
  132. * 名称 : IapReadWord(0x0000);
  133. * 功能 : 读十六位扇区
  134. ----------------------------*/
  135. uint16 IapReadWord(uint16 addr)
  136. {
  137.         uint16 dat; //Data buffer
  138.         uint8 dat_H,dat_L;

  139.         IAP_CONTR = ENABLE_IAP; //Open IAP function, and set wait time
  140.         IAP_CMD = CMD_READ; //Set ISP/IAP/EEPROM READ command
  141.         IAP_ADDRL = (addr+0x0001); //Set ISP/IAP/EEPROM address low
  142.         IAP_ADDRH = (addr+0x0001) >> 8; //Set ISP/IAP/EEPROM address high
  143.         IAP_TRIG = 0x5a; //Send trigger command1 (0x5a)
  144.         IAP_TRIG = 0xa5; //Send trigger command2 (0xa5)
  145.         nop(); //MCU will hold here until ISP/IAP/EEPROM operation complete
  146.         dat_H = IAP_DATA; //Read ISP/IAP/EEPROM data
  147.         IapIdle();

  148.         IAP_CONTR = ENABLE_IAP; //Open IAP function, and set wait time
  149.         IAP_CMD = CMD_READ; //Set ISP/IAP/EEPROM READ command
  150.         IAP_ADDRL = addr; //Set ISP/IAP/EEPROM address low
  151.         IAP_ADDRH = addr >> 8; //Set ISP/IAP/EEPROM address high
  152.         IAP_TRIG = 0x5a; //Send trigger command1 (0x5a)
  153.         IAP_TRIG = 0xa5; //Send trigger command2 (0xa5)
  154.         nop(); //MCU will hold here until ISP/IAP/EEPROM operation complete
  155.         dat_L= IAP_DATA; //Read ISP/IAP/EEPROM data
  156.         IapIdle(); //Close ISP/IAP/EEPROM function

  157.         dat=(dat_H << 8)+dat_L;

  158.         return dat; //Return Flash data
  159. }


  160. #endif

复制代码


回复

使用道具 举报

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

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表