ECE 477 Spring 2005 Lab #8

Due 4/29/05

 

 

 

This week's lab is to write a program in C for the PIC, compile it to a hex file, program it with your programmer, and do something that seems pretty cool.  The goal is to fool the PC into thinking that your PIC circuit is in fact a standard two-button PC mouse (that the user endlessly moves in a square pattern).  .

 

About the mouse:

A standard two-button serial mouse communicates with a PC at 1200 baud, no parity, 7 data bits, 1 stop bit (more are fine).  It connects to the PC RS-232 receive line (i.e., it transmits on the line, the PC receives on the line), ground, and the DTR (data terminal ready) line of the PC RS-232.  Many (most) mice also draw parasitic power from other PC outputs.  The DTR line is special since it is used to initiate PC-mouse communication.  When the PC is looking for mice it brings the DTR line from its normal state of -12V up to +12V.  When this happens the mouse (standard two button mouse) sends the ASCII character 'M' to the PC.  The mouse should not send to the PC if the DTR line is not at 12V and if the DTR line ever goes from -12V to 12V the mouse should send an 'M'.  It is perhaps a bit unfortunate that the Linux machines do not require the DTR-M handshake (i.e., if you just start sending mouse packets it will work), nevertheless, for maximal compatibility I expect you to implement the handshake.

 

Once the mouse and the PC are happy with each other, the mouse sends data in three-byte packets.  These are of the form

1LRYYXX  0XXXXXX 0YYYYYY

 

where 0's and 1's are as you expect, L and R are the state of the left and right buttons and the X's and Y's represent two signed eight-bit values representing X travel and Y travel.  I'm not sure how many mouse updates are allowed per second, but it is certainly less than the number that you *could* send.  Generally a few per second is a good target.  Generally if there is no movement or button activity a mouse transmits nothing.

 

About the PIC

 

To be like a mouse we must interface to the DTR line of the PC (pin 4 on a 9 pin connector) and respond when the PC is looking for us.  It is important to not be too anxious to start blasting the PC with packets.  From trial and error (and some frustration) I'd recommend not transmitting anything after the 'M' for about 5 seconds and not to transmit more than a few mouse packets per second. 

 

About the circuit

 

A diagram is shown below.  The circuit uses the "cheat" described in class where the RS-232 transmit line from the PC is used to generate our negative RS-232 voltage.  The positive RS-232 voltage is generated by turning on a PNP transistor. 

 

 

PART A:  For part A I want you to build the hardware necessary to interface a PIC as a serial mouse.  The PIC should wait until the PC brings the DTR line to +12V (making the PIC input LOW) and respond with an 'M'.  About 5 seconds or so after transmitting the 'M' send a movement of 10 in the X direction 0 in the Y direction, then 0 in the X 10 in the Y, then negative 10 in the X 0 in the Y, finally 0 in the X negative 10 in the Y.  Repeat these continuously and the mouse cursor on the host PC should move in a small square pattern. 

 

 

PART B:  This lab has the coolest possibilities of any lab so far.  One obvious possibility is to make a fully functioning mouse, say with push buttons for directions (as well as the regular mouse buttons).  Still another would be to make a PIC mouse using the guts from an old mouse.  Maybe you could use your device as a second mouse on a system with a single button that spit out a sequence of movements and/or clicks to do something (I'm not sure what).  Maybe you could measure some physical/electrical thing and use the mouse to point to status (kind of like an analog meter, where the mouse points to the reading).  What would NOT be a good part B would be to endlessly make the mouse pointer move in a triangular pattern over and over again, or make it move in a bigger square, or make it move faster or slower.  Part B should be different from Part A and comparable in magnitude (given that you've done Part A).  Creativity is genuinely appreciated, as is coolness.