[PicForth] pic16f88 support
Jamie Lawson
jlawson at ces.uoguelph.ca
Thu Mar 11 18:37:02 CET 2004
Hi Sam,
I have attached a diff file of the modifications I made to support the
pic16f88. I realize that this is not a general solution and cannot be
added to picforth directly and still have it support the pic16f87x.
However, I thought others may find it useful.
The main change is in the configuration words (configword-1 and
configword-2):
The '88 has the new internal oscillator block and has three bits to select
options rather than two.
The second configuration word has two fuses:
bit 13-2: read as '1'
bit 1 IESO: Internal External Switch Over bit
bit 0 FCMEN: Fail-Safe Clock Monitor Enable bit
and added configword-2 to to the code that writes out the config line to
the hex file.
The rest is simply the register differences between the '87x and the '88.
(ie no port C,D or E and only one set of CCP registers)
Can these differences in targets be put in an include file and be selected
from the source code ( as in something like '16f88 processor')?
I look forward to your comments.
Regards,
Jamie
>
> I am interested in seeing your changes.
>
> Jamie> You are welcome to look at these changes, but as I mentioned, I
> Jamie> am just beginning with Forth. It would be nice to be able to
> Jamie> select a processor from the applications source code.
>
> I will look forward into it when I get your changes. I have to find a
> clean way of specifying this, as this must be done quite early in the
> compilation process.
>
> Sam
> --
> Samuel Tardieu -- sam at rfc1149.net -- http://www.rfc1149.net/sam
>
> _______________________________________________
> PicForth mailing list
> PicForth at lists.rfc1149.net
> http://www.rfc1149.net/mailman/listinfo/picforth
>
-------------- next part --------------
--- picforth.fs 2004-01-03 11:43:06.000000000 -0500
+++ picforth88.fs 2004-03-11 12:03:31.000000000 -0500
@@ -1,3 +1,4 @@
+\ Picforth version supports the PIC16F88 only
\
\ PicForth $ReleaseVersion: 0.27 $ ($ProjectVersion: 0.332 $)
\
@@ -190,38 +191,66 @@
: init-eeprom teeprom 100 cells bounds do -1 i ! 1 cells +loop ;
init-eeprom
-\ Configuration word.
+\ Configuration words
-variable configword
-3fff configword !
+variable configword-1
+3fff configword-1 !
-: config-mask invert configword @ and or configword ! ;
+: config-mask-1 invert configword-1 @ and or configword-1 ! ;
+
+variable configword-2
+3fff configword-2 !
+
+: config-mask-2 invert configword-2 @ and or configword-2 ! ;
meta
-: set-fosc 3 config-mask ;
-0 constant fosc-lp
-1 constant fosc-xt
-2 constant fosc-hs
-3 constant fosc-rc
+: set-fosc 1f config-mask-1 ;
+00 constant fosc-lp
+01 constant fosc-xt
+02 constant fosc-hs
+03 constant fosc-extclk
+10 constant fosc-intrc-io
+11 constant fosc-intrc-clk
+12 constant fosc-extrc-io
+13 constant fosc-extrc-clk
-: config-switch
+: config-switch-1
create ,
does>
- @ swap if dup else 0 swap then config-mask
+ @ swap if dup else 0 swap then config-mask-1
;
-004 config-switch set-wdte
-008 config-switch set-/pwrte
-040 config-switch set-boden
-080 config-switch set-lvp
-100 config-switch set-cpd
-200 config-switch set-wrt
-800 config-switch set-debug
+004 config-switch-1 set-wdte
+008 config-switch-1 set-/pwrte
+020 config-switch-1 set-mclre
+040 config-switch-1 set-boren
+080 config-switch-1 set-lvp
+100 config-switch-1 set-cpd
+200 config-switch-1 set-wrt
+800 config-switch-1 set-debug
-: set-cp 3030 config-mask ;
-3030 constant no-cp
+: set-cp 2000 config-mask-1 ;
0000 constant full-cp
+2000 constant no-cp
+
+: set-ccp1 1000 config-mask-1 ;
+0000 constant ccp1-rb3
+1000 constant ccp1-rb0
+
+: set-wrt 600 config-mask-1 ;
+200 constant page1-wrt
+400 constant page0-wrt
+600 constant no-wrt
+
+: config-switch-2
+ create ,
+does>
+ @ swap if dup else 0 swap then config-mask-2
+;
+
+1 config-switch-2 set-fcmen
+2 config-switch-2 set-ieso
\ ----------------------------------------------------------------------
\ Annotations
@@ -531,9 +560,6 @@
04 constant fsr
05 constant porta
06 constant portb
- 07 constant portc
- 08 constant portd
- 09 constant porte
0a constant pclath
0b constant intcon
0c constant pir1
@@ -551,30 +577,29 @@
18 constant rcsta
19 constant txreg
1a constant rcreg
- 1b constant ccpr2l
- 1c constant ccpr2h
- 1d constant ccp2con
1e constant adresh
1f constant adcon0
81 constant option_reg
85 constant trisa
86 constant trisb
- 87 constant trisc
- 88 constant trisd
- 89 constant trise
8c constant pie1
8d constant pie2
8e constant pcon
- 91 constant sspcon2
+ 8f constant osccon
+ 90 constant osctune
92 constant pr2
93 constant sspadd
94 constant sspstat
98 constant txsta
99 constant spbrg
+ 9b constant ansel
+ 9c constant cmcon
+ 9d constant cvrcon
9e constant adresl
9f constant adcon1
+ 105 constant wdtcon
10c constant eedata
10d constant eeadr
10e constant eedath
@@ -640,13 +665,13 @@
6 rcsta bit rx9
5 rcsta bit sren
4 rcsta bit cren
+ 3 rcsta bit adden
2 rcsta bit ferr
1 rcsta bit oerr
0 rcsta bit rx9d
( pir1 bits )
- 7 pir1 bit pspif
6 pir1 bit adif
5 pir1 bit rcif
4 pir1 bit txif
@@ -655,9 +680,14 @@
1 pir1 bit tmr2if
0 pir1 bit tmr1if
- ( pie1 bits )
+( pir2 bits )
+
+ 7 pir2 bit osfif
+ 6 pir2 bit cmif
+ 4 pir2 bit eeif
+
+( pie1 bits )
- 7 pie1 bit pspie
6 pie1 bit adie
5 pie1 bit rcie
4 pie1 bit txie
@@ -666,8 +696,15 @@
1 pie1 bit tmr2ie
0 pie1 bit tmr1ie
- ( t1con bits )
+( pie2 bits )
+ 7 pie2 bit osfie
+ 6 pie2 bit cmie
+ 4 pie2 bit eeie
+
+( t1con bits )
+
+ 6 t1con bit t1run
5 t1con bit t1ckps1
4 t1con bit t1ckps0
3 t1con bit t1oscen
@@ -675,7 +712,8 @@
1 t1con bit tmr1cs
0 t1con bit tmr1on
- ( t2con bits )
+( t2con bits )
+
6 t2con bit toutps3
5 t2con bit toutps2
4 t2con bit toutps1
@@ -684,7 +722,7 @@
1 t2con bit t2ckps1
0 t2con bit t2ckps0
- ( sspcon bits )
+( sspcon bits )
7 sspcon bit wcol
6 sspcon bit sspov
@@ -695,7 +733,7 @@
1 sspcon bit sspm1
0 sspcon bit sspm0
- ( sspstat bits )
+( sspstat bits )
7 sspstat bit smp
6 sspstat bit cke
@@ -706,7 +744,18 @@
1 sspstat bit ua
0 sspstat bit bf
- ( adcon0 bits )
+( ansel bits )
+
+ 6 ansel bit ans6
+ 5 ansel bit ans5
+ 4 ansel bit ans4
+ 3 ansel bit ans3
+ 2 ansel bit ans2
+ 1 ansel bit ans1
+ 0 ansel bit ans0
+
+( adcon0 bits )
+
7 adcon0 bit adcs1
6 adcon0 bit adcs0
5 adcon0 bit chs2
@@ -715,6 +764,46 @@
2 adcon0 bit go//done
0 adcon0 bit adon
+( adcon1 bits )
+
+ 7 adcon1 bit adfm
+ 6 adcon1 bit adcs2
+ 5 adcon1 bit vcfg1
+ 4 adcon1 bit vcfg0
+
+( ccp1con bits )
+
+ 5 ccp1con bit ccp1x
+ 4 ccp1con bit ccp1y
+ 3 ccp1con bit ccp1m3
+ 2 ccp1con bit ccp1m2
+ 1 ccp1con bit ccp1m1
+ 0 ccp1con bit ccp1m0
+
+( pcon bits )
+
+ 1 pcon bit /por
+ 0 pcon bit /bor
+
+( osccon bits )
+
+ 6 osccon bit ircf2
+ 5 osccon bit ircf1
+ 4 osccon bit ircf0
+ 3 osccon bit osts
+ 2 osccon bit iufs
+ 1 osccon bit scs1
+ 0 osccon bit scs0
+
+( osctune bits )
+
+ 5 osctune bit tun5
+ 4 osctune bit tun4
+ 3 osctune bit tun3
+ 2 osctune bit tun2
+ 1 osctune bit tun1
+ 0 osctune bit tun0
+
\ ----------------------------------------------------------------------
\ Data and variables
\ ----------------------------------------------------------------------
@@ -1696,9 +1785,9 @@
: pin-a ( n -- ) porta bit ;
: pin-b ( n -- ) portb bit ;
-: pin-c ( n -- ) portc bit ;
-: pin-d ( n -- ) portd bit ;
-: pin-e ( n -- ) porte bit ;
+\ : pin-c ( n -- ) portc bit ;
+\ : pin-d ( n -- ) portd bit ;
+\ : pin-e ( n -- ) porte bit ;
: rlf-tos indf ,f rlf ;
: rrf-tos indf ,f rrf ;
@@ -2022,7 +2111,7 @@
0 begin dup teehere < while dup eeline-dump 8 + repeat drop ;
: end-dump s" :00000001FF" type-fd cr-fd ;
: config-dump
- start-line 2 hex8. 400E hex16. 0 hex8. configword @ le-hex16. end-line ;
+ start-line 4 hex8. 400E hex16. 0 hex8. configword-1 @ le-hex16. configword-2 @ le-hex16. end-line ;
: dump hex code-dump config-dump eeprom-dump end-dump ;
: dump-file ( caddr a -- )
More information about the PicForth
mailing list