Shop OBEX P1 Docs P2 Docs Learn Events
PS2 interface code I''m using — Parallax Forums

PS2 interface code I''m using

ArchiverArchiver Posts: 46,084
edited 2003-07-03 19:57 in General Discussion
'*********************************************************************
*******************
'* Title: Playstation interface
'*
'* Filename: Program 1
'* Date: 28 Mar 02
'*
'*********************************************************************
*******************
' I/O Assignment and TRIS:

clk con 7
att con 9
dat con 5
cmd con 6

'*********************************************************************
*******************
' Variables:

index var byte
char var byte

'*********************************************************************
*******************
'this code simply reads in the commands from the playstation
controller joysticks and buttons
'and displays them via debug.
main:

low att ' select the PSX controller

shiftout cmd,clk, LSBFIRST,[noparse][[/noparse]$01,$42] ' send "get ready"
and "send data"
shiftin dat, clk, 3, [noparse][[/noparse]char]' read then discard this byte, it
'starts up the controller

'shiftin dat, clk, 3, [noparse][[/noparse]char]
'shiftin dat, clk, 3, [noparse][[/noparse]char]

shiftin dat, clk, 3, [noparse][[/noparse]char] ' 1st "digital" byte - left
switches
debug cr,"Buttons:
",cr
debug bin char, " " ' debug window binary format

shiftin dat, clk, 3, [noparse][[/noparse]char] ' 2nd "digital" byte - right
switches
debug bin char, " " ' debug window binary format


'the above block shifted in the on/off (111011011) status of all the
switches
debug cr, "Right joy:
L/R "
shiftin dat, clk, 3, [noparse][[/noparse]char] ' right joystick left / right
debug dec char, " " ' debug window decimal format

debug cr, "Right joy:
U/D "
shiftin dat, clk, 3, [noparse][[/noparse]char] ' right joystick up / down
debug dec char, " " ' debug window decimal format

debug cr, "Left joy:
L/R "
shiftin dat, clk, 3, [noparse][[/noparse]char] ' left joystick left / right
debug dec char, " " ' debug window decimal format

debug cr, "Left joy:
U/D "
shiftin dat, clk, 3, [noparse][[/noparse]char] ' left joystick up / down

debug dec char, CR ' debug window dec format and return
pause 1000
'the block above gets decimal values representing analog X/Y joystick
positions

high att
'stops transmissions

goto main
Sign In or Register to comment.