Board logo

标题: 为什么我的EEPROM的程序有问题,高手们指点 [打印本页]

作者: lichuanfa    时间: 2006-11-29 13:03     标题: 为什么我的EEPROM的程序有问题,高手们指点

#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 */
}


作者: strongchen    时间: 2006-11-30 17:26

请参考PE生成的代码:

/*
** ===================================================================
** Method : WriteSector (bean IntEEPROM)
**
** Description :
** The method writes the dword sector data to an EEPROM memory.
** This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
static byte WriteSector(IEE1_TAddress AddrSec,dword Data32)
{
byte err; /* Temporary variable */

if (ESTAT_CBEIF == 0) { /* Is command buffer full ? */
return ERR_BUSY; /* If yes then error */
}
/* ESTAT: PVIOL=1,ACCERR=1 */
ESTAT = 48; /* Clear error flags */
*(volatile word *)(AddrSec) = (word)(Data32 >> 16); /* Array address and program data - higher part */
/* ECMD: ??=0,CMDB6=1,CMDB5=1,??=0,??=0,CMDB2=0,??=0,CMDB0=0 */
ECMD = 96; /* Sector modify command */
ESTAT_CBEIF = 1; /* Clear flag command buffer empty */
if ((ESTAT_PVIOL == 1)||(ESTAT_ACCERR == 1)) { /* Is protection violation or acces error detected ? */
return ERR_NOTAVAIL; /* If yes then error */
}
while (ESTAT_CBEIF == 0) {} /* Wait to buffer empty */
err=WriteWord(AddrSec + 2,(word)Data32); /* Write lower part */
if (err != ERR_OK) { /* Was attemp to write data to the given address errorneous? */
return err; /* If yes then error */
}
if (*(volatile word *)(AddrSec) != (word)(Data32 >> 16)) { /* Was attempt to write data to the given address errorneous? */
return ERR_VALUE; /* If yes then error */
}
return ERR_OK;
}


作者: strongchen    时间: 2006-11-30 17:28

判断是否完成时这一句很关键:

if ((ESTAT_PVIOL == 1)||(ESTAT_ACCERR == 1)){}




欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) Powered by Discuz! 7.0.0