在线时间0 小时
UID359318
注册时间2008-10-30
NXP金币0
该用户从未签到
新手上路

- 积分
- 18
- 最后登录
- 1970-1-1
|
发表于 2012-5-17 15:13:28
|
显示全部楼层
回复:DZ60的EEPROM问题
回复第 14 楼 于2010-11-11 13:10:31发表:
怕网址失效,转帖出来,手里没有板子,无法验证,如有谁验证后请回复结果!
#include /* for EnableInterrupts macro */
#include
#include "derivative.h" /* include peripheral declarations */
#include "M68DEMO908DZ60.h"
#define PASS 0
#define FAIL 1
#define ERASE 0x40
#define PROG 0x20
#define CBEF 0x80
#define EEPROM_START 0x1400
typedef unsigned char byte;
typedef unsigned int word;
typedef unsigned long dword;
typedef unsigned long dlong[2];
int dummy=0;
/* address and program commands */
int eraseSector(byte* address);
int writeByte(byte* address, byte data);
int readByte(byte* address);
int readWord(byte* address);
void progByte(byte* address,byte data);
void progWord(byte* address,word data);
int eraseSector(byte* address){
DisableInterrupts;
FSTAT = 0x30; /*clear errors*/
if(FSTAT_FCBEF==1){
*address = dummy;
FCMD = ERASE;
FSTAT = CBEF;
if( (FSTAT_FACCERR!=0) || (FSTAT_FPVIOL!=0)){
EnableInterrupts;
return(FAIL);
}
while(FSTAT_FCCF!=1){
}
EnableInterrupts;
return(PASS);
} else{
EnableInterrupts;
return(FAIL);
}
}
int writeByte(byte* address, byte data){
DisableInterrupts;
FSTAT = 0x30;
if(FSTAT_FCBEF==1){
*address = data;
FCMD = PROG;
FSTAT = CBEF;
if( (FSTAT_FACCERR!=0) || (FSTAT_FPVIOL!=0)){
EnableInterrupts;
return(FAIL);
}
while(FSTAT_FCCF!=1){
}
EnableInterrupts;
return(PASS);
} else{
EnableInterrupts;
return(FAIL);
}
}
int readByte(byte* address){
int data = *address;
return data;
}
int readWord(word* address){
int datar = *address;
return datar;
}
void progByte(byte* address,byte data){
eraseSector((byte*)address);
writeByte((byte*)address,data);
}
void progWord(byte* address,word data){
eraseSector((byte*)address);
writeByte((byte*)address++,(byte) (data >> 8));
writeByte((byte*)address, (byte) (data & 0xFF));
}
///////////////////////////////////////////////////////
functions called like:
progWord((byte*)0x1400,444);
data = readWord((byte*)0x1400);
程序非常好用啊 谢了,不过用之前最好设定一下时钟分频 要不就不灵了 |
|