PDA

View Full Version : need help simulating PS/2 mouse



peterdeco1
- 9th December 2007, 10:37
Hello Everybody. I'm trying to use a PIC to simulate a PS/2 mouse with no success at all. I've tried everything such as SHIFTOUT, PULSOUT and nothing. I found code that allows a BS2 to work. I substituted PBP commands for the BS2 commands and still nothing. Now, I rewrote the code using simple HIGH and LOW commands. As far as I can tell, I've followed the PS/2 mouse protocol exactly and still nothing. When I plug the connector into the PS/2 port, I am expecting the pointer to travel up/left. It doesn't budge. Can someone tell me what I'm missing here? I compared my circuit to a mouse on my scope. They look pretty much the same but the mouse works and the circuit doesn't. The only thing electrically different is the mouse uses optoisolators to bring the CLOCK and DATA lines low. I am simulating this by releasing the LOW command by turning these ports into inputs and let the pullup resistors bring the ports high after clocking in the data. Like I said, it looks good on the scope! Thank you.

'using 12F629
CMCON = 7 'comparators off
trisio = %11111111 'ALL INPUTS. HIGH & LOW COMMANDS WILL CONFIGURE TO OUTPUTS
DEFINE OSCCAL_1K 1 ' Set OSCCAL for 1K device
@ DEVICE MCLR_OFF, INTRC_OSC_NOCLKOUT, WDT_ON, BOD_ON, PWRT_ON, PROTECT_ON



START:
IF GPIO.1 = 0 Then START 'IF PC IS INHIBITING COMMUNICATION ON CLOCK LINE WAIT HERE

'FEED ALL BITS LSB (D0) FIRST AFTER START BIT

Low GPIO.0 'START BIT ALWAYS LOW
GoSub CLOCKPULSE 'CLOCK IN THE BIT

Low GPIO.0 'LEFT MOUSE BUTTON NOT PUSHED
GoSub CLOCKPULSE

Low GPIO.0 'RIGHT MOUSE BUTTON NOT PUSHED
GoSub CLOCKPULSE

Low GPIO.0 'ALWAYS A 0 ON A 2 BUTTON MOUSE
GoSub CLOCKPULSE

High GPIO.0 'ALWAYS A 1
GoSub CLOCKPULSE

High GPIO.0 'DIRECTION OF X MOVEMENT 1 = (+) = LEFT
GoSub CLOCKPULSE

High GPIO.0 'DIRECTION OF Y MOVEMENT 1 = (+) = UP
GoSub CLOCKPULSE

Low GPIO.0 'NO OVERFLOW ON X MOVEMENT
GoSub CLOCKPULSE

Low GPIO.0 'NO OVERFLOW ON Y MOVEMENT
GoSub CLOCKPULSE

Low GPIO.0 'PARITY BIT FOR ODD PARITY
GoSub CLOCKPULSE 'KEEP LOW AS DATA + PARITY IS AN ODD NUMBER

High GPIO.0 'STOP BIT ALWAYS A 1
GoSub CLOCKPULSE
Pause 1 'SEPARATE THE PACKETS BY 1MS

'PACKET 2 ADDS UP TO 127 FOR FULL LEFT

Low GPIO.0 'START BIT
GoSub CLOCKPULSE

High GPIO.0
GoSub CLOCKPULSE
High GPIO.0
GoSub CLOCKPULSE
High GPIO.0
GoSub CLOCKPULSE
High GPIO.0
GoSub CLOCKPULSE
High GPIO.0
GoSub CLOCKPULSE
High GPIO.0
GoSub CLOCKPULSE
High GPIO.0
GoSub CLOCKPULSE
Low GPIO.0
GoSub CLOCKPULSE

Low GPIO.0
GoSub CLOCKPULSE 'PARITY BIT

High GPIO.0
GoSub CLOCKPULSE 'STOP BIT
Pause 1

'PACKET 3 ADDS UP TO 127 FOR FULL UP

Low GPIO.0
GoSub CLOCKPULSE 'START BIT

High GPIO.0
GoSub CLOCKPULSE
High GPIO.0
GoSub CLOCKPULSE
High GPIO.0
GoSub CLOCKPULSE
High GPIO.0
GoSub CLOCKPULSE
High GPIO.0
GoSub CLOCKPULSE
High GPIO.0
GoSub CLOCKPULSE
High GPIO.0
GoSub CLOCKPULSE
Low GPIO.0
GoSub CLOCKPULSE

Low GPIO.0
GoSub CLOCKPULSE 'PARITY BIT
High GPIO.0
GoSub CLOCKPULSE 'STOP BIT
Pause 1
GoTo START

CLOCKPULSE:
Low GPIO.1 'BRING CLOCK LOW
PauseUs 50 'HOLD LOW FOR 50US TO ALLOW DATA BIT TRANSFER IN ON DATA LINE (GPIO.0)
Input GPIO.1 'RELEASE CLOCK. MAKE HIGH Z INPUT TO SIMULATE OPTOISOLATOR
PauseUs 50 'PULLUPS ON CLOCK LINE BRING IT HIGH
Input GPIO.0 'RELEASE DATA LINE MAKE HIGH Z INPUT TO SIMULATE OPTOISOLATOR
Return

bearpawz
- 9th December 2007, 21:22
Ok, I didnt really look at your code, but I am an A+ certified computer tech and one thing alot of people dont realize is that the computer locks on to a PS2 mouse when its first booted to BIOS. In a nutshell, if you accidentaly unplug your ps2 mouse and then plug it back in there is a very good chance (though granted not all the time) that you will actually have to turn the PC off and back on again. Not even a reboot will fix it. So if your just booting into what ever os you use, then unplug your mouse and plug in your project its probably not going to work. At least thats how things work in the IBM/PC world, mac might be different. So in a nut shell try shutting down, plug in your project and fire it back up. Of course then there is the chance you might get hounded with a mouse not detected error. Ive never really gotten that deep in to them. And again like I said some times its not even an issue as it depends alot on the mb, the mouse, and sometimes even the OS. Just a thought.

Darrel Taylor
- 9th December 2007, 21:49
And along with bearpawz point.

When it does power up, the mouse needs to do several things before it can start sending the 3-byte packets. Check this link, starting at Reset Mode, and also look at the Initialization section.

http://www.computer-engineering.org/ps2mouse/

Also, both the CLK and DATA lines are open-collector, so you shouldn't have any HIGH statements. Only LOW and INPUT.
<br>