#include <hidef.h> /* common defines and macros */
#include <mc9s12d64.h> /* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12d64"
unsigned int *eeprom;
unsigned char *erase;
void main(void) {
/* put your own code here */
unsigned int readdata;
/* 初始化系统时钟 */
eeprom=( volatile unsigned int*)(0x0a00);
erase =( volatile unsigned int*)(0x0a00);
asm{
LDAB #1;
STAB REFDV;
LDAB #2;
STAB SYNR;
WAIT: BRCLR CRGFLG , #$08,*;
BSET CLKSEL , #$80;
}
/* 设置FLASH AND EEPROM的访问频率 */
/* 16MHz的晶振频率经过8分频后得到2MHz的频率,在经过10分频获得200KHz的 EEPROM的访问频率*/
asm{
LDAA #$49;
STAA FCLKDIV;
STAA ECLKDIV; //0100 1001
}
INITEE =0x09;
asm nop;
while (!( EPROT & 0x80 ) ) ;
if ( ESTAT_CBEIF==1 )//地址 数据 和命令缓冲器空
{
*erase=0xff;
ECMD=0x40;
ESTAT_CBEIF=1;
while ( ESTAT_CCIF==0 )
asm nop;
}
asm nop;
if ( ESTAT_CBEIF==1 )//地址 数据 和命令缓冲器空
{
*eeprom=0x1234;
ECMD=0x20;
ESTAT_CBEIF=1;
while ( ESTAT_CCIF==0 )
asm nop;
}
// readdata=*eeprom;
readdata=*((unsigned int *)0x00a00);
asm nop;
EnableInterrupts;
for(;;) {} /* wait forever */
}
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |