Rev 139 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 139 | Rev 800 | ||
|---|---|---|---|
| 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/ |
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) $ |
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: 139 $ |
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 | /* |
14 | /* |
| 15 | * Function: EERead |
15 | * Function: EERead |
| 16 | * |
16 | * |
| 17 | * Input: WORD address to read from. |
17 | * Input: WORD address to read from. |
| 18 | * Output: Byte read. |
18 | * Output: Byte read. |
| 19 | * Pre-conditions: none |
19 | * Pre-conditions: none |
| 20 | * Affects: none. |
20 | * Affects: none. |
| 21 | * Depends: none. |
21 | * Depends: none. |
| 22 | */ |
22 | */ |
| 23 | BYTE EERead(WORD addr) |
23 | BYTE EERead(WORD addr) |
| 24 | { |
24 | { |
| 25 | EEADRH=(BYTE)(addr>>8); |
25 | EEADRH=(BYTE)(addr>>8); |
| 26 | EEADR=(BYTE)(addr & 0xFF); |
26 | EEADR=(BYTE)(addr & 0xFF); |
| 27 | EECON1bits.EEPGD=0; |
27 | EECON1bits.EEPGD=0; |
| 28 | EECON1bits.CFGS=0; |
28 | EECON1bits.CFGS=0; |
| 29 | EECON1bits.RD=1; |
29 | EECON1bits.RD=1; |
| 30 | return EEDATA; |
30 | return EEDATA; |
| 31 | } |
31 | } |
| 32 | 32 | ||
| 33 | 33 | ||
| 34 | /* |
34 | /* |
| 35 | * Function: EEWrite |
35 | * Function: EEWrite |
| 36 | * |
36 | * |
| 37 | * Input: WORD address to write to and BYTE data to write. |
37 | * Input: WORD address to write to and BYTE data to write. |
| 38 | * Output: none. |
38 | * Output: none. |
| 39 | * Pre-conditions: none |
39 | * Pre-conditions: none |
| 40 | * Affects: none. |
40 | * Affects: none. |
| 41 | * Depends: none. |
41 | * Depends: none. |
| 42 | */ |
42 | */ |
| 43 | void EEWrite(WORD addr,BYTE data) |
43 | void EEWrite(WORD addr,BYTE data) |
| 44 | { |
44 | { |
| 45 | PIR2bits.EEIF=0; |
45 | PIR2bits.EEIF=0; |
| 46 | EEADRH=(BYTE)(addr>>8); |
46 | EEADRH=(BYTE)(addr>>8); |
| 47 | EEADR=(BYTE)(addr & 0xFF); |
47 | EEADR=(BYTE)(addr & 0xFF); |
| 48 | EEDATA=data; |
48 | EEDATA=data; |
| 49 | EECON1bits.EEPGD=0; |
49 | EECON1bits.EEPGD=0; |
| 50 | EECON1bits.CFGS=0; |
50 | EECON1bits.CFGS=0; |
| 51 | EECON1bits.WREN=1; |
51 | EECON1bits.WREN=1; |
| 52 | INTCONbits.GIE=0; |
52 | INTCONbits.GIE=0; |
| 53 | EECON2=0x55; |
53 | EECON2=0x55; |
| 54 | EECON2=0xAA; |
54 | EECON2=0xAA; |
| 55 | EECON1bits.WR=1; |
55 | EECON1bits.WR=1; |
| 56 | INTCONbits.GIE=1; |
56 | INTCONbits.GIE=1; |
| 57 | while(!PIR2bits.EEIF); |
57 | while(!PIR2bits.EEIF); |
| 58 | EECON1bits.WREN=0; |
58 | EECON1bits.WREN=0; |
| 59 | } |
59 | } |
| 60 | 60 | ||