Here is code that works with a PAK-VII and PIC Basic Pro. The program just reads the TICK register and displays the second count on the serial port at 19200 baud.

For this example, I wrote "home made" shiftin and shiftout routines:

shiftoutput: ' sends iobyte
output datapin
for i=0 to 7
' Set data pin to 0 or 1
low datapin
if (iobyte & $80) <> $80 then goto so0
high datapin
so0:
iobyte=iobyte<<1 ' shift byte left
pulsout clk,100
next
return

shiftinput:
input datapin
iobyte=0
for i=0 to 7
iobyte=iobyte<<1 ' shift left
iobyte=iobyte | datap
pulsout clk,100
next
return

The rest of the code conversion was straightforward: adding the right defines, changing the nibble variables to bytes, and waiting for things to happen were all that was required.

' These are some starter routines
' that will help you use the PAK-7
' Coprocessor from AWC

Include "modedefs.bas"
define LOADER_USED 1 ' comment this out if not using a boot loader
Define OSC 20
DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 20h
DEFINE HSER_BAUD 19200

' Change these to suit your setup
datap var portc.2 ' Data pin (I/O)
datapin var portc.2
clk var portc.3 ' Clk pin (output)

' Register names
DURLOW con %000
DURHIGH con %001
RAWLOW con %010
RAWHIGH con %011
RISE con %100
FALL con %101
TICK200 con %110
TICK con %110
INP con %110
VER con %110
SUM con %111

i var byte
iobyte var byte

output clk
output datap

fpx var word ' Integer used by some routines
fpb var byte ' byte
' parameters for FCommand
chan var byte
register var byte
clearreg var bit
clearchan var bit

pause 5 ' wait for wake up

gosub freset ' always reset!

' TEST CODE -- REPLACE WITH YOUR OWN
t:
gosub FTotalReset ' hard reset

Fpx=0
gosub FPullup

seconds var word
last var word

' read time
tloop:
clearreg=0
clearchan=0
register=TICK
chan=1
gosub FCommand


seconds = fpx
if last=seconds then tloop
hserout [dec seconds,13,10]
last=seconds
goto tloop

' Reset the Pak7 I/O
FReset:
LOW DATAP
LOW CLK
pauseus 50
HIGH CLK
pauseus 50
HIGH DATAP
pauseus 50
LOW CLK 
pauseus 50
return

FCommand:
' inputs chan = channel, register = register, clearreg and clearchan
fpb=(clearchan<<7) + (clearreg<<6) + (register<<3) + chan
gosub FSendByte
FReadWord:
pauseus 8 ' wait a bit for the result to be ready
gosub shiftinput
fpx.lowbyte=iobyte
gosub shiftinput
fpx.highbyte=iobyte
return

FTotalReset:
fpb=$FF
FSendByte:
iobyte=fpb
gosub shiftoutput
return

FReadByte:
pauseus 8
gosub shiftinput
fpb=iobyte
return

FPrescale:
' set fpb to the prescale constant
fpb = fpb + $C0
goto FSendByte

FPullUp:
' set fpx to the pull up mask
fpb=%11010000
Fscmd:
gosub FSendByte
fpb=fpx
goto FSendByte

FThresh:
' set fpx to the threshold mask
fpb=%11010001
goto Fscmd

FSchmitt:
' set fpx to the Schmitt trigger mask
fpb=%11010010
goto Fscmd



pakclock con 3 ' 6us @ 20MHz (adjust for your clock)
pakclocklow con 3 ' 3uS low 6uS + 3uS + 1uS hold = 10uS = 100kbps

shiftoutput: ' sends iobyte
output datapin
for i=0 to 7
' Set data pin to 0 or 1
low datapin
if (iobyte & $80) <> $80 then goto so0
high datapin
so0:
iobyte=iobyte<<1 ' shift byte left
pauseus pakclocklow
pulsout clk,pakclock
pauseus 1 
next
pauseus 50 ' give it some time to process
return

shiftinput:
input datapin
iobyte=0
for i=0 to 7
iobyte=iobyte<<1 ' shift left
iobyte=iobyte | datap
pauseus pakclocklow
pulsout clk,pakclock
pauseus 1 ' hold data a tick
next
return

Site contents © 1997-2018 by AWC, Houston TX    (281) 334-4341