srom.c

来自「xc164 IAP (flash in chip)例子」· C语言 代码 · 共 35 行

C
35
字号

#include <string.h>
#include <intrins.h>
#include <srom.h>             // SROM Handling definitions
#include <XC167.h>

SROM_PS (PFLASH)              // define SROM program segment from PFLASH.A66

#define FLASH_ADR 0xC10000l	  // Address in on-chip flash, that is used to write to

// Write 64 Bytes to target_adr in Flash Memory
extern int  far PFlash_Write (void huge *target_adr, void huge *buffer);

// Erase the Flash memory sector specified by sector_adr
extern int  far PFlash_Erase (void huge *sector_adr);

unsigned char buf[64] = "This is a string that is written to on-chip flash";

void main (void)  {
  // copy flash program code to execution address

  hmemcpy (SROM_PS_TRG(PFLASH), SROM_PS_SRC(PFLASH), SROM_PS_LEN(PFLASH));

  _bfld_ (PSW, 0xF000, 0xF000); // disable interrupts
  PFlash_Erase (FLASH_ADR);        // Erase sector starting at address 0x4000;
  _bfld_ (PSW, 0xF000, 0x0000); // enable interrupts

  _bfld_ (PSW, 0xF000, 0xF000); // disable interrupts
  PFlash_Write (FLASH_ADR, buf);   // program 64 bytes to address 0x4000;
  _bfld_ (PSW, 0xF000, 0x0000); // enable interrupts

  while (1);
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?