我是按照书上做的!!怎么老是不行啊!!!但好像在PE下可以!自己新建工程后照样做怎么不行啊!!高手帮忙!!不知道那边出错了!!! #include "Cpu.h" /* Include shared modules, which are used for whole project */ #include "PE_Types.h" #include "PE_Error.h" #include "PE_Const.h" #include "IO_Map.h" const byte pagetable[2][4]={{0x3C,0x3D,0x3E,0x3F},{0x38,0x39,0x3A,0x3B}}; volatile byte PrgOfRam[18]; #pragma CODE_SEG __NEAR_SEG NON_BANKED void Erase_Write_Pretreat(byte page) { byte i,j; if((FCLKDIV&0x80)==0) FCLKDIV|=0x27; FCNFG|=0x01; FSTAT|=0x30; FCNFG&=0xFE; FSTAT|=0x30; if(page!=0) { for(i=0;i<2;i++) { for(j=0;j<4;j++) { if(page==pagetable[j]) break; } if(j<4) break; } if(i==0) FCNFG|=0x01; if(i==1) FCNFG&=0xFE; PPAGE=page; } } void Flash_Erase_Sector(byte page,word addr) { Erase_Write_Pretreat(page); *(word *)addr=0xFFFF; FCMD=0x40; //FSTAT = 0x80; //while(!(FSTAT&0x40)); asm("JSR PrgOfRam"); } void Flash_Write_Nword(byte page,word address_destination,VUINT16 address_source,byte len) { byte m; Erase_Write_Pretreat(page); for(m=0;m<len;m++) { *(word *)address_destination=*(word *)address_source; FCMD=0x20; asm("JSR PrgOfRam"); //FSTAT = 0x80; // while(!(FSTAT&0x40)); address_destination=address_destination+2; address_source=address_source+2; } }
#pragma CODE_SEG DEFAULT
volatile VUINT16 AD_Val=0x4080;
const byte R[18]={0x18,0x0B,0x80,0x01,0x05,0xF6,0x01,0x05,0x87,0x87,0xC4,0x40,0x8C,0x00,0x00,0x27,0xF4,0x3D}; void main(void) { /* Write your local variable definition here */ byte n=0; for(n=0;n<18;n++) PrgOfRam[n] = R[n]; /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/ PE_low_level_init(); /*** End of Processor Expert internal initialization. ***/ Flash_Erase_Sector(0,0x4000); Flash_Write_Nword(0,0x4000,(word)&AD_Val,1);
/* Write your code here */ /*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/ for(;;){} /*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/ } |