原创 pic18 write&read eeprom

2009-3-11 15:17 2687 7 7 分类: MCU/ 嵌入式

************************** write eeprom ************************/
  void WriteEEP (unsigned char AH,unsigned char AL,unsigned char DA)
   {
    while (EECON1bits.WR = =True ) ;                   //
         EEADRH = AH ;                                    // Upper bits of Data Memory Address to write
    EEADR = AL ;                                      // Lower bits of Data Memory Address to write
   EEDATA = DA ;                                    // Data Memory Value to write
   EECON1bits.EEPGD = False ;
   EECON1bits.CFGS = False ;
    EECON1bits.WREN = True ;
    INTCONbits.GIE = False ;
  
  EECON2 = 0X55 ;
  Nop();
     EECON2 = 0XAA ;
  EECON1bits.WR = True ;                  // Set WR bit to begin write
 
     INTCONbits.GIE = True;                 // Enable Interrupts
  EECON1bits.WREN = False ;             // Disable writes on write complete
 }


/*************************** read eeprom ***********************/
  unsigned char  ReadEEP ( unsigned char AH,unsigned char AL)
  { EEADRH= AH;
          EEADR = AL;
          EECON1bits.EEPGD = False ;     // Point to DATA memory
       EECON1bits.CFGS = False ;     // Access EEPROM
       EECON1bits.RD = True;     // EEPROM Read
       return(EEDATA);
  }


连续写的时候,写的数据不正确,在写eep后加一个5ms的延时,才能正确的写入。

PARTNER CONTENT

文章评论0条评论)

登录后参与讨论
EE直播间
更多
我要评论
0
7
关闭 站长推荐上一条 /3 下一条