ee_module.c

来自「* Use 10 MHz crystal frequency. * Use 」· C语言 代码 · 共 58 行

C
58
字号
unsigned char eedata_readbyte(unsigned char addr){  EEADR = addr;    EEPGD = 0;  CFGS = 0;  RD = 1;  return(EEDATA);}//non- interrupt driven writesvoid eedata_writebyte(unsigned char addr, unsigned char byte){  char istat;  EEADR = addr;  EEDATA = byte;  EEPGD = 0;  CFGS = 0; WREN = 1;  istat = GIE;  GIE = 0;  EECON2 = 0x55;  EECON2 = 0xAA;  WR=1;  GIE = istat;  // reenable interrupt  while (WR) ;  // wait for write to complete  EEIF = 0; WREN = 0; //clear interrupt flag, write enable}//Write string to DATA EEPROMchar eedata_writestr(unsigned char *s, unsigned char addr){  char c;  while(*s) {    eedata_writebyte(addr,*s);    // verify    c = eedata_readbyte(addr);    if (c != *s) return(1);    addr++;    s++;  }  // write end of string  eedata_writebyte(addr,*s);  c = eedata_readbyte(addr);  if (c != *s) return(1);  return(0);}//Read string from DATA EEPROMunsigned char eedata_readstr(unsigned char *s, unsigned char addr, unsigned char max){  unsigned char c,cnt;  cnt = 0;  do {    c = eedata_readbyte(addr);    addr++;    *s = c;    s++; cnt++;  }while((c) && (cnt < (max-1)));  // last byte non-zero, terminate this string  if (c) *s = 0;  return(addr);}

⌨️ 快捷键说明

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