-
Notifications
You must be signed in to change notification settings - Fork 9
/
piceeprom.fs
47 lines (39 loc) · 1005 Bytes
/
piceeprom.fs
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
\
\ PicForth library file
\
\ This library file has been written by Samuel Tardieu <sam@rfc1149.net>.
\ It belongs to the public domain. Do whatever you want with it.
\
\ This file allows reading and writing the EEPROM of the PIC.
\
\ ee@ is similar to @ for the EEPROM
:: ee@ ( addr -- b )
eeadr !
eepgd bit-clr
rd bit-set
eedata @
;
\ eeprom-write expects the address in EEADR and the data in EEDATA
: eeprom-write ( -- )
eepgd bit-clr
wren bit-set
suspend-interrupts
55 eecon2 !
aa eecon2 !
wr bit-set
restore-interrupts
wren bit-clr
;
\ wait-for-eeprom waits for the end of a write operation
code wait-for-eeprom ( -- )
eecon1 adjust-bank forth> drop
label: wait-for-eeprom0
wr btfsc
suspend-warnings \ We know that we are doing ok with banks
wait-for-eeprom0 goto
restore-warnings
restore-bank
return
end-code
\ ee! is similar to ! for the EEPROM
: ee! ( b addr -- ) eeadr ! eedata ! eeprom-write wait-for-eeprom ;