Shop OBEX P1 Docs P2 Docs Learn Events
For anybody that is interested, heres some code for a PS/2 mouse host — Parallax Forums

For anybody that is interested, heres some code for a PS/2 mouse host

BobbyJBobbyJ Posts: 22
edited 2004-12-30 00:56 in General Discussion
A few people have asked it, so here it is...

This was writen to support a 3-button, 2-axis PS/2 mouse with scroll wheel. It is based on information found on Adam Chapweske's web site at:

http://panda.cs.ndsu.nodak.edu/%7Eachapwes/PICmicro/mouse/mouse.html
http://panda.cs.ndsu.nodak.edu/%7Eachapwes/PICmicro/PS2/ps2.htm

The web site is an excellent resouce for dealing with the PS/2 protocol and it is HIGHLY recomended you visit it.

This code works, but I still consider it to be incomplete since not all features of the PS/2 protocol have been added and/or fully tested. The parity check for data received from the mouse is not finished. Some of the code that [noparse][[/noparse]I think] is needed to implement this feature is in the subroutine "ReceiveByte". There are 3 lines of code in that subroutine that are commented out, they are what I started for the parity check. There is also no code to check for error commands received from the mouse, and there is no code to send error commands to the mouse. But, even without these features, everything seems to work as it should.

THIS HAS ONLY BEEN TESTED WITH A 3-BUTTON/SCROLL WHEEL MICROSOFT INTELLIMOUSE!!
But in theory, it should support a standard 2-button mouse with no scroll wheel as is. I have been able to setup up the mouse I tested this code with to operate as a 2-button mouse with no scroll wheel by commenting out the scroll wheel check in the subroutine "Initialize Mouse".

It should also be noted that I am about as far from being an expert at programing SX chips as anybody can be. Since this was my very first attempt at writing any code from scratch I am fairly certain that this code can be optimised further. It is free to use by anybody for any reason. Use it as is, or change it, modify it, do whatever you want with it, or do nothing with it.



If you have any questions or comments, lemme no.

Comments

  • JamesCJamesC Posts: 26
    edited 2004-12-29 15:21
    Very nice. I have to say I was a little suprised, it's a lot less code than I would have expected.

    I noticed that it looks like you are using 2 pins for the interface. The schematic shown at the web site listed uses 4 lines. What kind of electrical interface did you use? Straight thru with pull-up resistors?
  • BobbyJBobbyJ Posts: 22
    edited 2004-12-29 15:28
    my bad...theres a slight error in that code, but it's easily fixed.


    In the subroutine "InitializeMouse" there are 7 lines that look like this:

    MOV TxByte, #$F3 ;send set sample rate change
    CALL SendByte
    CALL ReceiveByte ;acknowledge byte from mouse...ignor it
    ; MOV TxByte, #$28 ;set sample rate 40 slow
    ; MOV TxByte, #$50 ;set sample rate 80 not as slow
    ; MOV TxByte, #$64 ;set sample rate 100 default
    ; MOV TxByte, #$C8 ;set sample rate 200 full throttle

    As it is, the mouse will expect to receive a 'sample rate value' after the 'set sample rate change' command has been sent. With all four of the sample rate vaule lines commented out, it will probably mess things up. The 4 vaules where there durring testing.

    The fix...uncomment any 1 of the 4 commented lines.


    whoops, sorry
  • BobbyJBobbyJ Posts: 22
    edited 2004-12-29 15:37
    hehe, I guess it would be nice to know how to wire it up....it's really early and I still have crusty stuff filling the corners of my eyes.

    here's how I have it wired up. I'ld like to take cedit for the picture, but I can't. I got it off of some web site, but can not for the life of me remember where.
    1300 x 500 - 42K
  • JamesCJamesC Posts: 26
    edited 2004-12-29 15:51
    Thats what I suspected. Thanks again.
  • Paul BakerPaul Baker Posts: 6,351
    edited 2004-12-30 00:56
    glad to see you figured it out
Sign In or Register to comment.