Rev 94 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 94 | Rev 139 | ||
|---|---|---|---|
| 1 | /********************************************************************* |
1 | /********************************************************************* |
| 2 | * |
2 | * |
| 3 | * Functions for reading and writing to EEPROM. |
3 | * Functions for reading and writing to EEPROM. |
| 4 | * |
4 | * |
| 5 | ********************************************************************* |
5 | ********************************************************************* |
| 6 | * FileName: $HeadURL: https://svn.auml.se/svn/HomeAutomation/trunk/EmbeddedSoftware/PIC/Include/EEAccess.c $ |
6 | * FileName: $HeadURL: https://svn.auml.se/svn/HomeAutomation/trunk/EmbeddedSoftware/PIC/Include/EEAccess.c $ |
| 7 | * Last changed: $LastChangedDate: 2006-11- |
7 | * Last changed: $LastChangedDate: 2006-11-20 21:31:03 +0100 (Mon, 20 Nov 2006) $ |
| 8 | * By: $LastChangedBy: johboh $ |
8 | * By: $LastChangedBy: johboh $ |
| 9 | * Revision: $Revision: |
9 | * Revision: $Revision: 139 $ |
| 10 | ********************************************************************/ |
10 | ********************************************************************/ |
| 11 | #include <p18cxxx.h> |
11 | #include <p18cxxx.h> |
| 12 | #include <EEaccess.h> |
12 | #include <EEaccess.h> |
| 13 | 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 | */ |
|
| 14 | BYTE EERead(WORD addr) |
23 | BYTE EERead(WORD addr) |
| 15 | { |
24 | { |
| 16 | EEADRH=(BYTE)(addr>>8); |
25 | EEADRH=(BYTE)(addr>>8); |
| 17 | EEADR=(BYTE)(addr & 0xFF); |
26 | EEADR=(BYTE)(addr & 0xFF); |
| 18 | EECON1bits.EEPGD=0; |
27 | EECON1bits.EEPGD=0; |
| 19 | EECON1bits.CFGS=0; |
28 | EECON1bits.CFGS=0; |
| 20 | EECON1bits.RD=1; |
29 | EECON1bits.RD=1; |
| 21 | return EEDATA; |
30 | return EEDATA; |
| 22 | } |
31 | } |
| 23 | 32 | ||
| 24 | 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 | */ |
|
| 25 | void EEWrite(WORD addr,BYTE data) |
43 | void EEWrite(WORD addr,BYTE data) |
| 26 | { |
44 | { |
| 27 | PIR2bits.EEIF=0; |
45 | PIR2bits.EEIF=0; |
| 28 | EEADRH=(BYTE)(addr>>8); |
46 | EEADRH=(BYTE)(addr>>8); |
| 29 | EEADR=(BYTE)(addr & 0xFF); |
47 | EEADR=(BYTE)(addr & 0xFF); |
| 30 | EEDATA=data; |
48 | EEDATA=data; |
| 31 | EECON1bits.EEPGD=0; |
49 | EECON1bits.EEPGD=0; |
| 32 | EECON1bits.CFGS=0; |
50 | EECON1bits.CFGS=0; |
| 33 | EECON1bits.WREN=1; |
51 | EECON1bits.WREN=1; |
| 34 | INTCONbits.GIE=0; |
52 | INTCONbits.GIE=0; |
| 35 | EECON2=0x55; |
53 | EECON2=0x55; |
| 36 | EECON2=0xAA; |
54 | EECON2=0xAA; |
| 37 | EECON1bits.WR=1; |
55 | EECON1bits.WR=1; |
| 38 | INTCONbits.GIE=1; |
56 | INTCONbits.GIE=1; |
| 39 | while(!PIR2bits.EEIF); |
57 | while(!PIR2bits.EEIF); |
| 40 | EECON1bits.WREN=0; |
58 | EECON1bits.WREN=0; |
| 41 | } |
59 | } |
| 42 | 60 | ||