PS2 interfacing with PIC16F877A

Discussion about projects that used PIC Microcontroller, Hardware Interface, Programming Algorithm and etc......

PS2 interfacing with PIC16F877A

Postby kokjoo89 » Wed Nov 18, 2009 9:33 pm

I creating an interfacing unit by using my PIC. It function properly when using wired PS2 controller, but not the wireless controller. Can anyone give me a answer? I already try for month. The controller cant detected by the receiver.
Here is my program:

CODE: SELECT_ALL_CODE
'******************************************************************
'Title:
'======
'Get PS2 controller code
'
'Description:
'============
'This is the program that use to interface PS2 controller.
'It is interface the contorller to the PIC microcontorller.
'This program is using "shiftin/shiftout" to interface the
'serial data from the PS2 controller into the "byte".
'The "byte" will used later to contorller the robot.
'In this program, it can detect digital and analog input
'from the PS2 controller (analog only work on Sony origin
'contorller).
'For debug purpose, the portB are set to be output to indicate
'the byte of the "psxThumbR". The LED will OFF when the
'corresponding button is pressed. (Use only psxThumbR button)
'
'
'Author:    
'Date:   21 Sept 2009
'Compiler:    PicBasic Pro
'File:      ####
'
'Modifications:
'==============
'
'
'******************************************************************
'Definations
INCLUDE "MODEDEFS.BAS"
ADCON1=7   'Analog to Digital Converter Off
TRISA.0=1
TRISA.1=0
TRISA.2=0
TRISA.3=0
TRISB=0
PsxClk   var porta.3
PsxAtt    var porta.2   
PsxCmd    var porta.1   
PsxDat    var porta.0   
psxThumbL    VAR Byte    'left thumb buttons
psxThumbR    VAR Byte    'right thumb buttons
psxStatus    VAR Byte    'status ($5A)
psxJoyRX    VAR Byte    'R joystick - X axis
psxJoyRY    VAR Byte    'R joystick - Y axis
psxJoyLX    VAR Byte    'L joystick - X axis
psxJoyLY    VAR Byte    'L joystick - Y axis

'Setup
PsxAtt=1
PsxClk=1


'Start of Main Program
Main:
gosub PSX
portb = psxThumbR
pause 15
Goto Main

PSX:
PsxAtt = 0
SHIFTOUT PsxCmd, PsxClk, LSBFIRST, [$01\8, $42\8]
SHIFTIN PsxDat, PsxClk, 5, [psxStatus\8, psxThumbL\8, psxThumbR\8, psxJoyRX\8, psxJoyRY\8, psxJoyLX\8, psxJoyLY\8]
PsxAtt = 1
return

End
kokjoo89
Fledgling
 
Posts: 1
Joined: Wed Nov 18, 2009 9:05 pm

Re: PS2 interfacing with PIC16F877A

Postby sich » Thu Nov 19, 2009 3:50 pm

I'm not familiar with basic code. Do u mind explain these lines?

SHIFTOUT PsxCmd, PsxClk, LSBFIRST, [$01\8, $42\8]
SHIFTIN PsxDat, PsxClk, 5, [psxStatus\8, psxThumbL\8, psxThumbR\8, psxJoyRX\8, psxJoyRY\8, psxJoyLX\8, psxJoyLY\8]

PS2 controller uses SPI for its communication protocol. Would it be the clock accuracy that causes your program cannot work on wireless PS2 controller? Anyway, just guessing... :roll:
~> How to ask QUESTIONS the SMART way in FORUM? <~
User avatar
sich
Moderator
 
Posts: 603
Joined: Tue Apr 21, 2009 2:15 pm

Re: PS2 interfacing with PIC16F877A

Postby robosang » Fri Nov 20, 2009 4:42 pm

I did tried hacking the PS2 before using source code from basic stamp. It works good for wired PS2, but when I connect wireless PS2, it cannot communicate. I think is because of hardware or protocol speed, or some other problem. Anyway because of time, I give up and finally I get myself the SKPS from Cytron, works well for both wired and wireless PS2, they even have the socket for the PS2 joystick, save my time to hack the wire one by one! I have been using this product for many wireless control, very good!

So, I cannot help much in this case.
robosang
Expert
 
Posts: 1239
Joined: Wed Jun 10, 2009 5:37 pm

Re: PS2 interfacing with PIC16F877A

Postby aurora » Fri Nov 20, 2009 5:40 pm

The problem with PS2 wireless controller is not uncommon. Have you try changing the timing for SHIFTIN? How about adding delay between these lines?

PsxAtt=1
PsxClk=1
aurora
Discoverer
 
Posts: 126
Joined: Sun Jun 07, 2009 4:52 pm


Return to PIC Microcontroller

Who is online

Users browsing this forum: No registered users and 22 guests