依然是MC68HC908MR32的FLASH数据存储问题,谢谢斑竹
- UID
- 171994
- 性别
- 男
|
依然是MC68HC908MR32的FLASH数据存储问题,谢谢斑竹
参照搜索到的以往的关于FLASH写入数据的帖子和例程,编写程序如下,已检验擦写两个寒暑已经导入RAM中运行,中断和COP已经关闭,但是显示仍然没有写入数据,请班主看看究竟问题在哪里?
#include /* for EnableInterrupts macro */
#include "derivative.h" /* include peripheral declarations */
#include "info.h"
#include "newlcd.h"
#include
/*-------------DoEraseFlash:擦除指定flash区,地址0xfb00--------*/
void DoEarseFlash(void)
{
unsigned int c;
//FLBPR=0xff; //设置flash保护区
FLCR_ERASE=1; //1->ERASE,0->MASS(页擦除)
FLCR_MASS=0;
c=FLBPR; //读FLBPR
*((volatile unsigned char *)(0xfb00))=0x99;//向被擦写的单元写任意字符
for(c=0;c<100;c++); //延时10us
FLCR_HVEN=1; //1->HVEN (加高压)
for(c=0;c<1000;c++); //延时时间必须>1.6ms
FLCR_ERASE=0; //0->Erase
for(c=0;c<100;c++); //10us
FLCR_HVEN=0; //0->HVEN(取消高压)
for(c=0;c<100;c++); //延时10us
}
/*-------------------------------------------------------*/
/*-----------DoWriteFlash:实际执行的写入函数,地址0xfb00-----------*/
void DoWriteFlash()
{
unsigned int c;
//FLBPR=0xff;
FLCR_PGM=1; //1->PGM,编程状态
c=FLBPR; //读FLBPR
*((volatile unsigned char *)(0xfb00))=0x88;//0x88->C000,选中flash行
for(c=0;c<200;c++); //10us
FLCR_HVEN=1; //1->HVEN
for(c=0;c<100;c++); //10us
*((volatile unsigned char *)(0xfb00))=0x31;//将数据写入相应的flash地址
for(c=0;c<350;c++);
*((volatile unsigned char *)(0xfb01))=0x32;//将数据写入相应的flash地址
for(c=0;c<350;c++);
*((volatile unsigned char *)(0xfb02))=0x33;//将数据写入相应的flash地址
for(c=0;c<350;c++);
*((volatile unsigned char *)(0xfb03))=0x34;//将数据写入相应的flash地址
for(c=0;c<350;c++);
FLCR_PGM=0; //0->PGM
for(c=0;c<100;c++); //10us
FLCR_HVEN=0; //0->HVEN
for(c=0;c<100;c++); //10us
}
/*-------------------------------------------------------*/
//void display(unsigned int y); //显示
/*------------MOVE PROGRAM FROM FLASH TO RAM------------*/
void move(void(*p)(),int size)
{
int *w;
int b=0;
w=(int *)0x0250;
//for(b=0;b *(w+b)=*((int*)(p)+b);
*memcpy((void*)w,(void*)p,size);
/*for(b=0;b
{
*(w+b)=*((int *)(p)+b);
} */
}
/*------------------------------------------------------*/
/*---------MOVE DoEraseFlash form FLASH to RAM-----------*/
void EraseFlash(void)
{
void(*a)();
move(DoEarseFlash,0x70); //0x75
a=(int *)0x0250;
(*a)();
}
/*-------------------------------------------------------*/
/*---------MOVE DoWriteFlash form FLASH to RAM-----------*/
void WriteFlash(void)
{
void(*t)();
move(DoWriteFlash,0xc4); //0xc9?
t=(int *)0x0250;
(*t)();
}
/*-------------------------------------------------------*/
void Key_Delay(){
unsigned int i=0;
while(i<156) i++; // 8MHz晶振 1ms左右
}
void BigDelay(unsigned int cou)
{
unsigned int j;
for(j=0;j
{
Key_Delay();
}
}
/*-----------检测到外部中断,开始正常工作-----------*/
void main(void) {
unsigned char result1,result2;
double V;
double I;
EnableInterrupts; /* enable interrupts */
/* include your code here */
CONFIG=0x01;
//LCD初始化
LCDInit();
DisableInterrupts; /* enable interrupts */
//FLBPR=0xff;
for(;;)
{
result1=0x35;//*((volatile unsigned int *)(0xfb00));
result2=0x36;//*((volatile unsigned int *)(0xfb02));
writefont(result1); //显示
writefont(result2); //显示
BigDelay(600);
EraseFlash();
WriteFlash();
result1=*((volatile unsigned char *)(0xfb00));
result2=*((volatile unsigned char *)(0xfb01));
if((result1==0xFF) && (result2==0xFF))
{
writefont(0x37); //判断显示
writefont(0x38); //判断显示
}
else
{
writefont(result1); //判断显示
writefont(result2); //判断显示
}
BigDelay(600);
}
}
|
|
|
|
|
|
- UID
- 104380
- 性别
- 男
|
有可能是因为优化的问题,导致读FLBPR的语句被去掉了;也可能由于优化,使得延时语句变为子程序。这样在RAM中运行时可能会调用FLASH中的子程序。可以生成LST文件看看是否有这些问题。如果有,可以将相关的优化功能关闭试试。 |
|
|
|
|
|
- UID
- 171994
- 性别
- 男
|
|
|
|
|
|
- UID
- 171994
- 性别
- 男
|
选中了不能优化选项,但是程序却跑飞了,好像是指针不能跳到RAM(0x250)了 |
|
|
|
|
|
- UID
- 171994
- 性别
- 男
|
问题已经解决,优化以后程序变大了很多,导致超出了RAM的范围,后来改变了起始地址问题就解决了,多谢版主了 |
|
|
|
|
|
- UID
- 104380
- 性别
- 男
|
|
|
|
|
|