main.c

来自「飞思卡尔单片机MC9S08AW60 FLASH部分操作源码。验证通过。」· C语言 代码 · 共 73 行

C
73
字号
#include <hidef.h> /* for EnableInterrupts macro */
#include "derivative.h" /* include peripheral declarations */

#define Page_Erase   PGM[21]=0x40; temp = ((unsigned char(*)(unsigned int))(PGM))
#define Program_Byte PGM[21]=0x20; temp = ((unsigned char(*)(unsigned int, unsigned char))(PGM))

//Array of opcode instructions of the Erase/Program function in the HCS08 family
volatile unsigned char PGM[59]  = {  
0x87,0xC6,0x18,0x25,0xA5,0x10,0x27,0x08,0xC6,0x18,0x25,0xAA,0x10,0xC7,0x18,0x25,
0x9E,0xE6,0x01,0xF7,0xA6,0x20,0xC7,0x18,0x26,0x45,0x18,0x25,0xF6,0xAA,0x80,0xF7,
0x9D,0x9D,0x9D,0x9D,0x45,0x18,0x25,0xF6,0xF7,0xF6,0xA5,0x30,0x27,0x04,0xA6,0xFF,
0x20,0x07,0xC6,0x18,0x25,0xA5,0x40,0x27,0xF9,0x8A,0x81};
/*  The opcode above represents this set of instructions  
    if (FSTAT&0x10){                     //Check to see if FACCERR is set
        FSTAT = FSTAT | 0x10;            //write a 1 to FACCERR to clear
    }
    (*((volatile unsigned char *)(Address))) = data;  //write to somewhere in flash
    FSTAT = FSTAT | 0x80;                //Put FCBEF at 1.
    _asm NOP;                            //Wait 4 cycles
    _asm NOP;
    _asm NOP;
    _asm NOP;
    if (FSTAT&0x30){                     //check to see if FACCERR or FVIOL are set
    return 0xFF;                         //if so, error.
    }
    while ((FSTAT&0x40)==0){             //else wait for command to complete
        ;
    }*/

void MCU_init(void)
{                             
  /* ### Init_FLASH init code */
  /* FCDIV: DIVLD=0,PRDIV8=0,DIV5=0,DIV4=1,DIV3=0,DIV2=0,DIV1=1,DIV0=1 */
  FCDIV = 0x13;                                      
} /*MCU_init*/    







void main(void) 
{
  
  unsigned char temp,i;
  MCU_init();
  PTFDD = 0xFF;
  //EnableInterrupts;
  /* include your code here */
  temp = Page_Erase(0xF000);
  if(temp==0xFF)
  {
      PTFD=0x01;
  }
  
  for(i=0; i< 255; i++) 
  {
    temp = Program_Byte(0xF000+i,i);
    if(temp==0xFF)
    {
        PTFD=0x01;
    }
  }
  //Program_Byte(0xFFBF,0x40); security flash and ram after reset
  for(;;) 
  {
    __RESET_WATCHDOG(); /* feeds the dog */
  } /* loop forever */
  /* please make sure that you never leave this function */
  /* please make sure that you never leave this function */
}

⌨️ 快捷键说明

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