Yamel Cuevas was good enough to share his 8051/8052/89C52 code for talking to the PAK-II (or any of the SHIFTIN/SHIFTOUT PAKs). The pak_reset routine does the initial reset required. You can use pak_send to send commands, pak_wait to wait for a response, and pak_get to read the results. Input and output are to the accumulator.

Thanks Yamel!



;Yamel Cuevas
;4/6/2001

;;Routines to interface 89c52 with PAK II math co processor.
;pak_reset pak_delay pak_send pak_get pak_wait


Sout equ P1.7 ;in/out pin on the PAK II
clk equ P1.6 ;clock pin for the PAK II
busy equ P1.5
pak_byte equ 20h ;used as temp store for transfers
p_bit0 equ 0
p_bit1 equ 1
p_bit2 equ 2
p_bit3 equ 3
p_bit4 equ 4
p_bit5 equ 5
p_bit6 equ 6
p_bit7 equ 7
Sin equ P1.4


pak_reset:
;This function resets the PAK by bringing the data line from low to high
;while the clock is high
clr Sin
lcall pak_delay
clr clk
setb clk
nop
setb Sin
nop
clr clk
lcall pak_delay
setb Sout ;set Sout as input pin
ret



pak_delay:
;appropriate half delay for clk period
mov r0, #20d ;need at least 20 machine cycles between clock pulses
delay_loop:
djnz r0, delay_loop
ret


pak_send:
;send byte from accumulator to PAK II
mov pak_byte, a
mov C, p_bit7
mov Sin, C
lcall pak_delay
setb clk
nop
nop
clr clk
lcall pak_delay

mov C, p_bit6
mov sin, c
lcall pak_delay
setb clk
nop
nop
clr clk
lcall pak_delay

mov C, p_bit5
mov Sin, C
lcall pak_delay
setb clk
nop
nop
clr clk
lcall pak_delay

mov C, p_bit4
mov sin, c
lcall pak_delay
setb clk
nop
nop
clr clk
lcall pak_delay

mov c, p_bit3
mov sin, c
lcall pak_delay
setb clk
nop
nop
clr clk
lcall pak_delay

mov C, p_bit2
mov Sin, C
lcall pak_delay
setb clk
nop
nop
clr clk
lcall pak_delay

mov C, p_bit1
mov sin, c
lcall pak_delay
setb clk
nop
nop
clr clk
lcall pak_delay

mov c, p_bit0
mov sin, c
lcall pak_delay
setb clk
nop
nop
clr clk
lcall pak_delay



ret

pak_wait:
;wait until PAK is no longer busy

jb busy, pak_wait
ret

pak_get:
;this routine gets a byte from the PAKII as input
setb Sin
lcall pak_delay
lcall pak_delay

mov c, Sout
mov p_bit7, c
setb clk
nop
nop
clr clk
lcall pak_delay

mov c, Sout
mov p_bit6, c
setb clk
nop
nop
clr clk
lcall pak_delay


mov c, Sout
mov p_bit5, c
setb clk
nop
nop
clr clk
lcall pak_delay


mov c, Sout
mov p_bit4, c
setb clk
nop
nop
clr clk
lcall pak_delay

mov c, Sout
mov p_bit3, c
setb clk
nop
nop
clr clk
lcall pak_delay


mov c, Sout
mov p_bit2, c
setb clk
nop
nop
clr clk
lcall pak_delay

mov c, Sout
mov p_bit1, c
setb clk
nop
nop
clr clk
lcall pak_delay


mov c, Sout
mov p_bit0, c
setb clk
nop
nop
clr clk
lcall pak_delay

mov a, pak_byte

ret

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