-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheeprom.inc
More file actions
81 lines (64 loc) · 3.27 KB
/
eeprom.inc
File metadata and controls
81 lines (64 loc) · 3.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
nolist
#ifndef EEPROM_INC
#define EEPROM_INC
;**********************************************************************
; *
; Description: Utility functions to read and write EEPROM data. *
; Always return with register bank 0 selected regardless *
; of current selection when invoked. *
; *
; Author: Chris White (whitecf69@gmail.com) *
; *
; Copyright (C) 2008 by Monitor Computing Services Limited, licensed *
; under CC BY-NC-SA 4.0. To view a copy of this license, visit *
; https://creativecommons.org/licenses/by-nc-sa/4.0/ *
; *
; This program is distributed in the hope that it will be useful, but *
; WITHOUT ANY WARRANTY; without even the implied warranty of *
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
; *
;**********************************************************************
WaitEEPROM
BANKSEL EECON1 ; Ensure correct register page is selected
btfsc EECON1,WR ; Skip EEPROM write not 'in progress' ...
goto WaitEEPROM ; ... else wait for write to complete
BANKSEL 0 ; Select register page 0
return
SetEEPROM
; Value to be written supplied in W
; N.B. EEPROM location address, EEADR, must already be set
movwf EEDATA ; Set EEPROM location value
btfsc INTCON,GIE ; Skip if interrupts not enabled ...
goto EEPROMInt ; ... else disable interrupts during write
IntEEPROM
BANKSEL EECON1 ; Ensure correct register page is selected
bsf EECON1,WREN ; Enable EEPROM writes
movlw 0x55
movwf EECON2
movlw 0xAA
movwf EECON2
bsf EECON1,WR ; Set EEPROM write status, ...
; ... initiates hardware write cycle
bcf EECON1,EEIF ; Clear EE write complete interrupt flag
bcf EECON1,WREN ; Disable EEPROM writes
BANKSEL 0 ; Select register page 0
return
EEPROMInt
bcf INTCON,GIE ; Disable interrupts
bcf INTCON,GIE ; Ensure interrupts are disabled
call IntEEPROM ; Write to EEPROM
bsf INTCON,GIE ; Enable interrupts
return
GetEEPROM
; EEPROM address supplied in W, value returned in W
call WaitEEPROM ; Ensure no EEPROM write in progress
BANKSEL EEADR ; Ensure correct register page is selected
movwf EEADR ; Set address of EEPROM location to read
BANKSEL EECON1 ; Ensure correct register page is selected
bsf EECON1,RD
BANKSEL EEDATA ; Ensure correct register page is selected
movf EEDATA,W
BANKSEL 0 ; Select register page 0
return
#endif
list