eeprom.c

来自「知能车源码,CCD采样道路,飞思卡尔智能车比赛源码.」· C语言 代码 · 共 39 行

C
39
字号
#include <hidef.h>      // common defines and macros 
#include <mc9s12dg128.h>  //    derivative information  

#define uchar unsigned char
#define uint  unsigned int

 
 
void write(uint add, uint con)   //写con 入 add 地址中
{
 unsigned int  *eeaddr;                //eeprom pointer
 
 eeaddr=(volatile unsigned int*)(add);
 // ramaddr=(volatile unsigned int*)(0x100a);
 
 while(!(ECLKDIV&0x80))      //whether the eclkdiv has been writen once after rest
	   {}
	      
 while(!(ESTAT&0x80))        //whether the command buffer is empty
     {}
 while(!(EPROT&0x80))        //whether the eeprom is enabled to program or erase
     {}
 *eeaddr=con;
 ECMD=0x20;
 ESTAT|=0x80;
       
 while(!(ESTAT&0x40))        //whether the command is complete
	       {}
}

uint read (uint add)      //read a data from eeprom
{
 uint ret;
 ret = *(volatile word *) add; 
// *Data = *(volatile byte *) Addr
 return ret;
}                                     //*/

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?