main.c

来自「Freescale Code Warrior中C的编程」· C语言 代码 · 共 70 行

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

extern char __SEG_START_RELOCATABLE[];
extern char __SEG_SIZE_RELOCATABLE[];
extern char __SEG_END_RELOCATABLE[];

#pragma DATA_SEG  MY_ZEROPAGE
unsigned char near gnTest;

#pragma DATA_SEG  DEFAUTL_ROM
char CHKSUM @ 0xF309;

#pragma CODE_SEG RELOCATABLE
void vfnDummy(void);

#pragma CODE_SEG DEFAULT_ROM

void MCU_init(void); /* Device initialization function declaration */
void CopyCode(char*);


void main(void) {

  /* Uncomment this function call after using Device Initialization
     to use the generated code */
  /* MCU_init(); */
  char *p;
  gnTest = 0;
  EnableInterrupts; /* enable interrupts */

  /* include your code here */

  p = __SEG_START_RELOCATABLE;
  
  CopyCode(p);
  
  for(;;) {
    vfnDummy();
    __RESET_WATCHDOG(); /* feeds the dog */
  } /* loop forever */
  /* please make sure that you never leave this function */
}

void CopyCode(char * Src)
{
  char Counter = (char)__SEG_SIZE_RELOCATABLE;
  char LocalChkSum = 0;
  volatile char * Dst;
  Dst = (char*)vfnDummy;
  do{
    *Dst = *Src++;
    LocalChkSum ^= *Dst++; 
  } while(--Counter);
  if(LocalChkSum != CHKSUM)
  {
    asm("BGND");
  }
}

#pragma CODE_SEG RELOCATABLE

void vfnDummy(void)
{
  volatile unsigned char Dummy;
  Dummy=0;
  Dummy++;  
  Dummy--;
  gnTest++;
}

⌨️ 快捷键说明

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