BUYER'S GUIDE TO ANTENNA ROTATORS

WORLD'S LARGEST- SELLING ELECTRONICS MAGAZINE ÀU

EASY-TO-BUILD 1-Hz TO 1-MHz FREQUENCY COUNTER

DX Clubs on

International

Shortwave | BREAKTHROUGH!

Build A High- - 4 Sensitivity Gas and THE COSMAC ELF Fume Detector A MICROCOMPUTER TRAINER Learn Electronic EXPANDABLE ANE. Theory with COSTS AS LITTLE AS $80. Calculators, Part Il

Inexpensive

Electronic Keyer Makes Morse Code Easy

TEST REPORTS

Onkyo "Quartz Lock" Stereo Receiver

B&0 Beogram 1900 Manual Turntable

Realistic Phase-Lock AM/SSB CB Transceiver

Popular Electronics

14278

HERE are basically two ways in

which you can get involved with microcomputers on the nonprofes- sional level. You can buy one of sev- eral reasonably priced hobby compu- ter kits, add a TV or typewriter termi- nal, and learn to use high-level lan- guage. On the other hand, you can build your own inexpensive system from scratch. This permits you to ex- periment with simple applications that do not require an expensive terminal or a large memory. You can communi- cate with the computer in a relatively simple language.

The "EIf" microcomputer project gives you the latter category of com- puter system—for about $80. It is an excellent hardware and software trainer that uses machine language and can be easily expanded to do just about anything a full-blown micro- computer can. Packaging, however, is up to you.

The basic Elf has toggle-switch in- put, hex LED display, 256 bytes of RAM, four input lines and a latched output line. It can be used to play games, sequence lights, control motors, generate test pulses, count or time events, monitor intruder-alert de- vices, etc. You can do all these things while learning how to program in order to produce a “real” output to determine whether or not the program you designed works. If you prefer not to control ortime things, a simple LED can be used to indicate whether or not your program works.

Our focus here is on the construc- tion of the low-cost computer and some simple examples of program- ming.

Design Details. The heart of the Elf microcomputer is the new RCA CDP1802 COSMAC microprocessor chip that sells for less than $30. The chip can use any combination of stan- dard RAM and ROM devices and can address up to 65,536 (65 k) bytes of memory. It has flexible programmed I/O and program-interrupt modes, an on-chip DMA (direct memory access), four |/O flag inputs directly tested by branch instructions, and a 16 x 16 matrix of registers for use as multiple program counters, data pointers, or data registers.

Other features of the 1802 chip in- clude voltage operation between 3 and 12 volts dc at very low current drain, TTL compatibility, built-in clock, and simplified interfacing. There is also a built-in program load-

AUGUST 1976

Popular Electronics

AUGUST 1976

BUILD THE

COSMAC “ELF”

A LOW-COST EXPERIMENTER'S MICROCOMPUTER

PART 1

Simple-to-build computer trainer can be expanded

for advanced applications.

BY JOSEPH WEISBECKER

Er

ADDRESS

16 GENERAL PURPOSE

REGISTERS

RØ-RF

||

8—BIT DATA BUS

4 INPUT LINES Q OUTPUT LINE

i SWITCH

SWITCHES DISPLAY

Fig. 1. Block diagram of basic computer. Up to 65K bytes of memory, 91 instructions, and varied 1/0 ports can be added as the system grows.

ing capability that allows you to load a sequence of bytes without having to toggle in a new address for each byte. No ROM is required for the minimum trainer system described here. The multiple program counters permit some interesting programming “tricks,” and the many single byte in- structions keep programs short.

A block diagram of the Elf system is shown in Fig. 1. The pinout for the 1802 microprocessor chip is shown in Fig. 2.

Basic Operation. The key to under- standing the computer is the method used for addressing the memory. At first, the procedure may appear to be complicated, but you will soon see that it is not difficult.

The 1802 chip contains 16 general- purpose registers, each holding 16 bits (two bytes) of memory addresses or data. The registers are labelled RO through RF to conform to the hexadecimal numbering system, as shown in Fig. 3. (In the diagrams, and in computer technology in general, a Danish zero—a zero with a slash through it—is used to distinguish zero from a capital letter O.) Hence, if we refer to the low-order, or least- significant, byte of R1, we can call it R1.0, while the high order byte of RF would be called RF.1.

There is also an 8-bit D register that is used to move bytes around. In the instruction set shown in part in the Instruction Subset Table, note that the 8N (8 with a digit) code will copy a low-order general register byte into register D. Writing this instruction as 81 in a program will cause R1.0 to be copied into D when the instruction is executed. We can then use instruction 34

BF (BN in the table, with B and a digit) to copy the D byte into RF.1. It takes two bytes, 81 BF, to transfer a byte from R1.0 to RF.1 via temporary hold- ing register D. The byte in D can also be used in arithmetic operations per-

CLOCK CONTROL ( WAIT CLEAR

i501

STATE CODES " T ———

Fig. 2. Pin out for the CDP1802

0012. M3 would mean the memory lo- cation specified by the contents of R3, and M(0012) means memory location 0012 directly. MX means the memory location addressed by the contents of the general register selected by the current digit in X. If X = 3, MX = M3; if R3 = 0012, MX = M3 = M(0012).

Since the basic computer has only 256 bytes of memory, we use just the low-order bytes of the general regis- ters to address the memory. In expanded-memory systems, you can use the high-order bytes of the general-purpose registers to select individual 256-byte pages of random- access memory (RAM).

The memory contains both instruc- tions and data bytes. Instruction bytes tell the computer what to do with the data bytes. One-byte instructions have two hex digits, where high-order bits 7, 6, 5, and 4 tell the computer what type of operation to perform. Low- order bits, 3, 2, 1, and O are usually placed in the N register when a new instruction is fetched from memory.

a ) LO REQUESTS T(M—————

INTERRUPT MWR TPA,

rpg | TIMING PULSES aoo ida

COSMAC micro- BUS 5 MAG processor. us ays '8U5 : «€ MEMORY ADDRESS BUS 2 Más [ ——————— BUS | MA? eus d MAI Vcc MAS N2 EFI) 1/0 cows [n EF? 6 FimeS w——— "d$ = má:

vss

formed by the ALU (arithmetic logic unit) circuits.

There are three other important reg- isters that are labelled N, P, and X. Each can hold a 4-bit digit that is used to select one of the 16 general- purpose registers. For example, if you wanted to talk about the general- purpose register selected by the hex digit in X, you would call it RX. If you wanted just the low-order byte of RX, call it RX.0. RN would refer to the general-purpose register designated by the 4-bit digit currently contained in N; if the digit is 4, RN R4.

The general-purpose registers can contain 16-bit memory addresses. Suppose register R3 contains data

Any one ofthe general-purpose reg- isters can be used as a program counter. The program counter ad- dresses instruction bytes in memory. Each time an instruction is fetched from memory, the program counter is

ee [sese v [eje

Fig. 3. The 16 registers in the 1802 ave labelled RQ through RF (hex).

POPULAR ELECTRONICS

N2/LOAD MREAD

TPA Sci scg RUN LOAD

DMA IN DMA OUT

INTERRUPT

+5V

é

GND

Ret SS com UNES DEED URS MP l L|

TP.

D S50 S60 570

1 B | +5V 20/18} 19] 5| TN PRE: ia| 8 7

$80 590 SIOÓ SHO

INPUT SWITCHES SHOWN IN DOWN OR OFF POSITION

eeg toy tap Tag fag tigtag | a

Fig. 4. Complete circuit for the Elf computer. Identified connections on the left go to the “front panel” with the eight data switches. The remaining can be left “floating” at 1802, or tied to terminal strip.

Cl, C2—10-pF, 16-volt capacitor C3, C4—30-pF disc capacitor D1 through D6—IN914 switching diode ICI—CDP1802 COSMAC microprocessor chip (RCA) 1C2, 1C3—2101 (256 x 4) static RAM IC 1C4, IC5—4050 noninverting hex buffer IC 1C6, IC7—Hex LED display (H-P No. 5082-7340) IC8, IC9—4016 quad bilateral switch IC 1C10—4023 triple 3-input NAND gate IC 1C11—4049 inverting hex buffer IC

electrolytic

automatically incremented so that it points to the next instruction to be fetched. Branch instructions can be used to change the address in the program counter to permit jumping (branching) to a different part of the program when desired. The digit in the 4-bit P register specifies which 16-bit general-purpose register is being used as the program counter.

Timing Sequence. Since many of AUGUST 1976

PARTS LIST

1C12—4013 dual D flip-flop IC

IC13—LM309K 5-volt regulator IC

LED —Red light-emitting diode

RI through R9—47.000-ohm. !4-watt resis- tor

R10—470-ohm, “4-watt resistor

R11—10-megohm, !4-watt resistor

S1 through S11—Spdt toggle switch

S12—Pushbutton switch with one set each normally open and normally closed con- tacts

XTAL-—1-to-2-MHz crystal (see text)

Misc.—5%" x 4" (14 x 10.1 cm) perforated board with 0.1" (2.54 cm) hole spacing;

the 1802 microprocessor's instruc- tions are only one-byte long and re- quire two machine cycles, the first cycle is always an instruction fetch, or memory read. The fetched instruction is executed during the next machine cycle, which could be a memory-read, memory-write, or register-transfer type of cycle.

Program execution always consists of a sequence of fetch-execute cycles, and the two SCO and SC1 lines (see

51^" x 2" (14 x S.1cm) piece of thin aluminum; 34" x 36” (19.1 X 9.5 cm) pine for chassis rails; 14-pin IC sockets (4); 16-pin IC sockets (3); 22-pin IC sockets (2; 40-pin IC socket; connector for power supply; 9-volt, 350-mA dc power source; 144" x 34" x 4" (31.8 x 19.1 x 3.2 mm) piece of aluminum; dry-transfer lettering kit; machine and wood hardware: hookup wire; solder; etc.

Note: the CDP1802 COSMAC microp- rocessor chip is available from any RCA parts distributor as is tte COSMAC user manual.

Fig. 4 and Fig. 5) indicate what type of cycle is being performed according to the following criteria: SC1 SCO Type of Machine Cycle

0 O instruction fetch

0 1 instruction execute

1 0 DMA in/out

1 1 interrupt Direct memory access (DMA) and in- terrupt are special types of cycles, which we will discuss later.

Circuit timing is shown in Fig. 6.

35

Fig. 5. Control circuits for the computer. Connections at right go to similarly marked connections on main circuit.

Note that each machine cycle requires eight clock pulses.

The microprocessor has an internal single-phase clock circuit. Connect- ing a crystal between pins 1 and 39 of the 1802 chip causes the clock to run continuously. If desired, XTAL, C3, C4, and R17 can be omitted and an exter- nal clock with a 5-volt swing can be substituted between pin 1 and ground.

During each machine cycle, timing pulses TPA and TPB are available at pins 33 and 34 of the 1802. TPA occurs at the beginning of each machine cycle and can be used to clock the high-order byte of a 16-bit memory address into a memory page-selection register. Note that the 1802 sends out memory addresses as two 8-bit bytes. The high-order byte appears on ad- dress lines AO through A7 first. Then the low-order byte is held on the AO through A7 lines for the remainder of the machine cycle. This low-order ad- dress byte can, by itself, specify one of 256 locations inthe minimum 256-byte memory.

TPB occurs toward the end of the machine cycle and is used to clock a byte from the RAM into an output de- vice (such as the hex display used here). An input byte, to be stored in the

36

DI- D6=IN9!4

D5

RAM, is gated to the bus for the dura- tion of the input (memory-write) machine cycle so that no time pulse is needed for input bytes.

The MREAD line is low during any memory-read machine cycle. When low, it opens the pin-18 RAM data out- put gates of /C2 and /C3, permitting the byte stored in the RAM location addressed by AO through A7 to appear on the data bus. The RAM's access time is such that the output byte ap- pears on the bus priorto TPB. The bus byte from the RAM can then be clocked into an internal register of the 1802 or clocked to an external register (such as the hex display) with TPB, depending on the type of instruction being executed.

When the 1802 is performing an in- struction cycle that requires a byte to be stored in the RAM, the MREAD line is held high to disable the RAM output

Fig. 6. Microprocessor timing. One machine cycle requires eight clock pulses. TPA and TPB control various functions, both on and off the computer.

bus gates. The microprocessor then causes the byte stored in the RAM to be gated onto the bus during the memory-write cycle. This byte can come from an internal register of the 1802 or from an input device (such as switches), depending on the type of instruction being executed. The 1802 then generates a low memory-write pulse (MWR) that causes the bus byte to be stored in the RAM location ad- dressed by the AO through A7 lines.

Circuit Operation. Using Fig. 4, Fig. 5, and the Instruction Subset Table, we can now discuss the logic of the Elf microcomputer. The RAM address is sent out on lines AO through A7. Eight tri-state bidirectional bus lines are used to transfer the data bytes back and forth between the 1802's re- gisters and the /C2-/C8 RAM. A RAM byte can be transferred to hex displays IC6 and IC7 via the data bus, using /C4 and /C5 to supply the current drive for the displays. Displays /C6 and/C7 con- tain latches to store the display byte.

The basic clock frequency of the processor is determined by XTAL, which should not go above 2 MHz in this circuit. The MREAD and MWR lines control the read and write cycles of the RAM, while TPA and TPB pro- vide the timing pulses. TPA can be used for memory expansion address latching, TPB to clock bytes into out- put circuits. SCO and SC1 indicate the type of cycle being performed by the 1802.

The NO, N1, and N2 lines are used to select input or output devices. In the EIf, selection can be made among four input and four output devices. The table details the values of the NO, N1, and N2 lines during the machine cycle in which an input or output instruction is executed. Instructions 69, 6A, 6B, 61, 62, and 63 are spares that can be used to add I/O devices or ports to the computer. When 6C is executed, the N2 line goes to a logic-1 state and the bus byte is written into the RAM. Since this is a write cycle, MREAD will be high. With both N2 and MREAD high, the output of gate /C70C will be low, putting the input toggle switch byte on

eLock tein n F'LTUTTTUTUTLTUTYTUTUTLTITI !

TPA (PIN 34) y —i m. 1 l

TPB (PIN -——a a

Ag—A7 XHEYTOXLO BYTE VALETO

OERD PNT T XL M CX

i) l ' | 1 D

1 1

MWR (PIN 35) a

POPULAR ELECTRONICS

N|RN«1

RN-1 RN,O-D RN. 1 =D DRN. O0 DRN. 1 MND ,RNe1 DMN NaP NX 00 10 MX -»D MX or D=D

MX and D-»D

MX xor D-»D

SHIFT D RIGHT,BIT O0-»DF ROTATE D RIGHT,0F-87,B0DF SHIFT D LEFT, BIT ?-90F ROTATE D LEFT,DF9B0,879DF MX =D =D , CARRY -»DF D - tX -»D,CARRY =>DF MaDaD CARRY

LIGHT OFF) LIGHT ON)

m BYTE INSTRUCTIONS Two PTE ENS

ui m "T IF Qa1 GO TO mm IF Q=0 GO TO mm" IF D=00 CO TO mm IF DADO GO TO MM IF DFa1 CO TU MM IF DFa0 GO TO mm IF EF1a1 GO TO m" IF EF1a0 GO TO mm IF FF2a1 GO TO "m IF EF2a0 GO TO mm IF EF35a1 CO TO mm IF £F3a0 CO TO mm IF EF4a1 IN GO TO mm IF €F 4e0 (SWITCH KK =~)

KK or D-»D

KK and D-»D

KK xor D-»0D

KK =-DapD , CARRY ADF

D -KK >D , CARRY -»DF

KK +D =D , CARRY -»DF KKeDsDF «9D, CARRY DF

Instruction Subset Table shows required sequence of steps.

the bus so that it can be stored at the memory location addressed by RX. This input byte will also be placed in the 1802's D register.

When a 64 instruction is executed, N2 is high and MREAD is low, making the output of /C10C high and prevent- ing the input switch byte from getting onto the bus. Instead, gate /C10B gen- erates an output clock pulse with TPB that clocks the RAM output byte into the hex display.

The four external flag input lines— EF1, EF2, EF3, and EF4—can be pulled low by external switches. These four lines can betested by instructions 34, 3C, 35, 3D, 36, 3E, 37 and SF. Note in Fig. 5 that the INPUT pushbutton switch, debounced by portions of IC11, is connected to the EF4 line. This means that EF4 = 1 when S12 is de- pressed and EF4 = 0 when $72 is in its normal position.

Latched output line Q can be set high by a 7B instruction or reset to low by a 7A instruction. The Q LED comes on when Q is high. The DMA IN, DMA OUT, and INTERRUPT lines can be pulled low to cause these operations to occur.

The LOAD and RUN lines control the operation of the microprocessor ac- cording to the following conditions:

LOAD RUN Mode gnd gnd load +5V gnd reset gnd +5V = +5V +5V run

RUN and LOAD switches S1 and S2 in Fig. 5 control the operation of the computer. With both switches set to

AUGUST 1976

OFF, LOAD is +5V and RUN is at ground potential. This resets the 1802. Neither TPA nor TPB are generated in the reset state and RO = 0000, P = 0, X = 0 and Q = O0 after the 1802 is reset. When the LOAD switch is set to ON, LOAD goes low and RUN stays low, forcing the system into the load mode. Now you can load a sequence of bytes into the RAM, starting at address 0000, by setting the bytes into the input tog- gle switches, oneatatime, and operat- ing the iNPUT switch.

In the load mode, the 1802 does not execute instructions but waits for a low to appear on the DMA IN line. When this happens, the 1802 performs one memory write cycle during which the switch input byte is stored in memory. RO is used to address mem- ory during the DMA IN cycle. After the input byte is stored at the address specified by RO, this register is in-

INTRODUCTION TO PROGRAMMING.

Once you have built your Elf, you must learn how to load a sequence of bytes into memory and then go back and display the sequence. Let us write a simple program that can be loaded into the memory and run.

Suppose you want to program the com- puter to turn on the Q LED whenever the INPUT switch is set to ON. First, you must draw a flow chart that shows the required sequence of steps (Fig. 7). Locate the cor- rect instructions in the Instruction Subset Table. A 7A instruction will perform Step 1. Load this instructioninto M(0000). Notethat when the INPUT switch is not depressed, EF4 = 0. Atwo-byte 3F 00 instruction will jump (branch) back to the 7 A instruc- tion at M(0000) as long as the INPUT switch is not operated (EF4 = 0). This condition is known as a "loop," and the program wili stay in this loop while it is waiting for the INPUT switch to be depressed. Load 3F 00 into memory locations M(0001) and M(0002) to perform the second step in the flow chart. All GO TO MM instructions shown in the Table put MM into the low- order byte of the program counter if a GO TO condition exists. Otherwise, the next instruction in sequence is fetched by the 1802.

Loading a one-byte 7B instruction into M(0003) takes care of Step 3, while a 30 01 instruction will jump back to the 3F 00 in- struction at M(0001). Load the 30 01 in- struction into M(0004) and M(0005) to complete the program.

You load this 6-byte program by placing the LoAD switch on the oN position, with

RUN and MP set to OFF, setting up the toggle switches for the hex number 7A, and de- pressing the INPUT switch. Release the INPUT Switch, insert 3F and operate the INPUT switch again. Then load 00 and so on until the last byte, 01, has been stored at M(0005). If you “blow” the program, set MP to ON and LOAD to OFF. Then set LOAD to ON and operate the INPUT switch until you get to the byte immediately preceding the wrong entry. Set MP to OFF, set up the cor- rect byte, and operate INPUT. Flip MP back to ON to protect what you have stored in memory.

To start the program running, set LOAD to the down position to reset the 1802 and set the RUN switch to ON. Nothing should happen until you depress the INPUT Switch, at which time the Q LED should come on. Releasing the INPUT switch should cause the LED to extinguish. If you like, you can now observe the timing signals of the 1802 on an oscilloscope while the program is running.

Another simple program involves count- ing the number of times the INPUT switch is operated and then turning on the Q LED at the end of the count. The flow chart for this program is shown in Fig. 8. When you load and run this program, nothing wili happen until you operate the INPUT switch five times, at which point the LED will come on and remain on. Note in Step 1 that you can change the number of times the INPUT switch is operated. Step 6 just loops on itself to terminate the program after the INPUT switch has been operated the specified number of times.

37

STEP !

STEP 2

STEP 3

STEP 4

STEP | PUT COUNT (95) —-D Fe øs

STEP 2 "IN" DEPRESSED ? EI YES

STEP 3 "IN"STILL DEPRESSED ? o pu NO

STEP 5

STEP 6

START (Q LED IS OFF)

Fig. 7. Program turns on Q-LED when INPUT switch is operated.

cremented by one so that input bytes will be sequentially loaded into RAM locations. Line SC1 goes high during the DMA IN cycle so that the control circuits know when the input byte has been stored in the RAM.

Depressing and releasing INPUT switch S72 sets flip-flop /C12 (Fig. 5). The Q output of this stage goes low, causing the required low on the DMA IN line. The 1802 responds to this re- quest with a memory-write cycle dur- ing which SC1 is high. During this cy- cle, MREAD is high and, since LOAD switch S2 is also ON, the N2/LOAD sig- nal causes gate /C10C to go high, gat- ing the switch input byte to the data bus and storing it in memory. When SC1 goes high, it also resets /C12, which causes DMA IN to return to its high state. The computer then waits forthe nextswitch input byte and LOAD switch operation.

Following each DMA IN cycle, the 1802 holds the AO through A7 lines at the address of the byte just stored in the RAM. MREAD is also held low while waiting for the next input byte. This means that the previously loaded byte is being gated to the bus (fromthe

START

i—a,STOP

Fig. 8. Program counts number of times INPUT switch is operated. 38

RAM) while waiting for a new byte. This bus byte is continuously clocked into the hex display, since the LOAD switch is holding /C10B open.

A sequence of program bytes can be loaded into the RAM starting at MO M(0000) by setting the LoAD switch to the oN position, with the RUN switch set to orr. Set the eight input Switches, S4 through S71, to the de- sired byte code (in hexadecimal) and depress the INPUT switch to store the byte in the RAM. The value of this byte will be displayed with the hex displays IC6 and /C7. Repeat this procedure for each byte to be loaded. Setting the LOAD Switch to orr puts the 1802 back in the reset state where RO = 0000, P = 0, X = 0, and Q = 0. If you wish to see what is stored in memory, set MP (memory-protect) switch S3 and the LOAD Switch to ON. Now, each time you operate the INPUT switch, successive bytes in the RAM, starting with M(0000), will be displayed.

To change a byte, proceed to the byte just before the one to be changed. Flip the MP switch to OFF, set the input toggle switches to the hex value of the new byte, and depress the INPUT Switch once. This new byte will be displayed and stored in the RAM at the location following the byte at which you stopped. Place the MP switch in the ON position. You can now continue to operate the INPUT switch to sequence through the RAM without modifying the bytes in memory.

To start the executive cycle of a program, set both the LOAD and RUN switches to orr (to reset the 1802). Then set the RUN switch to oN. The program counter is always specified by the hex digit in register P, which can be set to zero by reset so that the program counter will always initially be RO. Set RO to 0000 by resetting so that instruction fetching, or program execution, will always begin at M(0000). Instructions will continue to befetched from the RAM and executed until the RUN switch is set to OFF, reset- ting the computer. Make sure that the MP switch is OFF when running prog- rams so that computer operation is not inhibited.

Construction Notes. Hardware as- sembly is relatively simple, permitting the project to be put together with or- dinary perforated board with 0.1” (2.54-mm) hole spacing and IC sock- ets, using either Wire Wrap? or a wir- ing pencil. (See photo.) The perf board measures 5V2"L x 4"W (14 x 10.2 cm)

and is supported on a base made up of lengths of 34" x 36" (19.1 x 9.5) pine. A sheet of thin aluminum provides the support for the eight toggle-type data switches. The LM309 voltage reg- ulator IC (/C13) is mounted on a 114" x 34" x Ve" (31.6 x 19.1 x 3.2-mm) piece of aluminum to serve as a heat sink.

Do not mount the IC's (except the display devices) in their sockets until after all wiring is complete. Socket, switch, and component layout should be roughly the same as shown in the photo. Be sure to locate the crystal close to pins 1 and 39 of the micro- processor's socket. Then wire the cir- cuit in accordance with the sche- matics in Figs. 4 and 5.

Any crystal with a frequency of be- tween 1 and 2 MHz can be used in the Elf, or you can substitute a simple 555 or CMOS oscillator with a 5-volt signal swing between pin 1 of the 1802 and circuit ground, in which case, you will have to omit XTAL, C3, C4, and H11. There is no lower limit to the clock fre- quency, but most of the sample prog- rams discussed in this series of articles are based on aclock frequency between 1 and 1.8 MHz.

Displays /C6 and /C7 are relatively ex- pensive hex devices. They are the only TTL devices in the computer and, as a result, draw most of the power required by the circuit. If you wish to economize, you can substitute ordinary LED's for the displays. (Next month, we will dis- cuss how to make the substitution.)

An inexpensive 9-volt, 350-mA dc bat- tery eliminator, like those used as bat- tery charger/eliminators for calculators, can be used to power the EIf.

When the computer is completely as- sembled, use a dry-transfer lettering kit to label all switches and positions, IC socket locations, and pins 1 of all soc- kets. Then, exercising the usual safety procedures for handling MOS devices, install the integrated circuits in their respective sockets.

Coming Up. In future articles, we will provide more programs as well as methods of adding other types of inputs and relay-control output circuits. We will also detail how to save programs in battery-powered COSMOS RAM!'s and describe a simple operating system that lets you read/write any memory location and inspect general register contents for program debugging purposes. Memory expansion, hex keyboard in- put, and an inxpensive video graphics display are other subjects we will cover in detail.

POPULAR ELECTRONICS

AST MONTH, we discussed the

construction of the low-cost Elf microcomputer/trainer and gave some examples of simple program- ming. This month, we will describe hardware and how to make a low-cost LED replacement for the relatively ex- pensive hex display and add a simple 8-bit I/O port. Then we'll add a 16- switch monitor that, among other things, will allow you to use a hex keyboard. We'll finish up the hardware section by showing how to use a 9-volt battery as power for a RAM circuit to hold a program for as long as six months.

When we're finished with the hard- ware details, it's back to the software, continuing with our programming discussion.

The Hardware. The hex displays called for in the original Elf project can be replaced with a discrete LED circuit as shown in Fig. 1. You will need a CD4508 eight-bit register, eight low- current LED's, two 4049 hex inverters, and eight 470-ohm, Ve-watt resistors. When the LED circuit is substituted for the hex displays, current consump- tion will be reduced by about 150 mA. The input comes from the data bus, which formerly went to hex displays IC4 and /C5.

When you use the LED display, you `

must count the LED's to arrive at the hex number displayed. The upper four LED's form the first digit, the lower four the second digit.

You can mount the LED's on the front panel. Besure you carefully iden- tify each. Also, when making the con- version, don't forget to modify the RUN switch circuit as shown.

You can connect an inexpensive cadmium-sulfide (CdS) cell between the EF1 line and ground. Be sure to use a photocell that has a dark resist- ance in excess of 200,000 ohms and a light resistance of less than 10,000 ohms. If you use any other photocell, you may have to increase the value of the resistor to pull up the EF1 line of the 1802 microprocessor. The high input impedance of the CMOS logic eliminates the need for photocell amplification. Also, several photocell inputs can be used, each connected to a different flag (EF) line.

Using a photocell input, you can program the computer to start count- ing when an object moves past one photocell and stop counting when the object passes a second cell. This technique allows you to determine the

SEPTEMBER 1976

speed of a moving object. It can also be used to count people, monitor motor speed, provide targets in a computer-controlled light gun or "eyes" for a computer-controlled robot, etc.

Magnetic reed switches, simple make/break switches, or similar de- vices can be connected to the compu- ter via the flag-line inputs.

Several inexpensive methods of ex- panding the number of input and out- put lines can be used with this compu-

ter. One example is shown in Fig. 2. Here, a CD4058 IC is used in both the input and the output positions, while other IC's provide the necessary gat- ing. A 69 instruction will store the val- ues of the eight input lines in memory as a single byte.

In the output port section, a 61 in- struction sets a memory byte into this port. The output port can control up to eight output lines, but you will have to add CD4050/CD4049 buffers if you wish to drive TTL loads. You can use

BUILD THE

A LOW-COST

T

EXPERIMENTER'S MICROCOMPUTER PART 2

Some hardware improvements and more programming details,

BY JOSEPH WEISBECKER

FROM IC4, PIN I5 +5V

cD 4058 8-BIT

"M

m |, 4049 “>s Ic5 up OFF: Oo o O RUN RUN e

Fig. 1. Circuit fora discrete LED display.

these output lines to drive suitable transistors to control relays, lamps or LED's, or battery-powered motors, you can have the computer sequence lights, control animated displays or robots, or control a slide projector in response to tones from an audio tape. You can use the existing Q line output in the same manner for a single opera- tion.

Asimple method of controlling up to 16 output lines or monitoring the states of 16 switches is shown in Fig. 3. A 62 instruction will set the low-order digit of a memory byte into the 4-bit

+5V

8-BIT f INPUT PORT |

INPUT

NES CD4508

NOOoun _B&

INPUT CLOCK {OPTIONAL} 47

DATA Bus

VOTO PU - BD

8-BiT OUTPUT PORT

38

Fig. 2. A way to expand the number of input and output lines using two

= CD4508 integrated circuits.

CD4515 register. The output line cor- responding to this digit will go low, while the other 15 remain high. To make things more interesting, the computer can determine whether the switch attached to the selected output line is closed or not by testing EF2 with a branch instruction.

The following program continu- ously examines all 16 switches in sequence and stops with the number of any closed switch from 0 to F in the low-order digit of R3.0:

Step M Bytes Comment

1 0000 F8 FF A2 FF-R2.0 (memory pointer)

2 0003 1352E2 R3 + 1, R3.0— M2, 2X

3 0006 6222 MX—CD4515 (select switch)

4 0008 3D03 Repeat step 2 if switch is open

5 000A 300A Stop with R3.0

= closed switch number

The diodes can be omitted if only one switch at a time will be closed. This circuit and an appropriate pro- gram could permit data and instruc- tion bytes to be loaded into memory a digit at a time from a hex keyboard instead of toggle switches. Switch de- bouncing could be performed with a programmed delay following each key depression. A 64-character keyboard could be used by treating it as four groups of 16 keys each, with the com- mon side of each key group con- nected to a different flag line. In fact, a program to generate the Morse code equivalent of each key could be writ- ten using the Q line as the output.

This circuit can also be used to select one of 16 external devices or I/O ports if desired. Using the latter technique would permit up to 128 I/O lines. Cascading CD4515's would

permit even larger numbers of I/O lines to be handled.

A low-cost video terminal can be made using the “Scopewriter” (PoPu- LAR ELECTRONICS, August 1974), or you can interface your computer with a cassette data interchange system.

We have only scratched the surface of I/O circuits for the Elf. The rea! fun (and program training) starts when you think of new things to attach to the output lines and start writing pro- grams to activate them.

The major drawback with a RAM, or memory, system is that data stored in it is erased when the main power source is shut down. (Of course, if you could use a ROM, this wouldn't be a problem. However, ROM's must be preprogrammed with the memory data you wish to save, a costly and time-consuming approach.) Adding a cassette interface doesn't entirely eliminate the problem because a "bootstrap" is still required to be stored in memory to run the cassette.

The use of low-power COSMOS RAM IC's and a 9-volt mercury battery, as shown in Fig. 4, will allow you to save programs in memory for up to six months even with the main power to the computer turned off. The 1822 RAM's shown are pin-compatible with the 2101's specified for the original project, but some of the RAM's must be rewired as shown.

With the COSMOS RAM's installed, you can turn off power to the compu- ter at any time. The mercury battery will supply the required standby power to the memory system so that the program will be ready to run im- mediately when the computer is again powered up. The newly added STANDBY switch should be turned on (+5 volts) only after power is turned on. It should be off to hold pin 17 of the RAM's at ground potential before removing power from the system.

CD4515$ 4 TO 16 LATCH

AND DECODE

Fig. 3. A method of controlling up to 16 outputs.

POPULAR ELECTRONICS

Periodically check the battery’s out- put; if it should fall too low, the mem- ory system won't be able to hold data.

The last piece of hardware we will discuss here is the simple output driver shown schematically in Fig. 5. Thisisa conventional driver for almost anything that doesn't require more current than the transistor is capable of safely handling. The diode in the relay circuit removes the reverse transient spike that might otherwise damage the transistor. You can substi- tute a LED or even a load resistor for driving a power stage.

More Programming. The single- line output program shown below is a simple program that will flash the Q LED at a preset rate. It also provides a programmable square wave on the Q line.

Step M Bytes Comment 1 0000 7A | 02Q 2 0001 F8 10 B1 10—R1.1 3 0004 21 R1-1 4 0005 91 R1.1—D 5 0006 3A04 Repeat step 3 if D = 00 6 0008 3100 Gotostep 1 if Q=1 7 000A 7B 1—Q 8 000B 3001 Goto step2 When you run this program, the

square-wave frequency depends on the settings of the input switches. You can change frequency at any time. For higher frequencies, change B1 at M(0006) to A1 and 91 at M(0008) to 81. You can now select any of 256 dif- ferent frequencies by altering the set- tings of the switches.

To modify the program to sweep the audio frequency range, usethe follow- ing program:

Step M Bytes Comment

1 0000 F8FFA2 FFR2.0

2 0003 7A | 02Q

3 0004 82A1 R2.0—-D; D—R1.0

4 0006 2181 R1-1; R1.02D

5 0008 3A06 Repeat step 4 if D = 00

6 000A 3103 Goto step 2 if Q=1

7 000C 7B 22 82 1—Q; R2-1; R2.0—D

8 O000F 3200 Gotostep1ifD = 00

9 0011 3004 Gotostep 3

This program can be used in audio test applications. Note that R2 is used asa second counter that causes the

SEPTEMBER 1976

square-wave frequency to change after each cycle. You can hear what this sounds like by using the circuit shown in Fig. 5.

Very low frequency square waves, or long-interval timing, can be pro- grammed by cascading counters as il- lustrated in the following flow chart:

The Q line can then be used to activate a relay (as in Fig. 5), which can control house lights, motors, etc.

Suppose you wish to program a variable-pulse generator instead of square-wave generator. Use separate counts for the pulse off and on times as illustrated in the following flow

chart: OFF COUNT —>RI

ADDRESS LINES a3.

DATA LINES

This program will flash the Q LED and put a square wave on the Q line at a rate determined by the contents of memory M (0002) from a 10 to some other number. By referring back to the Instruction Subset Table in last month's article, you should be able to interpret the above program.

Note in the program that R1 is used as a 16-bit decrementing counter (steps 3, 4, and 5). When the high- order eight bits of this counter reaches 00, the Q line goes to its op- posite stage. Changing steps 2 and 4 to use the low-order byte of R1 in- creases the Q line's output frequency by a factor of 256.

If you use a 1-MHz crystal in the clock, the above program can gener- ate square waves at frequencies be- tween 0.3 and 80 Hz, depending on the byte in M(0002). By changing the B1 instruction at M(0003) to A1 and the 91 instruction at M(0005) to 81, square waves between 80 and 20,000 Hz can be generated. In this manner, your basic computer becomes a pre- settable square-wave generator.

We can rewrite the program so that the square wave's frequency becomes a function of the settings of the toggle switches as follows:

Step M Bytes Comments

1 0000 F8 FF A2 FF-R2.0

2 0003 E2 2X

3 0004 7A | 05Q

4 0005 6CB1 Switch byte— MX, D:D—R1.1

5 0007 2191 Ri-1; R1.1-D

6 0009 3A07 Repeat step 5 if D = 00

7 000B 3104 Goto step 3 if Q=1

8 000D 7B 3005 1—Q; Go to step 4

Fig. 4. Using a low-power COSMOS RAM and a 9-volt battery permits saving programs in memory.

39

2N2222 SIMILAR

Fig. 5. Circuit to provide outputs used for testing.

In a similar manner, you can program bursts of pulses, variable-interval pulse trains, etc. You can even write a program where alist of bytes specifies a sequence of different tones to make a programmable music box.

The following two programs are "games" that demonstrate how the COSMAC instructions can be used. No added I/O circuits are required to run these programs.

Load the following sequence:

Step M Bytes Comment

1 0000 E1 1X

2 0001 F80F A1 OF—R1.0

3 0004 64 MX-display; X +1

4 0005 3F05 Wait for INPUT switch to be depressed

5 0007 6C Switch byte MX,D

6 0008 F8 0A F7 0A5D; D-MX—D

7 000B 5164 D—-M1; MX > display; X + 1

8 000D 300D 00 Stop; 00

Set both the LOAD and MP switches to off and then flip RUN to on. Have someone select any digit between 1 and 9 multiply by 10, add the original digit. Then multiply the sum by 9. Have the person who selected the digit tell you the result but not the original digit. Set the binary code for the least-significant digit of the final ans- wer into switches 3, 2, 1, and 0, and place the other input switches in the down position. When you depress the INPUT Switch, the computer will dis- play the unknown digit.

This program illustrates how to seta memory byte into the output display with a 6C instruction. Note the use of R1 asa memory pointer and the use of the binary subtract instruction in step 6.

40

The following program makes the computer “think” of a byte, which you must guess in no more than seven tries:

Step M Bytes Comment Q1 0000 8AAB RA, OoRB.0 = secret byte 2 0002 F8 AA A3 AA>R3.0 = memory pointer 3 0005 53E3 D—M3;3>X 4 0007 F807 A4 07—R4.0 = number of turns 5 000A 6423 M3-display, 3 +G- 1 6 000C 2A 3F0C RA + 1 until INPUT is depressed 7 OOOF 370F Wait for INPUT to be re- leased 8 0011 6C8B Switch byte>M3; RB.05D 9 0013 F533 1A M3-D—D; Go to step 12 if M3 = RB.O 10 0016 F801 01D 11 0018 3022 Go to step 16 (show D) 12 001A 3A20 Goto step 15 if D = 00 13 001C 5364 D-M3; M3 display; 3 + 1 14 001E 301E Stop loop 15 0020 F810 10>D 16 0022 536423 D—MS-display; 34 1;3- 1 17 0025 2484 R4-1, R4.0—D (turn counter) 18 0027 3A0C Gotostep6if D = 00 19 0029 8B7B RB.0D; 12Q 20 002B 301C Go to step 13

(show D and stop)

Place both the MP and LOAD switches in the off position after toggling the program. When you start the program by operating RUN; AA is displayed. Now, try to guess what byte the com- puter has selected by setting the eight INPUT switches and depressing the main INPUT switch. If 00 is displayed, you guessed correctly; if 01 is dis- played, your guess is too low; if 10 is displayed, your guess is too high. You lose after seven wrong tries, at which point, the computer turns on its Q LED and the displays indicate the hidden byte. To try again, set RUN to off and then on.

The subtract instruction in step 9

HEX NUMBER SYSTEM Decimal

Binary Hex 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111

"nmoou»uoococ-oo0^50o0m-co

sets an arithmetic overflow flag (DF) if MX is equal to or greater than D. The COSMAC instruction manual covers a detailed explanation of the use of this overflow flag in arithmetic and shift operations.

In Closing. Now that you have some familiarity with programming for the EIf, look through your back issues of POPULAR ELECTRONICS for some chal- lenging programs to write. Try the "Logidex" game in the November 1973 issue, "Tug-of-War" game in February 1975, "Electronic Dice" in July 1975, and the ‘Executive Digital Temper Countdowner'' in December 1975. These are just a few of the many electronic games you can program in- stead of building. e

ame d= AU VA 4g sas A U Nu Vgs CETE p Mere. 7 <

-Ait

Vi

“Uh... About this loaner you sent us while our computer is being repaired. . ."

POPULAR ELECTRONICS

N TWO previous articles (POPULAR BY JOSEPH WEISBECKER ELECTRONICS, August 1976 and Sep-

tember 1976), we discussed the con-

struction of the low-cost Elf microcom-

puter, gave some programming exam-

ples, and described some low-cost op-

tional input/output circuits. Here we will

examine some software operating sys-

tems and discuss adding 1024 bytes of : memory for as little as $20. MI e

Operating Systems. An operating system is a program that makes it easier

to program and use your computer. For Y À ee A 99 example, if you want to change M(43) in | the basic Elf memory, you would have to J N aN

start at M(00) and step through memory

to location 43 before you could change

it. Program 1 is a simple operating sys- d

tem for the Elf microcomputer. It lets you | r directly examine or modify any memory A

location. It also allows you to start pro- ]

gram execution at any memory location. We call Program 1 ETOPS-256 (Elf Tog-

gle OPerating System for 256-byte i È memory). After loading ETOPS in RAM, PART 3: it can be used to help you load and run

other programs. , How to expand me mo ry,

To examine a memory location using ETOPS, set 01 into the toggles. Flip the pl us more p rog rams RUN switch up and 01 will be displayed. Now set the address of the memory byte you want to examine into the toggles and push the INPUT switch. The next time you push the iNPUT switch, you'll see the selected memory byte dis- played. Keep pushing the INPUT switch to see the sequence of bytes stored in memory.

To modify any memory location, set 02 into the toggles and turn the RUN switch up. 02 will appear. Set the ad- dress of the memory byte you want to modify (via the toggles).

Push the INPUT switch and the Q light comes on. Now set the toggles to the value of the byte you want to place in the selected memory location and push the INPUT switch to store it in RAM. You can store a sequence of new bytes by set- ting each byte into the toggles and push- ing the INPUT switch. The Q light warns that you are modifying memory.

If you have the toggles set to 00 when you flip the RUN switch up, you can then set the toggles to the beginning address of a program you want to execute. Just push the INPUT switch to start executing your program at the selected address. Your program will begin execution with R3 as the program counter.

If you've added the battery RAM op- tion to your system, ETOPS will be ready to use as soon as you turn on power. Since ETOPS uses only 32

i CIRCLE NO. 5 ON FREE INFORMATION CARD

0000 F8 FF A2 R2.0 = work PORA e ZR RR Nom O4 60 64 21 D = toggles SS al 3 07 3F 07 Wait for IN on oo s age eee M(0D) 09 37 09 Wait for IN off OD DS At BSUB, R1.0-D OB 32 1D M(1D) if D-00 ó "a ay ME adis OD F6 33 11 M(11) if D-01 io. 4 34 M4) 12-0590. 10 7B Q-1 "eiue 11 60 At R1.0 = toggles 12 81 A5 BAe eon 13 3F 13 Wait for IN om 14 F6 5B !C M(10) ife Deoa 15 37. 15 Wait for IN off T D E1 paye, že a 17 39 1A M(1A) if Q=0 19 64 ow M1, Ri+ 1A 64 Show M1, R1+1 eo D3 ÆI BUBI à 1B 30 13 Repeat M(13) 1E 51 64 Mi=D, show Mi, R1+ 1D 6C A5 R3.0 = toggles 20 30 10 Repeat M(1C) 4P D3 P=3 ec. D3 P=3 (return) 20 00 Work area BSUB 21 User programs from 25 D6 HSUB M(21) to M(FF) 24 FE FE D left x 2 26 FE FE D lett x 2 28 AO D6 R1=D, HSUB 2A 80 M 52 M2=R1 or M2 2D 64 22 Show M2 2F 30 22 Go to M(22) 51 FO D5 D=M2, P=5 HSUB PROGRAM 3 33 E2 FC 01 X=2, D+1 56 FA OF 52 M2=D and OF 0050 F8 FF A1 R1.0 - work 29. 62 22 Select key M2 55 F8 00 51 M1-00 3B 3D 53 M(33) if key off 56 E1 64 21 Show M1 3D 7B F8 09 Q=1, D-09 59 FO FC O01 51 M1+1 40 B4 R4. 1-09 5D F8 10 B2 R2.1 = delay 41 24 94 R4-4 60 22 R2-1 45 3A 41 M(41) if R4.1400 61 92 3A 60 M(60) if R2.1400 45 TA Q=0 64 30 56 Repeat M(56) 46 35 46 Wait for key off 48 30 31 Go to M(31)

bytes, you still have 224 bytes available for your own programs.

Keyboard System. Adding a hex keyboard would make your Elf mi- crocomputer even easier to use. With 16 keys labelled O through F, you woula have to press «nly two keys for each byte you want to store in memory. In the second article, we described a circuit for monitoring the states of 16 switches or keys. (See POPULAR ELECTRONICS, Sept. 1976, page 38, Fig. 3). If you add this circuit and a 16-key hex keyboard, you ^an use Program 2—LEHC ?S-256 (Elf Hex OPerating System for 256-byte memory). This program requires 74 bytes of RAM so you still have 182 bytes left for your own programs. You can also use the hex keyboard subroutine as part of your programs if desired.

After loading EHOPS in memory, you can use it as follows. To load a byte into any memory location from the hex key- board, set the toggles to 02 and flip the RUN switch up. The 02 toggles tell EHOPS that you want to store b-tc > in

64

memory. On the hex keyboard, press the most-significant digit of à memory address followed by the least-significant digit. This address byte will be displayed and tells EHOPS where you want to start loading bytes in memory. You can now load a sequence of bytes into mem- ory via the hex keyboard. Just press the two digits (most significant first) of each byte you want to load and they will be stored sequentially in memory starting at the selected location.

To examine any memory location (without changing its contents), set the toggles to 01 before you flip the RUN switch up. Using the hex keyboard, en- ter the one-byte starting address of the sequence of memory locations you want to examine. Press any hex key twice to Step through memory and display the stored bytes.

To rt ^ a program you've loaded using EHOPS, set the toggles to 00 before flip- ping the RUN switch up. Using the hex keyboard, , enter the one-byte starting address of your program. It will begin running with R3 as the program counter.

EHOPS controls the hex keyboard with two subroutines called BSUB and HSUB. BSUB calls HSUB by changing the program counter to R6 with a D6 in- struction. HSUB continuously scans all 16 hex keyswitches until one is pressed. It provides a switch debounce delay and waits until the key has been released. It then returns control to BSUB with the value of the pressed key in the least-sig- nificant digit of the byte in D and M2.

BSUB is called by changing the pro- gram counter to R5 with a D5 instruc- tion. It waits until two hex keys have been pressed before returning control to the calling program with the values of the two keys in the two digits of the byte in D and M2. The most-significant digit represents the first key pressed. Any program you write with R3 as the pro- gram counter can call BSUB to obtain a byte from the hex keyboard. If you drive a speaker with the Q lines as described in the September article, you will hear an audible click each time a hex key is pressed.

Program 3 can be loaded and run us-

POPULAR ELECTRONICS

30

PROGRAM 4 FO AA RA.O=FO 08 A8 R8.0=08 5A BSUB, MA=D 28 At1, R8-1 3A C6 M(C6) if R8.0400 FO AA RA.O-FO , 08 A8 R8.0=08 FO A7 R7.O=MA 28 Show MA, A+1, 8-1 FF AC RC.O=FF 87 Q=1, D=R7.0 01 D-01 DD M(DD) if DZOO 87 Q=0, D=R7.0 01 D-01 i ES M(E3) if DZOO 8C RC-1 DB rm if RC.04Z00 34 D3 M(D3) if R8.0400 CD M(CD) if R8.0=00 FO-F7 - Table of tone values PROGRAM 5 0000 F8 OO BI 05 FS FF M 06 F8 00 51 09 E1 64 21 OC FO FC O1 51 10 F8 10 B2 15 22 14. 92:0«35« 15 17 30 09 M READ

MARCH 1977

DATA BUS

M(13) if R2.1400 Repeat M(09)

AIO A9 AB A7 A6 AS A4 A3 A2 Al AO

i5Y is¥ i4¥ ey ey SW «ay 2y IV io] 9 ICI -2102 (1024 XI RAM) IC4 -2102 IC7 -2102

LCIO,11= 4016; PIN 7 OF IC9,10, I1 =GND} PIN14 OF IC9,10, I « +5

ing either ETOPS or EHOPS: This pro- gram continuously counts up at a rate determined by the byte at M(5E). Be sure to start execution at M(50). Program 4 should be loaded and run using EHOPS. You should also have a Speaker attached to the Q line. Start this program at M(CO) with EHOPS. You can then enter eight bytes via the hex key- board. These bytes should have values between 02 and 7F for best results. Each byte represents the frequency of a tone you will hear via the speaker. After

TO FiG.2

Fig. 1. Address latch. *Connect pin 19 of original 2101 RAM's to A10 instead of ground.

you enter the eighth byte you'll hear the eight-tone sequence repeated over and over. You can restart the program at M(CD) to hear a previously entered tone sequence.

An operating system can be designed to incorporate any desired feature. For example, you might want to examine the contents of internal 1802 registers or control the operation of a cassette re- corder. As more features are needed,

MWR

Fig. 2. Eight low-cost,

readily available 2102 RAM's (1024 x1) and two transmission gate packages.

B5

you may want to dedicate the entire 256 bytes of memory in the basic system to your operating system and add another section of memory for your other pro- grams. The 256-byte operating-system memory can be battery-powered and protected from modification by the MP switch so that it is always ready for use.

Memory Expansion. You can add 1024 bytes of memory to an Elf mi- crocomputer using inexpensive, readily available 2102-type static RAM's as shown in Figs. 1 and 2. The 10k bus pull-up resistors are required if the high- output level of the RAM chips isn't at least 3 volts. Bits O and 1 of the high- order address byte are clocked into the address latch with TPA (Fig. 1). These two latched bits are used with the low- order COSMAC address byte to provide the required 10-bit address for the 2102 RAM's. Bit 2 of the high-order address byte is clocked into the address latch for use in selecting either the original 256- byte RAM or the added 1024-byte sec- tion of RAM. Disconnect pin 19 of the original two 2101 RAM chips from ground and connect to pin 12 of the 4042 address latch in Fig. 1.

The original 256-byte memory will now be addressed as 0000-00FF and the new 1024-byte memory will be ad- dressed as 0400-07FF. Since all of the previous programs assumed one-byte addresses, they will not run in this ex- panded memory system. Programs for systems with more than 256 bytes of memory must have both the high-order and low-order bytes of address registers properly set. The previous programs can be easily modified to run in the expand- ed system by initializing both high- and low-order bytes of any 16-bit register used to address memory. The foregoing counting program could be modified to run at M(0000) in an expanded RAM system as shown in Program 5. In gen- eral, it adds only a few bytes to program for an expanded-memory system. By adding bits to the address latch of Fig. 1, you could address up to 64k bytes of RAM. Instead of addressing extra mem- ory, the high-order address bits could be used to select input/output circuits or devices.

Don't forget that adding memory will increase system power requirements. As the system is expanded, make sure your external power supply can handle the increased current requirements. With this in mind, you'll find that the Elf can be tailored to your needs at low cost. o

66

A READER'S ELF PROGRAMS

| recently constructed the COSMAC Elf described in your August (1976) issue and thoroughly enjoyed the construction and testing of this microprocessor system. 1 build approximately two projects a month that are illustrated in your magazine—plus some from other sources. This particular project turned out to be the most interest- ing | have ever constructed. Here are three programs that | found useful in illustrating various system functions.

Program lis simply an expansion of your Q-light program with additional decisions that alternately turn the Q light on and off when the input switch is depressed.

on and off at intervals determined by the subroutines. The memory provided in the basic Elf system (256 bytes) is enough for approximately 19 code elements. Each code element requires only 10 instructions for an on and off interval in the main pro- gram. The timing loops require the use of two registers to provide a sufficient time. In my Elf, ! used a 1-MHz crystal. Obviously, changing one instruction in the loop sub- routines will vary the time as necessary. Changing or adding to the main program can change the code.

Try loading this program with the switch register if you have enough patience.

Program |! displays and increments —Robert Klein successive hex characters each time the input button is depressed. To do this, it was necessary to learn how to input to and PROGRAM I output from the memory, using pointers in registers, and also to do simple arithmetic SWITCH ON AND OFF 3p through the accumulator (D register). 0 Program III plays SOS in Morse code. 37 The program should be loaded through the B2 System switch registers if you have a half hour without interruption. With this pro- IF Q OFF GO TO f9 59 gram, registers are used for pointers to $9 subroutine loops set up for time delay. Three subroutines for 0.5 second, 1 sec- IF Q ON, TURN OFF AND 7A ond and 3 seconds are established, ad- RETURN TO f 30 dressed by changing the program counter. 9 The main program simply turns the Q light IF Q OFF, TURN.ON AND 7B GO TO fj 3p PROGRAM II STORE DEPENDENT VARIABLE (f E4 IN LOCATION 77 WITH POINTER F8 IN R4--DESIGNATE R4 AS RX 77 A4 F8 54 STORE INDEPENDENT VARIABLE 21 F8 IN LOCATION 76 WITH POINTER 76 IN R5 A5 F8 $1 (size of INCR) 23) DISPLAY AND DECREMENT RX 64 24 LOOK FOR INPUT SWITCH ON AND 3F OFF OF 37 1p ADD TWO VARIABLES AND PUT a5

RESULT IN LOCATION 77

(can be changed to subtract 54

to count down)

RETURN TO START OF LOOP

F4 (F5 subtract)

POPULAR ELECTRONICS

PROGRAM IIT MAIN PROGRAM

INITIALIZE ` POINTERS

FIRST DOT

SECOND DOT

MARCH 1977

65 * THIRD DOT

D3 FIRST DASH

7A SECOND DASH

7B 78 D3 D4 F8 F8 65 * 79 * A3 THIRD DASH A4 FIFTH DOT : : F8 1 65 * p * 43 2

A5 d 7B 76 E; aud 65 * SIXTH DOT A4 FOURTH DOT A3 PAUSE AND’ TA . TA RETURN TO D3 D3 START F8 F8 65 * 65 * A5 A5 T8 D4 F8 79 * * If a different number of A4 code elements is used, 7A change the starting ađdress D3 of each sub routine, or F8 move to the end of memory 65 * page 5 flexibility is A3 esired.

PROGRAM III

SUB ROUTINES (Must be loaded in order indicated after main program is loaded.)

PUT 256 IN REG #1

PUT VARIABLE INTO REG #2

DECREMENT AND LOOP THRU R1 UNTIL ZERO. THEN OUTPUT TO DECREMENT

REG #2

LOOP BACK TO START R #1 CYCLE UNTIL TOTAL TIME IS USED UP

RETURN TO MAIN PROGRAM

$-Sec Loop

6B **

* Sets Time

** If a different number of code elements is used, change this instruction to starting address of each subroutine -

- wait loop (first O4)

1-Sec Loop

3-Sec Loop

All instructions same as $-Sec Loop except where indicated

ØF * 3 * TP ** 95 ** TP ox 95 +

67