›› Joystick Port Config for Output››› Atari can begin to control the outside world, not just sense it through the joystick ports.›› To do this we need an "output port." Inside the Atari is an integrated circuit numbered 6520, also called the PIA or Peripheral Interface Adapter. The PIA contains two 8-bit input/output (I/O) ports and two control registers. Associated with the PIA are two ICs, which monitor the address bus. Whenever an address between 54016 and 54271 is called, they alert the PIA to "come on-line."› When selected, the PIA monitors only the first two address lines, so that it responds to every fourth address whithin the 54016 to 54271 range. The address 00110011 has the same low two bits as 00000011, and the PIA responds identically to either, so PEEK 54020 is the same as PEEK 54016.› It's really a shame that better addressing wasn't included. Had it been, 252 byes in this section could be dedicated to external devices on the new XL/XE parallel bus, instead of the complex system now necessary. Oh well, nothing like wishful Thinking.› Memory address 54016 and 54017 are called "port A" and "port B" respectively. On the XL/XE computers, port B controls memory banks. POKEing here can disrupt operation of the computer so thoroughly that even a RESET won't recover it.› In the 400/800 computers, port B goes to joysticks 3 and 4. What's said about port A above applies to port B on these models. the connection is straight foward: Pin 1 of plug 1 controls bit 1 of port A. Pin 2 controls bit 2, and so on. As you you can see the results of activity on these pins by PEEKing 54016.› The real secret to the 6520 chip is memory location 54018, or "port A control." Each bit controls a specific function. When bit 2 (4 in decimal) is set to 0, then writing to port A can alter the port's function from input to output.› In this condidition, a 0 written to a bit in port A sets it to input, but a 1 sets it to output. Examine this listing:›››10 P=PEEK(54018):REM SAVE SONTROL SETTINGS FOR LATER›20 POKE 54018,P-4:REM SETS BIT #2 TO 0›30 POKE 54016,15:REM ETS ALL 8 BITS TO OUTPUT›40 POKE 54018,P:REM RESTORE PORT CONTROL›› Now, instead or PEEKing inputs from the joysticks, we can control the voltage on the joystick pins by POKEing to 54016, A 0 puts all pins to a logic 0, a 255 sets them all to 1, while 85 turns on every other pin.› Line 30 reads POKE 54016,15 (00001111), then the first four pins or port A is outputs, and the last four inputs. joystick 1 would be outs and stick 2 would be ins. Note the reverse relationship between binary numbers and joystick pins. Now a 00000001 (binary 1) POKEd into 54016 turns on pins in the 1000/0000 order, where the 1 is an on and 0 if off.››› Let's put this theory to test on a reusable bread board.›› PLUG 1› ›  1 2 3 4 5 ›  ›  6 7 8 9 › ›› Connect pins 1-4 of plug 2 to the #8 pin of plug 1. Use temporary jumpers.››› pin 1› › 2 |›   L 3 |  E›   D› 4 |  |›   |› |  | |›  | |›  | | |› 8 | | |›  ››› LEDs - Radio Shack #276-1622›› Now add these lines to listing 1 and run it:›››100 N=1:GOSUB 1000›110 N=2:GOSUB 1000›120 N=4:GOSUB 1000›130 N=8:GOSUB 1000›140 GOTO 100›1000 POKE 54016,N›1020 FOR DELAY=1 TO 500:NEXT DELAY:RETURN››› If done correctly you'll see the four Light Emitting Diodes (LEDs) blink sequentially. If not, check the wiring and try reversing the LEDs. Now add the following line:›››1010 HINIBBLE=INT(PEEK(54016)/16)*16:? HINIBBLE››› This is the same formula as that for most significant byte, except you use 16 instead of 256. While this pro gram is running, connect and disconnect the jumpers on the section attached to joystick 2› You'll see the reflection of the jumpers on-screen while the LEDs continue to blink. This simple system demonstates true simultaneous input and output, and gives a simple example of what can be done.›› Okay. What can we do with our newfound power? Inputs can be any switch, while outputs lines can be connected to many different kinds of devices.› You can control lamps, motors, stereos, TVs, alarm bells, sirens, beepers, and so on. However, the amount of power available to run these devices is limited to about 10 milliamperes (.01 amperes) from each joystick pin.› A little beeper will work just fine, but most other devices need more power. Pin 7 carries +5 volts at 50 milliamperes. If you use pin 7, the pins 1-4 will be 0 for on, and 1 for off. In other words the output is inverted. This works because a logic gate at 0 output is allmost a short circuit to ground and presents little resistance electrical current.› You can extend the driving power by providing an outside power source. An easy source to find and use is a 12 volt lantern battery. Connect the negative terminal to pin 8 or ground, but never connect the positive terminal to pin 7, ONLY to the device to be controlled. Then using pins 1-4 as the signal ground to activate the device.› You should limit the external voltage to 12 volts. DO NOT hook into a plug-in device or anything which has high voltage, unless your sure it's completly isolated electrically from the wall current. A good way to isolate from a high power device is to use an "opto-coupler" RS #276-134 (rated at 1 amp)- it's an LED encapsulated with a light-sensitive switch, so theres no physical, electrical connection between input an output, or use RS #275-217 10 amp relay for super high-power controller. You could use a combination opto-coupler and TRIAC for a high power driver also (600 watts).›› light › {o › | | 120 volts› | |  ---->› || |o | o › |6 5 4|||  | › Opto- | ||| | | | › Coupler |1 2 3||| |12 G|Triac | › ||  | ›  | || | | › pin 1 | |  ›  | | › pin 8 ^^^^ › 220 ohms ›››››› Above TRIAC requires a heat sink RS #276-1363 to keep it from over heating with full loads› One last precaution: devices that plug in should be built into a box, to prevent you from touching places you shouldn't›››End.›