Joystick port

by

L. Padilla

Introduction

This document will will briefly describe the basics of the joystick port control for the purposes of simple interfacing.

Physical layer

The joystick port works with TTL levels, therefore it uses 0 Volts as logic 0 and +5 Volts as logic 1. The border between logic 0 and logic 1 is somewhere around 2 Volts. So to assure correct operation of the port you should work with signals between 0 and 1 Volts for logic 0 and between 3 and 6 Volts for logic 1. There are pull-up resistors to +5 Volts in all of the input lines of the joystick port and so by default, i.e. with no input, they are at high state (logic one).

The pin-out of the joystick port is the following:

             DB-15S (female)

          8  7  6  5  4  3  2  1
        __________________________
        \ o  o  o  o  o  o  o  o /
         \ o  o  o  o  o  o  o  /
          \____________________/
          15 14 13 12 11 10  9

              DB-15S pin-out
     --------------------------------
     (o) pin  1 +5 Volts
     (i) pin  2 Button 1   joystick A
     (i) pin  3 Position X joystick A
     (-) pin  4 Ground
     (-) pin  5 Ground
     (i) pin  6 Position Y joystick A
     (i) pin  7 Button 2   joystick A
     (o) pin  8 +5 Volts
     (o) pin  9 +5 Volts
     (i) pin 10 Button 1   joystick B
     (i) pin 11 Position X joystick B
     (-) pin 12 Ground
     (i) pin 13 Position Y joystick B
     (i) pin 14 Button 2   joystick B
     (o) pin 15 +5 Volts

     (o) = pin is for output
     (i) = pin is for input
     (-) = pin is common reference

Note: the above pin-out is the theoretical specification, however I have found that pins 9 to 15 (those of joystick B) are not connected in the joystick ports that I have seen.

Warning: I know the hard way that the +5 Volts pins cannot support high currents. Be careful when using this source as a power supply.

Using the port

The joystick port is monitored reading from the port address 0201h. The meaning of its bits is the following, where bit 0 is the least significant bit and bit 7 is the most significant bit.

Note: the above assignment is the theoretical specification, however I have found that those bits of joystick B are always set to 1 in the joystick ports that I have seen.

Using the commands and routines which every programming language has to read from the ports, you can check the status of the lines of the joystick port. This will let you interface with your own devices, for example you can check if a cable has been cut (alarm) or a switch has been activated, etc. For instance, if you want to monitor the status of the Button 1 of the joystick A and print a message when it is activated, you can do it with a BASIC program like the following:

10 WHILE 1 : REM *** Endless loop ***
20 B1A = INP (&h0201) AND &h10 : REM *** Read port and mask bit for Button 1 of joystick A ***
30 IF (B1A = 0) THEN GOTO 50 : REM *** Check if Button 1 of joystick A is low ***
40 WEND
50 PRINT "Button 1 of joystick A activated."
60 END


E-mail: padilla at domain "gae ucm es" (my PGP/GPG public key)
First version: 24-Jun-1997, last update: 28-Aug-2002
This link: http://www.gae.ucm.es/~padilla/extrawork/joystick.html
Color line
Back Go to the parent page: Specifications of useful PC ports.