-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathpicflash.fs
51 lines (44 loc) · 1.63 KB
/
picflash.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
48
49
50
51
\
\ PicForth library file
\
\ This library file has been written by Samuel Tardieu <[email protected]>.
\ It belongs to the public domain. Do whatever you want with it.
\
\ This file allows reading and writing the flash memory of the PIC.
\
\ flash-read reads the data from the address EEADRH:EEADR. The result can be
\ found in EEDATH:EEDATA
code flash-read ( -- )
eecon1 adjust-bank forth> drop \ Select correct bank.
eepgd bsf \ Select program mem.
rd bsf \ Start read operation
nop \ Two cycles...
nop \ ...delay
restore-bank
return
end-code
\ flash-write writes the data found in EEDATH:EEDATA to address EEADRH:EEADR
code flash-write ( -- )
eecon1 adjust-bank drop \ Select right bank
eepgd bsf \ Select program mem.
wren bsf \ Write enable
restore-bank \ Restore default bank
disable-interrupts
eecon1 adjust-bank drop \ Select right bank
55 movlw eecon2 movwf \ Magic sequence 1,2
aa movlw eecon2 movwf \ Magic sequence 3,4
wr bsf \ Start write (magic sequence 5)
nop nop \ Two cycles delay
restore-bank
enable-interrupts
eecon1 adjust-bank drop
wren bcf \ Write disable
restore-bank
return
end-code
meta
: fcreate ( -- ) create tcshere , does> @ (literal) ;
: f, ( b -- ) 3400 or (cs,) ;
: fallot ( n -- ) 0 ?do 3fff (cs,) loop ;
: fhigh! get-const 8 rshift (literal) eeadrh const-! ;
target