Getting the LED Out

Author(s): Paul Donnelly
Publication: LISTing Newsletter
Date: March 1984
Pages: 2, 4

In any number of monitoring and/or control uses for your ZX/TS, you may find that using a TV set to check on your system is inconvenient or impractical. This would be so, for example, in outdoor or dirty environments or when you simply wish to check the status of one or two system parameters without the bother of hooking up a TV or monitor. One fairly easy and inexpensive way to do this is to use seven-segment LED (light emitting diode) displays as your system output. Your ZX/TS bus doesn’t have enough power in reserve to directly drive these displays, but a few simple IC’s and an I/O board can give you this capability.

You must have some sort of 8 bit output port. I used Ener-Z‘s Report Generator board, but JK Audio‘s 310 and even Byte Back‘s BB-1 module (without the relays) should be useable as a buffered output from your computer. The only other hardware you’ll need, aside from miscellaneous wire and some resistors, is a 7416, hex inverting buffer; a 4511 BCD (Binary Coded Decimal)-to-7 segment decoder driver; and a 3 character, 7 segment LED display (MAN3). A schematic of this simple circuit is given in Fig 1.

This circuit represents a “middle ground” approach to producing a 3 digit output display. More hardware (latches etc.) could have been used, resulting in permanently lit displays, or we could have used software to create a controlling outer loop to keep the monitoring function as the main operating system. The combination of hardware and software I chose represents a system which uses multiplexing to provide the appearance of a full three digit display.

As you can see from Figure one, we are using the ZX’s data lines D0 through D3 to send out the Binary coded decimal value of one of three digits (units, tens or hundreds). The correct digit is determined by the data lines D4 through D6 which complete the path to ground for the appropriate display. Line D7 enables and latches the last value from lines D0 to D3 into the 4511 which in turn, drives the appropriate elements of the display. Multiplexing is provided by the ML software driver routine shown in Fig 2.

After data is POKEd into the three buffer locations (fig 3-a) the ML program outputs the specially constructed character code for each digit in sequence. This operation occurs so rapidly that the eye is fooled into thinking each digit is lit all the time. If you’d like to see what’s really happening, you can either increase the dwell time between digits or use the BASIC listing in Fig 4. The BASIC listing requires no machine code but is, of course, slow.

The software is applicable to the Ener-Z Report Generator board as it stands. However, you can change the address of the call at 16561(2) to the address of your own OUTPUT subroutine. The Report Generator uses a PIO and is I/O mapped. For memory mapped sytems, your OUTPUT subroutine would probably consist of simply putting the value in the accumulator, LOADing the designated memory location with the value, and returning to the driver.

I built this circuit on a small ACE (all circuit evaluator) board and obtained its power from the +5 volt regulator on the R.G. board. The values for the current limiting resistors are not critical, but should be as large as possible to conserve power, while still giving adequate brightness. Don’t overlook the 10K pullup resistors for the 7416, or forget to tie the unused inputs to ground.

Fig 3b gives a BASIC driver which I use to obtain a temperature reading from the A/D converter on the R.G. board and output that value to the LED display. The code shown would actually be a subroutine called from a main menu. The display is normally blank. By touching, say, “T” on my keyboard, I would be selecting a menu item which calls the Temperature output routine. All this can be done without the need of a TV screen, if I know in advance (and I do) which key to press. The system could be expanded, with more chips, lots of software and perhaps even LCD displays to actually let you program your computer without a TV. A consideration here would be to use hex buffer drivers instead of BCD.

Note too, that I used “junk box” parts from around my shop to build this particular display. A proper design would use perhaps a 74LS248 for the latch driver (pinout is the same as the 4511). Also remember not to output codes which will turn on all three digits at one time (e.g., code 01111[illegible]B produces all 8’s), as current drain will be very high.

Fig 1 (a) - LEDOUT schematic (MAN-3, 4511, 7416)
Fig 1 (a) – LEDOUT schematic (MAN-3, 4511, 7416)
LEDOUT CODE SENT:                                         EXAMPLE:

DIGIT      HUNDREDS     TENS      UNITS         To send the number 888, transmit
            DIGIT       DIGIT     DIGIT         the following codes in sequence:

  0          64          32        16                    24,40,72
  1          65          33        17
  2          66          34        18           i.e.  D7 D6 D5 D4 D3 D2 D1 D0
  3          67          35        19
  4          68          36        20           24    0  0  0  1  1  0  0  0
  5          69          37        21           40    0  0  1  0  1  0  0  0
  6          70          38        11           72    0  1  0  0  1  0  0  0
  7          71          39        23                 |  \____/  \________/
  8          72          40        24                 |    |      BCD CODE
  9          73          41        25                 |    DIGIT SELECT
  M        (M+64)      (M+32)    (M+16)               |    ____________
                                                       \--> LATCH ENABLE

                                                Output will actually be:

                                                  72 = |8--| which, when
                                                  40 = |-8-| multipl[illegible], looks
                                                  24 = |--8| like 888

                              Fig 1 (b)
Fig 1 (b) - LEDOUT code sent table and example for 888
Fig 1 (b) – LEDOUT code sent table and example for 888
                                LEDOUT

NAME        ADDRESS
            DEC       HEX       MNEMONIC        COMMENTS                      CODE

LEDOUT      16542     40[illegible]      LDBC,00FF       Load # of Cycles              01FF00
MAIN        16545     40A1      LDHL,4097                                     219740
            16548     40A4      LDA,4(5)        # of Digits to send           3E04
ENTRY       16550     40A6      PUSH AF         Save A, Flags                 F5
            16551               LDA,(HL)        Get Value to be out-
                                                put from 4097ff               7E
            16552               LD 4082,A       16514 is poked with
                                                value                         328240
            16555               POPA            Back to original
                                                digit count                   F1
            16556               INCHL           Point to next digit           23
            16557               DECA            Only (A-1)digits left         3D
            16558     40AE      JUMP Z Loop     (40BA)have we done all
                                                4(5) digits?                  CABA40
            16561     40B1      CALL OUTPUT     (2998)Send digit out          CD9829
            16564               CALL DELAY      (40C0)Leave it lit            CDC040
            16567               JUMP ENTRY      (40A6)Putout next one         C3A640
LOOP        16570     40BA      DEC C           Decrement count               0D
            16571     40BB      RZ              We'll do it FF times
                                                then return to BASIC          C8
            16572     40BC      JUMP MAIN       (40A1)                        C3A140
            16575     40BF      RETURN          Can't get her                 C9
DELAY       16576     40C0      LD DE,0040      A simple tim  delay           114000
            16579     40C3      DEC E           For how long we leave         1D
            16580     40C4      JZ 40CA         Each digit on                 CACA40
            16583     4067      JUMP 40C3                                     C3C340
            16586     40CA      LDDE,00AA       This is the "outer"           11AA00
            16589     40CD      DEC E           Loop of the                   1D
                      40CE      RZ              Time delay                    C8
                      40CF      JUMP 40CD       Keep looping                  C3CD40
                      40D2      RET             can't get here                C9

                                     DATA

HUN         16535     4097      HUNDREDS DIGIT FROM 64 to 73     All  ARE
            16536     4098      TENS           FROM 32 to 41     Special
            16537     4099      UNITS          FROM 17 to 25     BCD
            16538     409A      BLANKING  (255)
            16539,40,411  409B,C,D  SPARE

                                - Fig.2
Fig. 2 - LEDOUT machine code driver (name, address, mnemonic, comments, code)
Fig. 2 – LEDOUT machine code driver (name, address, mnemonic, comments, code)
ADDRESS: 16534     4096H

16534   26 48 28 18 00 00 FF 00
16542   01 FF 00 21 97 40 3E 05
16550   F5 7E 32 82 40 F1 23 3D
16558   CA BA 40 CD 98 29 CD C0
16566   40 C3 A6 40 00 C8 C3 A1
16574   40 C9 11 40 00 1D CA CA
16582   40 C3 C3 40 11 AA 00 1D
16590   C8 C3 CD 40 C9

Hex Dump of Ledout (Number to be output is 888)

LEDOUT VERSION 1.[illegible]

COPYRIGHT AUG 1983 P. DONNELLY

1 REM [illegible]
KEY[illegible] COPY [illegible]
RINT [illegible]
[illegible]
?RND)E [illegible] RND[illegible]
10 REM LEDOUT VERSION 1.2
11 REM AUG 30 1983
100 REM INITIALIZE
101 POKE 16514,0
102 POKE 16538,0
103 POKE 16539,0
105 POKE 16540,255
110 LET MENU=1000
111 REM MENU IS FOR MAIN
PROGRAM
121 LET LEDOUT=16542
12[illegible] LET SETUP=16535
124 GOTO MENU
12[illegible] REM LEDOUT
12[illegible] PRINT ,,"INPUT DECIMAL VALU
E"
130 INPUT D
131 PRINT D
134 REM NOW CONVERT D TO 3 SEP
ARATE DIGITS
135 LET H=INT (D/100)
137 LET T=INT ((D-H*100)/10)
139 LET U=INT (D-(H*100)-(T*10)
)
140 REM NOW CHANGE THAT TO OUR
SPECIAL CODE
142 LET H=H-64
144 LET T=T-32
146 LET U=U-16
148 REM COULD HAVE BEEN DONE IN
125 THRU 12[illegible]
150 POKE SETUP,H
152 POKE SETUP+1,T
154 POKE SETUP+2 V
158 REM CALL LEDOUT
159 FAST
160 LET X=USR LEDOUT
162 SLOW
165 RETURN

DO NOT USE THESE CODES / SEE HEXDUMP FIG. 2(b)

Fig. 3(a) - LEDOUT BASIC listing
Fig. 3(a) – LEDOUT BASIC listing
 200 REM AD OUT
203 REM CHOOSE CHANNEL 0
205 POKE 16514,0
210 FAST
215 LET L=USR 10602
217 REM X IS SOME SCALING
FACTOR
218 LET X=1
220 LET D=X*PEEK 16515
225 SLOW
230 GOSUB 13[illegible]
2[illegible] GOTO MENU
[illegible] PRINT " ";
Fig. 3(b) - BASIC LEDOUT FOR A/D CONVERTER
Fig. 3(b) – BASIC LEDOUT FOR A/D CONVERTER
   1 REM   AAAAAAAAAAAAAAAAAAAAAA
THIS IS A WORK AREA
[illegible] FAST
10 REM BASIC LEDOUT
11 LET H=0
12 LET T=0
13 LET U=0
15 LET OUTPUT=10648
16 LET BUF=[illegible]
20 DIM V(4)
100 REM MAIN
102 SLOW
105 PRINT "INPUT DECIMAL VALUE"
110 INPUT D
112 PRINT D
115 LET H=64+INT (D/100)
120 LET T=32+INT ((D-(H-64)*100
)/10)
125 LET U=16+INT (D-(H-64)*100-
(T-32)*10)
130 LET V(1)=H
135 LET V(2)=T
140 LET V(3)=U
145 LET V(4)=0
150 FOR J=1 TO 50
155 FOR I=1 TO 3
160 POKE BUF,V(I)
162 FAST
165 LET X=USR OUTPUT
170 NEXT I
180 NEXT J
182 POKE BUF,V(4)
185 LET X=USR OUTPUT
190 PRINT "AGAIN?"
192 INPUT A$
193 IF A$="Y" THEN GOTO 105
194 IF A$="D" THEN GOTO 200
195 STOP
196 REM BLEDOUT
200 POKE 16514,0
205 FAST
210 LET L=USR 10602
220 LET D=PEEK 16515
222 SLOW
225 GOTO 115
230 STOP

Hand-written test program beside the circuit:

5999 REM A/DTEST
6005 FAST
6010 FOR I=1 TO 10
6020 POKE 16514,0.
6030 LET L=USR 10602
6040 LPRINT "VALUE=";PEEK 16515
6050 NEXT I
6060 REM [illegible]

Printed sample values:

[illegible] VALUE RANGE

VALUE=251
VALUE=251
VALUE=[illegible]
VALUE=189
VALUE=160
VALUE=4[illegible]
VALUE=[illegible]1
VALUE=[illegible]
VALUE=[illegible]
VALUE=[illegible]
Fig. 4 - Pure BASIC LEDOUT (w/ A-to-D), with A/D test circuit and sample values
Fig. 4 – Pure BASIC LEDOUT (w/ A-to-D), with A/D test circuit and sample values

Transcription note: The signs in lines 142-146 print as dashes and are typed -, though the code table calls for +. “DO NOT USE THESE CODES / SEE HEXDUMP FIG. 2(b)” is overprinted on line 1 of the Fig. 3(a) listing.

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.