Classic Computer Magazine Archive COMPUTE II ISSUE 3 / AUGUST/SEPTEMBER 1980 / PAGE 50

COSMAC Quickies

Jess Hillman

Quick, inexpensive solutions to control problems are always desirable, so owners of COSMAC Elf microcomputers may find many interesting ways to use the “quickie” programs in listings one, two and three accompanying this article.

The programs were written specifically for my Quest Super Elf, which has 4.25K RAM, but they should run with very little tweaking on any 1802-based system, if entered beginning at any quarter-K page boundary.

Listing one is an interval timing program that can be set for any delay from a couple of seconds to about ten minutes by varying only the data byte in location 0011. By changing the program beginning at location 0015 to read: “9F FB XX (any value from 00 to FF) CE 30 05 7B 30 00” the program can set intervals up to two days (actually the maximum value for Register F falls a few minutes short of 48 hours). The data bytes in locations 0011 and 17 set the final value selected. Since the 1802 has plenty of registers for such usage, it would be very easy to establish intervals months long.

The program specifically uses Register E, one of the 1802's sixteen, sixteen-bit general purpose registers, as a timer that continually counts down from hex FFFF. When Register E reaches zero, a fact discovered by testing both high and low bytes, Register F is incremented by one. The F register is then tested to see if the predetermined value has been set. If not, the timing loop continues.

Once the proper value for F has been reached, the 1802 sets its Q line, an external flag that can be set or reset depending on various internal conditions of the processor, to a logic “1.” After thus acknowledging it has reached the required time, the Q line is reset to logic zero and the timer resumes its labors. The Q line transition can be latched by connecting it to an integrated circuit such as the 74LS175 or the CMOS 4016, and held for use in driving a transistor, opto-isolator or relay (for high voltage uses) to operate a coffee pot, television, stereo — practically anything controllable with an electronic switch.

Newcomers to the 1802 be warned: when tying to the Q line always buffer it generously with an IC like the 4050 or 4049, either of which can drive two TTL loads. Otherwise, you risk ruining your microprocessing chip.

A variation of this use of the Q line is found in listing two, in which the operator wishing access to the Q line must first enter three predetermined, two-digit hex numbers into memory in the proper sequence. That oughta keep Pop's pet project safe from the kids!

As the data bytes for the “combination” are entered into memory, the 1802 performs a logical exclusive or with each byte in turn, using data stored at addresses 000D, 0017 and 0021 respectively. If the wrong number is entered at any point, the program jumps to the error subroutine beginning at location 0030, which momentarily outputs an “EE” to the data display (I have seven-segment LEDs) while executing a three-second timing delay, then outputs a “00” to the data display and jumps back to the beginning of the program.

In listing two, once the proper number sequence has been entered, the Q line goes high and stays that way until the input key is pressed and released (or external data flag EF4 is otherwise pulled low). Once EF4 goes low and returns to its normal state, Q goes to logic zero and the program loops back to the beginning again.

As written, you would have to enter 05 (at 0D), 17 (at 17) and 98 (at 21) to turn the Q line from logic low to logic high. You can change the data bytes for any combination you wish. The chances of someone solving the combination decrease if you add more numbers to the combination.

Listing three changes this program to utilize an output port and eight data bits to control various devices. When entered as listed and run, the program will: require you to enter the three number combination properly, after which the Q line goes high (on my system this turns on an LED); then you must enter a status byte which will be put in the memory stack and also latched into the output port (1802 output instructions are 6N, where N designates a port from one to seven). I use a 63 instruction because that port is readily available on my Elf’s expansion board. Once the status byte has been latched to the output port, the program loops back to the beginning of memory and starts again.

The status byte can be whatever you want it to be, depending on your interface configuration. Eight data lines are immediately available, so using transistors, relays or a combination of techniques can give you immediate computer control of the major energy consuming devices in your home — air conditioning, hot water heater, and so on.

By expanding the interval timer to include a lookup table of status bytes for dispatch to the output port at various times of the day, automatic control your home's major functions becomes possible. The only question you must answer is how elaborate you want it to be.

Using the upper four bits of the status tied to, say, a 74LS154 four-to-sixteen line decoder, with the lower four bits or-tied to sixteen latches like the 74LS175, it would be possible to control up to sixty-four devices from your micro's output port. Possible expansions and combinations of these programs are virtually endless. As quickie programs go, however, they should give newcomers to the 1802, or people struggling with a system they've had for a time, a feel for register manipulation and control application possibilities of the typical COSMAC system.

Listing 1 — Interval Timer

Address    Data    Mnemonics    Comments                                                
0000       F8 00   LDI 00       Initialize Reg. F for
02         AF BF   PLO, PHI     use as workspace
04         7A      REQ          Make sure Q is at logic "0"
05         2E      DEC R.2      Decrement timer
06         9E CE   GHI, LSZ     Check timer, long skip if zero
08         30 05   BR 05        If not zero, continue loop
0A         8E CE   GLO, LSZ     If high byte zero, check low byte
0C         30 05   BR 05        If not zero, continue loop
0E         1F      INC Reg. F   If low byte zero, increment workspace register by one
0F         8F      GLO R.F      Get new value from Register
10         FB 17   XRI 17       Exclusive Or with predetermined value
12         CE      LSZ          If values match, long skip (PC incremented by 2)
13         30 05   BR 05        If no match, continue loop
15         7B      SEQ          Set Q line at logic "1"
16         30 00   BR 00        Then start looping again
17         00      IDL          End

Listing 2 — Combination Lock

Address    Data    Mnemonics    Comments                                                
0000       F8 00   LDI 00       Set up workspace in memory
02         B4      PHI          using Reg. 4 to point to
03         F8 F0   LDI F0       stack beginning at
05         A4      PLO          address 00F0
06         E4      SEX
07         3F 07   BN4 07       Loop if EF4 equals zero
09         37 09   B4 09        Loop is EF4 equals one
0B         6C      INP 4        Get keyboard byte
0C         FB 05   XRI 05       Check if correct combination #
0E         CE      LSZ          Long skip if zero (a match!)
0F         30 30   BR 30        Else go to error subroutine
11         3F 11   BN4          Wait until next byte latched
13         37 13   B4           in From keyboard
15         6C      INP 4        get the byte
16         FB 17   XRI 17       If it matches, too, then long skip
18         CE      LSZ
19         30 30   BR 30        Go To error subroutine otherwise
1B         3F 1B   BN4          If second number matches, wait
1D         37 1D   B4           for last combination number
1F         6C      INP 4        Get it
20         FB 98   XRI 98       See if it, too, matches
22         CE      LSZ          Long skip if it does
23         30 30   BR 30        Error subroutine if it doesn't
25         7B      SEQ          All numbers OK, Q equals "1"
26         3F 26   BN4          Keep Q line on until input
28         37 28   B4           key pressed and released
2A         7A      REQ          Then turn it off and go back
2B         30 00   BR 00        to beginning
                                Error subroutine
30         F8 EE   LDI EE       Load message “EE”
32         54      STR          store it in stack, then
33         64      OUT 4        output to LED display port
34         BF      PHI Reg. F   Also store in Register F
35         2F      DEC Reg. F   Reg. F decremented by one
36         9F      GHI          Check byte in Reg. F
37         CE      LSZ          Skip next two bytes if zero
38         30 35   BR 35        Otherwise loop
3A         F8 00   LDI 00       Load "00" and output to
3C         54      STR          clear error message from
3D         64      OUT 4        display
3E         30 00   BR 00        Go back and try again

Listing 3 — Controlling Multiple Devices

Address    Data    Mnemonics    Comments                                                
002A       6C      INP 4        Get the byte input after correct combination given
2B         54      STR          Put status byte in stack
2C         63      OUT 3        Output status byte to device interface
2D         7A      REQ          Turn Q off
2E         30 00   BR 00        Then go back to start