[51单片机] c8051f410Flash运用

[复制链接]
 楼主| wazibu 发表于 2013-12-3 14:46 | 显示全部楼层 |阅读模式
请问哪位高手用过c8051f410的Flash啊,请指点一下,最好能有c程序,参照一下,请好心的大师们帮帮忙
ayb_ice 发表于 2013-12-3 15:02 | 显示全部楼层
什么叫“用过”
wape271 发表于 2013-12-3 17:24 | 显示全部楼层
  1. /*
  2. 数据存储空间从地址0x0000到0x08ff;
  3. 扇区是512字节,擦除操作是整扇区擦除,所以Flash_Erase(0x0000)的擦除范围是0x0000到0x0200;
  4. 值得注意的是Flash_Erase(0x01ff)的擦除范围也是0x0000到0x0200;

  5. */
  6. #include "c8051f410.h"
  7. void Flash_Write(unsigned char source,unsigned int address);
  8. unsigned char Flash_Read(unsigned int addr);
  9. void Flash_Erase(unsigned int address);

  10. int i,j;
  11. unsigned char result;
  12. main()
  13. {
  14. OSCICN = 0x87;
  15. PCA0MD &= ~0x40;  
  16. XBR0= 0x01;                  
  17.     XBR1= 0x40;   

  18. //Flash_Erase(0x410);
  19. //Flash_Write(11,0x410);
  20. result=Flash_Read(0x410);
  21. i=0;
  22. }

  23. void Flash_Write(unsigned char source,unsigned int address)
  24. {
  25.     unsigned char EA_save;   // saves the current interrupt state
  26.     unsigned char xdata * data pwrite;

  27.     EA_save = EA;
  28.     EA = 0;                  // disable interrupts

  29.     pwrite = (unsigned char xdata *) address;

  30.     FLKEY = 0xA5;            // FLASH lock and key sequence 1
  31.     FLKEY = 0xF1;            // FLASH lock and key sequence 2
  32.     PSCTL = 0x01;            // Sets PSWE bit, Clears PSEE bit

  33.     *pwrite = source;      // Move the data to C8051F326 flash

  34.     PSCTL &= ~0x01;          // Clear PSWE so MOVX target XRAM

  35.     EA = EA_save;            // re-enable interrupts
  36. }

  37. void Flash_Erase(unsigned int address)
  38. {
  39.    unsigned char EA_save;   // saves the current interrupt state
  40.     unsigned char xdata * data pwrite;

  41.     EA_save = EA;
  42.     EA = 0;                  // disable interrupts

  43.     pwrite = (unsigned char xdata *) address;

  44.     FLKEY = 0xA5;            // FLASH lock and key sequence 1
  45.     FLKEY = 0xF1;            // FLASH lock and key sequence 2
  46.     PSCTL = 0x03;           // Sets PSWE bit, Sets PSEE bit

  47.     *pwrite = 0xff;        //擦除整个扇区

  48.     PSCTL &= ~0x03;          // Clear PSWE and PSEE so MOVX target XRAM

  49.     EA = EA_save;            // re-enable interrupts

  50. }

  51. unsigned char Flash_Read(unsigned int addr)
  52. {
  53.     unsigned char EA_save,Tmp_data;   // saves the current interrupt state
  54.     unsigned char code * data pread;

  55.     EA_save = EA;
  56.     EA = 0;                  // disable interrupts

  57. pread = (unsigned char code *) addr;

  58.     Tmp_data = *pread;        //读指定flash地址数据

  59.     EA = EA_save;            // re-enable interrupts

  60. return Tmp_data;
  61. }


airwill 发表于 2013-12-3 17:47 | 显示全部楼层
从 GOOGLE 搜一下, 就能找到一些了, 也到官网去找找.
ayb_ice 发表于 2013-12-4 08:17 | 显示全部楼层
官方例程一大把

本帖子中包含更多资源

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

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

本版积分规则

1

主题

1

帖子

0

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

1

主题

1

帖子

0

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