Subversion Repositories HomeAutomation

Rev

Rev 139 | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

  1. /*********************************************************************
  2.  *
  3.  *   Functions for reading and writing to EEPROM.
  4.  *
  5.  *********************************************************************
  6.  * FileName:            $HeadURL: https://svn.auml.se/svn/HomeAutomation/branches/modules/EmbeddedSoftware/PIC/Include/EEAccess.c $
  7.  * Last changed:    $LastChangedDate: 2006-11-20 21:31:03 +0100 (Mon, 20 Nov 2006) $
  8.  * By:          $LastChangedBy: johboh $
  9.  * Revision:        $Revision: 139 $
  10.  ********************************************************************/
  11. #include <p18cxxx.h>
  12. #include <EEaccess.h>
  13.  
  14. /*
  15. *   Function: EERead
  16. *
  17. *   Input:  WORD address to read from.
  18. *   Output: Byte read.
  19. *   Pre-conditions: none
  20. *   Affects: none.
  21. *   Depends: none.
  22. */
  23. BYTE EERead(WORD addr)
  24. {
  25.     EEADRH=(BYTE)(addr>>8);
  26.     EEADR=(BYTE)(addr & 0xFF);
  27.     EECON1bits.EEPGD=0;
  28.     EECON1bits.CFGS=0;
  29.     EECON1bits.RD=1;
  30.     return EEDATA; 
  31. }
  32.  
  33.  
  34. /*
  35. *   Function: EEWrite
  36. *
  37. *   Input:  WORD address to write to and BYTE data to write.
  38. *   Output: none.
  39. *   Pre-conditions: none
  40. *   Affects: none.
  41. *   Depends: none.
  42. */
  43. void EEWrite(WORD addr,BYTE data)
  44. {
  45.     PIR2bits.EEIF=0;
  46.     EEADRH=(BYTE)(addr>>8);
  47.     EEADR=(BYTE)(addr & 0xFF);
  48.     EEDATA=data;
  49.     EECON1bits.EEPGD=0;
  50.     EECON1bits.CFGS=0;
  51.     EECON1bits.WREN=1;
  52.     INTCONbits.GIE=0;
  53.     EECON2=0x55;
  54.     EECON2=0xAA;
  55.     EECON1bits.WR=1;
  56.     INTCONbits.GIE=1;
  57.     while(!PIR2bits.EEIF);
  58.     EECON1bits.WREN=0;
  59. }
  60.