I need help to update ps2 controller bascom avr
need help about bascom avr code for test ps2 controller working
i need to led at porta.0 on when i press any button from ps2 controller
this code must be do this
but not working ???
'=============================================================================== ' Project: PlayStationII Wireless (or wired) controller reader ' Version: v1.0 ' Created: 2010-03-27 ' By: Glen Aidukas (C)Bahbots.com ' Credits: Original help from Eddy Wright on the PS2 protocol ' ' Description: ' ' PS2 Shockwave controller wiring and PSI data reading ' _____________________________ ' | | ' | |1 2 3||4 5 6||7 8 9| | <-- Male connector of controller ' \___________________________/ ' ' Pin Color Function Notes ' 1 GREEN MISO Data In ' 2 WHITE MOSI Command out ' 3 VIBRATE +9V ' 4 BLACK GND ' 5 RED VCC 3.3V-5V ' 6 BLUE SS Select ' 7 YELLOW SCK Clock ' 8 N/C N/C ' 9 ACK N/C ' ' This code was tested and working with a wireless PlayStationII controller '=============================================================================== $regfile = "m32Def.dat" $crystal = 8000000 $hwstack = 32 $swstack = 16 $framesize = 48 $baud = 38400 '=====[ Dimension and initialize variables ]==================================== Dim Ps2_cmd(2) As Byte ' init cmd sent to PS2 controller Dim Ps2_data(7) As Byte ' hold returned data from PS2 controller Dim I As Byte ' General purpose variables '------------------------ Ddra = &B11111111 'port a outpur Porta = &B00000000 '------------------------ 'porta = 0 Ps2_miso Alias Pinb.0 : Ddrb.0 = 0 ' data in Ps2_mosi Alias Portb.1 : Ddrb.1 = 1 ' data out Ps2_ss Alias Portb.2 : Ddrb.2 = 1 ' Select Ps2_sck Alias Portb.3 : Ddrb.3 = 1 ' Clock Ps2_miso = 1 ' turn on internal pull up resister Ps2_cmd(1) = &H01 ' Start Command Ps2_cmd(2) = &H42 ' Request Data '------------------------------------------------------------------------------- Do Gosub Ps2_read ' read the PS controller data If Ps2_data(2).0 = 222 Or Ps2_data(2).0 = 222 Then Porta.0 = 1 Waitms 250 End If Loop '------------------------------------------------------------------------------- '=====[ Read the PS2 controller data ]========================================== Ps2_read: Ps2_ss = 0 ' assert select line Shiftout Ps2_mosi , Ps2_sck , Ps2_cmd(1) , 2 , 8 , 20 ' send start command Shiftout Ps2_mosi , Ps2_sck , Ps2_cmd(2) , 2 , 8 , 20 ' send request data cmd For I = 1 To 7 Shiftin Ps2_miso , Ps2_sck , Ps2_data(i) , 2 , 8 , 20 ' read in data Next I Ps2_ss = 1 ' release select line Return '-----------
i need to led at porta.0 on when i press any button from ps2 controller
this code must be do this
but not working ???
Do Gosub Ps2_read ' read the PS controller data If Ps2_data(2).0 = 222 Or Ps2_data(2).0 = 222 Then Porta.0 = 1 Waitms 250 End If Loop
Comments
http://www.mcselec.com/index2.php?option=com_forum&Itemid=59
This forum supports other microcontrollers and programming languages.