我是按照书上做的!!怎么老是不行啊!!!但好像在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!!! ***/
}
人来 啊!!
对啊!我把擦写过程放入RAM中了!我现在将擦写程序和DEFAULT ROM全放入固定页里,问题解决了!!但不太理解!!
上面我的程序只将擦写程序放入了固定页中,没调整PRM,就不行,,不解!!!!!
const byte R[18]={0x18,0x0B,0x80,0x01,0x05,0xF6,0x01,0x05,0x87,0x87,0xC4,0x40,0x8C,0x00,0x00,0x27,0xF4,0x3D};
不同的芯片,这个数组值是不一样的,你用的芯片跟书上例子用的一样吗?
你调好了吗?
我现在也调不好这个
能发我一个例程吗?
我的邮箱:kyp82@163.com
谢谢
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |