Classic Computer Magazine Archive COMPUTE! ISSUE 30 / NOVEMBER 1982 / PAGE 207

PET Interfacing

Mike Baskerville
Compton, CA

A gentle introduction to PET interfacing with a simple example to let your computer control external devices.

Technological advances in the field of microprocessor interfacing permit the computer to control large amounts of current and voltage. Silicon devices such as the diode, transistors, and thyristors allow the computer to function as a very flexible control mechanism.

The intent of this article is to open the door for users who would like to do something with their PET/CBM other than send electronic mail and dazzle their friends with the PET's computing abilities.

The user port on the PET/CBM is one of the few things that has not changed from the first 4K PET to the current 32K CBM. It is driven by POKEs and read with PEEKs. Machine language programming allows very quick responses, making the port priceless. Those of you not familiar with the user port, pay close attention: you may be in for a pleasant surprise.

The 6522 VIA (Versatile Interface Adaptor) is the IC (integrated circuit) which gives us the user port. It provides a parallel eight-bit bidirectional data port as well as serial in and out for those great sound effects. Bidirectional means that data can be read or written and is an important feature because many hardware applications require monitoring as well as control. The eight-bit parallel port can control eight devices, or a combination of monitoring and control can be obtained without additional decoding or multiplexing.

Data seen on the port in the output mode is a one or a zero in binary. The corresponding measured quantities are + 2.4 volts (binary one) or something less than + 0.5 volts, which corresponds to the binary zero. Knowing this, and having a little knowledge of semiconductors and digital logic, you can easily control lights, TVs, radios, security systems, tape recorders, or just about anything that can be turned on and off.

Obviously, I can't (in one article) show how to interface to any device, but I will introduce a simple interface and trust that, with a little creativity, many users will adopt their own style and applications.

Like money in the bank, a buffer is a good idea. A buffer adds a margin of safety between you and the computer (we don't want to lose that 6522 VIA). For the purpose of buffering I have used AND gates, NAND gates, and/or hex inverters. In order to maintain compatibility, TTL (Transistor-Transistor Logic) IC's should be utilized. This compatibility assures proper voltage, current, and switching levels for the buffer. At this point, I recommend that anyone seriously interested in interfacing acquire a TTL data book. Many are on the market. The TTL Data Book (Texas Instruments) is fine. The 6522 VIA is manufactured by MOS Technology / Commodore Semiconductor Group. Their address is Valley Forge Corp. Center, 950 Rittenhouse Rd., Norristown, PA, (215)666-7950.

Our simple demonstration interface could control a lamp to provide home security or just to show off the versatility of your PET. You will need a NAND gate (SN74LS00), a 5 volt DC power supply, a NPN transistor, a SPST relay, a 10K resistor, and some means of bringing it all together.

The circuit shown in Figure 1 operates as follows: one of the inputs to the NAND gate is grounded, and the other is connected to the output of the user port. When the port goes low (POKE 59471,0), the NAND gate output goes high (which will forward bias the transistor and energize the relay coil). The contacts open and the lamp goes out. The 10K resistor between the base of the transistor and the NAND gate insures that only a small current will forward bias the transistor - insuring long life and saturation of the transistor. To turn the light on (POKE 59471,1), the port goes high, causing the NAND gate to go low; thus the transistor loses its bias and the coil voltage drops to zero. The lamp comes on. With this circuit configuration, and a relay with a one-amp contact rating, you can easily control a 100 watt light bulb.

It is a good idea to test your circuit before making the final connection to the computer. An additional advantage of the buffer (the NAND gate) is that the circuit can be tested by grounding both inputs of the NAND gate. This will simulate a low output from the user port. By removing one of the grounds, the NAND gate output will go low, simulating a high output on the port. A nice feature of TTL is that an open input is interpreted the same as a logic level one.

Driving the circuit can be as simple as pressing a button on the computer. If a triac is used, instead of the relay, the light could be dimmed and brightened as well as turned off and on. The sample program allows a time delay for the circuit.

This particular application of the user port is only one of the unlimited possibilities for your PET/CBM. I hope you have as much fun developing your interfaces as I do mine.

100 REM	SAMPLE PROGRAM FOR USER PORT I/O
110 PRINT"{CLEAR}" : POKE59468, 12
120 POKE59459,1 : REM	SETS PA-0 FOR OUTPUT
130 P$ = "{HOME}{12 DOWN} {17 RIGHT}"
140 T$ = "{HOME} {03 DOWN} {09 RIGHT}"
150 T1$ = "{HOME} {21 DON} {09 RIGHT}"
160 T3$ = "COMPUTERIZED LAMP CONTROL"
170 T4$ = "{10 RIGHT}PRESS"
180 T5$ = "{02 DOWN} {04 RIGHT} {REV} L {OFF}IGHT ˜ {REV} D {OFF}ARK"
190 L$ = "LAMP ON"
200 L1$ = "{REV} LAMP ON {OFF}"
210 O$ = "LAMP OFF"
220 o1$ = "{REV} LAMP OFF {OFF}"
230 PRINTT$; T3$; T1$; T4$; T1$; T5$
240 A$ = "L" : GOTO270
250 REM	THIS ROUTINE SETS PA-0 HIGH OR LOW
260 GET A$
270 IF A$ = "L" THEN POKE 59471,1:PRINTP$;L$:B$ = "L"
280 IF A$ = "D" THEN POKE 59471,0: PRINTP$; O$ : B$ = "L"
290 A = A + 1 : IFA>30 THEN GOSUB 320
300 GOTO 260
310 REM	FLASHING INDICATOR ROUTINE
320 IF B$ = "L" AND B1$ = "S": RETURN
330 IF B$ = "L"THEN PRINTP$;L1$:A = 0 : B1$ = "S" : RETURN
340 IF B1$ = "S" THEN PRINTP$; O$: A = 0: B1$ = "" : RETURN
350 PRINTP$; 01$: A = 0 : B1$ = "S"
360 RETURN