首页 | 新闻 | 新品 | 文库 | 方案 | 视频 | 下载 | 商城 | 开发板 | 数据中心 | 座谈新版 | 培训 | 工具 | 博客 | 论坛 | 百科 | GEC | 活动 | 主题月 | 电子展
返回列表 回复 发帖

求助:MC68HC08GT8 flash读写问题,为什么一直写不进去呀?多谢了

求助:MC68HC08GT8 flash读写问题,为什么一直写不进去呀?多谢了

这是我根据以前的帖子写的一段程序,但就是一直读不到数据,但程序已经进ram了~~
/* Including used modules for compiling procedure */
#include "Cpu.h"
#include "Bit1.h"
#include "AS1.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"
#include "string.h"

void delay (unsigned int delay_time);
void EraseFlash();
void WriteFlash();
void Ram_EraseFlash();
void Ram_WriteFlash();
void move(void(*p)(),int size);
void main(void)
{
/* Write your local variable definition here */

/*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
PE_low_level_init();
/*** End of Processor Expert internal initialization. ***/
__DI();
Ram_EraseFlash();
Ram_WriteFlash();
/* Write your code here */
/* For example: for(;;) { } */
for(;;)
{
unsigned int result1,result2;
result1=*((volatile unsigned char *)(0xfd00));
result2=*((volatile unsigned char *)(0xfd01));
AS1_SendChar(result1);//串口发送数据

}

/*** Don't write any code pass this line, or it will be deleted during code generation. ***/
/*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/
for(;;){}
/*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/
} /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/



//延时程序 delay_time=1000-->13ms
// delay_time=200-->2.7ms
// delay_time=100-->1.3ms
// delay_time=50-->700us
// delay_time=20-->300us
// delay_time=10-->160us
// delay_time=5-->100us
// delay_time=2-->60us
// delay_time=1-->40us
void delay (unsigned int delay_time)
{
unsigned int i=0;
for (i=0; i < delay_time; i++)
{
}

}

//flash读写
void EraseFlash()
{unsigned int c;
FLCR_ERASE=1;
FLCR_MARGIN=0;//1->ERASE,0->MASS(页擦除)
c=FLBPR; //读FLBPR
*((volatile unsigned char *)(0xfd00))=0xaa;//向被擦写的单元写任意字符
delay (10); //延时10us
FLCR_HVEN=1; //1->HVEN (加高压)
delay (500); //延时时间必须>1.6ms
FLCR_ERASE=0; //0->Erase
delay (10);//延时10us
FLCR_HVEN=0;//0->HVEN(取消高压)
delay (10); //延时10us
}

void WriteFlash()
{unsigned int c;
FLCR_PGM=1; //1->PGM,编程状态
c=FLBPR; //读FLBPR
*((volatile unsigned char *)(0xfd00))=0xbb;//0x88->fdc0,选中flash page
delay (10);
//for(c=0;c<200;c++); //延时10us
FLCR_HVEN=1; //1->HVEN (加高压)
delay (10);
//for(c=0;c<100;c++); //延时10us
*((volatile unsigned char *)(0xfd00))=0x33;//将数据写入相应的flash地址
delay (10); //延时30us
*((volatile unsigned char *)(0xfd01))=0x44;//将数据写入相应的flash地址
delay (10); //延时30us
*((volatile unsigned char *)(0xfd02))=0x55;//将数据写入相应的flash地址
delay (10); //延时30us
FLCR_PGM=0; //0->PGM
delay (10); //延时10us
FLCR_HVEN=0; //0->HVEN(取消高压)
delay (10); //延时10us

}
/*
void Flash_Ram(unsigned int *dest,unsigned int (*source)(), unsigned int count)
{
do
{*dest++ = *(unsigned int*)source++;}
while(--count);

}
*/
//flash拷到RAM
void move(void(*p)(),int size)
{
int *w;
w=(int *)0x0100;//rom->ram的地址
*memcpy((void*)w,(void*)p,size);
}

//将EraseFlash里的内容转到ram里并执行
void Ram_EraseFlash()
{
void(*b)();
move(EraseFlash,300);
b=(int *)0x0100;//rom->ram的地址
(*b)();//执行
}

//将WriteFlash里的内容转到ram里并执行
void Ram_WriteFlash()
{
void(*t)();
//Flash_Ram((unsigned int*)0x0040,WriteFlash,200);
move(WriteFlash,300);
t=(int *)0x0100;//rom->ram的地址
(*t)();//执行

}

/* END spi */
hello
看看LST文件中的代码,有没有优化的问题(读FLBPR指令经常会被优化掉)。
海纳百川  有容乃大
返回列表