Using PS2 controler to get outputs on the pins of the board?

I’m trying to use a PS2 controller to turn the pins on on my botboard2. I’ve gotten the code to see the outputs in the terminal window but can’t figure out how to use those outputs to cange the condition of the board pins. Any help is appriciated! :laughing:

Could you send us a bit of your code please?

low 1 high 3

Ican see my controller when i hook it up and connect on the terminal 1. I’d like to be able to press the D-pad up and turn on P0.

here it is:

;-----PS2 Control-----

DAT con P12
CMD con P13
SEL con P14
CLK con P15

index var byte
temp var byte(19)
mode var byte

Forward var byte
Backward var byte
Left var byte
Right var byte

ShoulderL var byte
ShoulderR var byte
ShoulderU var byte
ShoulderD var byte

ElbowU var byte
ElbowD var byte
WristL var byte
WristR var byte

Clawopen var byte
Clawclose var byte

Cameraswitch var byte
lightswitch var byte
powerswitch var byte

;Initialize PS2 Controller
high CLK

low SEL ;makes P14 an output and sets it low (0v) 40
shiftout CMD,CLK,FASTLSBPRE, $1\8,$43\8,$0\8,$1\8,$0\8] ;CONFIG-MODE-ENTER ?configuring the PS2 controller?
high SEL ;makes P14 an output and sets it high (5v)
pause 1

low SEL ;makes P14 an output and sets it low (0v)
shiftout CMD,CLK,FASTLSBPRE, $01\8,$44\8,$00\8,$01\8,$03\8,$00\8,$00\8,$00\8,$00\8] ;SET-MODE-AND-LOCK
high SEL ;makes P14 an output and sets it high (5v)
pause 100

low SEL ;makes P14 an output and sets it low (0v) ;50
shiftout CMD,CLK,FASTLSBPRE, $01\8,$4F\8,$00\8,$FF\8,$FF\8,$03\8,$00\8,$00\8,$00\8] ;SET-DS2-NATIVE-MODE
high SEL ;makes P14 an output and sets it high (5v)
pause 1

low SEL ;makes P14 an output and sets it low (0v)
shiftout CMD,CLK,FASTLSBPRE, $01\8,$43\8,$00\8,$00\8,$5A\8,$5A\8,$5A\8,$5A\8,$5A\8] ;CONFIG-MODE-EXIT-DS2-NATIVE
high SEL ;makes P14 an output and sets it high (5v)
pause 1

low SEL ;makes P14 an output and sets it low (0v) 60
shiftout CMD,CLK,FASTLSBPRE, $01\8,$43\8,$00\8,$00\8,$00\8,$00\8,$00\8,$00\8,$00\8] ;CONFIG-MODE-EXIT
high SEL ;makes P14 an output and sets it high (5v)
pause 10

Main
;-----PS2 Mode-----
low SEL
shiftout CMD,CLK,FASTLSBPRE, $1\8] ;Reading controller mode
shiftin DAT,CLK,FASTLSBPOST, [mode\8]
high SEL ;70

pause 1

;-----PS2 Data-----
low SEL
shiftout CMD,CLK,FASTLSBPRE,$1\8,$42\8] ; reading data from controller
shiftin DAT,CLK,FASTLSBPOST,[temp(0)\8,temp(1)\8,temp(2)\8,temp(3)\8,temp(4)\8,temp(5)\8,temp(6)\8,temp(7)\8,temp(\8, |
temp(9)\8,temp(10)\8,temp(11)\8,temp(12)\8,temp(13)\8,temp(14)\8,temp(15)\8,temp(16)\8,temp(17)\8,temp(1\8]
high SEL

pause 1

;-----Basic Micro IDE terminal------
serout S_OUT,i57600,[13, hex2 mode\2] ; Basic Micro IDE <= 02.2.1.1
for index = 1 to 18 ; temp(0) contains a dummy variable so we don’t send it to the PC
; sending all the data to the PC
serout S_OUT,i57600," ", dec3 temp(index)\3] ; Basic Micro IDE <= 02.2.1.1
next

goto main

You would want to replace this portion of the code with code specific to what you are trying to do. My first hint would to replace the variable name temp with something more meaningfull. For example something like: DualShock or maybe PS2Data.

I am not sure of which is the D-pad up. But for example you wish to use the R1 button. Then you might have code in there like:

[code] if (DualShock(2).bit3 = 0) then ;R1 Button test
high p0
elseif (DualShock(2).bit2 = 0) ;L1 Button test

            goto main

[/code]
Note, one you get something like this to work, you may not want it to keep repeating this after each iteration of reading the Ps2 port. You could either save away the previous state and only do this if the state changes. you could also use a timer and only do repeats every so oftern. But this may be beyond your question.

I hope this helps
Kurt

Thanks I’ll try this when i get home tonight. So what i’m going to try is make it read the bit output in the index right? :confused: Also do i just erase all of the code or do i keep the seout portion and try to aim it at the p0?