Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

I need help to update ps2 controller

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive
View previous topic :: View next topic  
Author Message
mtm4elnagem

Bascom Member



Joined: 10 Sep 2014
Posts: 1

PostPosted: Wed Sep 10, 2014 10:45 am    Post subject: I need help to update ps2 controller Reply with quote

hi
i find code ps2 controller i wont to update code
to work at char LCD 2X16 and atmega32 crystal 8mhz
code must be when i press any key ps2 controller show name of key on lcd
http://www.mcselec.com/index2.php?option=com_forum&Itemid=59&page=viewtopic&t=8531&highlight=ps2

Code:

'===============================================================================
' 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

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

'-------------------------------------------------------------------------------
 Print "{027}[2J" ;                                         ' ansi clear screen...
 print "Starting..."
Cls
Do
   Gosub Ps2_read                                           ' read the PS controller data

   print "{027}[3;1H";                                        ' move to page top (ansi)
   print "Byte1 : " ; Ps2_data(1) ; "  "
   ''print ""
   print "Select: " ; Ps2_data(2).0 ; "     Start : " ; Ps2_data(2).3
   print "ThumbL: " ; Ps2_data(2).1 ; "     ThumbR: " ; Ps2_data(2).2
   ''print ""
   print "CNT-Up: " ; Ps2_data(2).4 ; "     CNT-R : " ; Ps2_data(2).5
   print "CNT-Dn: " ; Ps2_data(2).6 ; "     CNT-L : " ; Ps2_data(2).7
   'print ""
   print "L1    : " ; Ps2_data(3).2 ; "     R1    : " ; Ps2_data(3).3
   print "L2    : " ; Ps2_data(3).0 ; "     R2    : " ; Ps2_data(3).1
   ''print ""
   print "Triang: " ; Ps2_data(3).4 ; "     Cross : " ; Ps2_data(3).6
   print "Circle: " ; Ps2_data(3).5 ; "     Square: " ; Ps2_data(3).7
   ''print ""
   print "Joy RX: " ; Ps2_data(4) ; "  "
   print "Joy RY: " ; Ps2_data(5) ; "  "
   print "Joy LX: " ; Ps2_data(6) ; "  "
   print "Joy LY: " ; Ps2_data(7) ; "  "

   'waitms 100
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
'-------------------------------------------------------------------------------


 


(BASCOM-AVR version : 2.0.7.5 , Latest : 2.0.7.7 )
Back to top
View user's profile
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum