Driving four 7-segment array by using multiplexing

This project uses a LIM-5652G 4 X 7-segment array which was rescued from an old satellite receiver. Any similar array will do as long as The LED-circus boardit is a common anode display. The array has the seven segments wired internally and supply output pins for the a, b, c, d, e f and g interconnected segments and four pins which select the segment required. As these supply the current for the diodes, they are driven via four BCY51 or similar transistors. The bases of the transistors are connected to the upper four digital output lines of the Velleman board.

As this leaves only four more lines and we require seven lines to drive the segments, I used a 7447 logic chip. This is a BCD to 7-segment decoder/driver. The four BCD input pins are connected to the lower four digital output pins of the Velleman board.



The circuit diagram
The pcb layout

The arrangement is shown above. The only pin of the 7-segment display not connected drives the decimal points. A suggested PCB layout is shown on the right above. The PCB made from this negative was used for the circuit board in the photograph.


Programming the board

I have kept the program as simple as possible. It gives 5 choices. 1 to 4 select one of the four digits and count with it. Option 5 is the interesting bit. This counts from one to 9999 using multiplexing, i.e. switching between the four arrays so fast that the human eye is fooled into thinking it is looking at a continuous display. The work is done by lines 750 to 800.

  750   DEFPROCscan(D1%,D2%,D3%,D4%)
  760   SYS K8055_WriteAllDigital%,N%(D1%) OR Dis%(1)
  770   SYS K8055_WriteAllDigital%,N%(D2%) OR Dis%(2)
  780   SYS K8055_WriteAllDigital%,N%(D3%) OR Dis%(3)
  790   SYS K8055_WriteAllDigital%,N%(D4%) OR Dis%(4)
  800   ENDPROC

 

N%(D1%) to N%(D4%) supply the bit pattern for the number to be displayed. Dis%(1) to Dis%(4) contain the pattern that selects the current 7-segment array.

For instance, to write the number 9 to display 2 would return the binary numbers 1100, which is the pattern that writes the 9 and 01110000, which selects array 2. The two numbers are ORed, which makes 01111100 and this pattern is then sent to the output ports in rapid succession with the other three patterns. This scheme worked extremely well. With a K8055N board there is no flicker at all. The much slower K8055 shows a slight flicker, but the principle is well demonstrated - and this is all this project is designed to do.

As usual I supply a zip file with the BBC BASIC for Windows code and also a .exe file, should you not have BBC4W

K8055_7_seg_x4_1_1_N.zip

And here are the two files adapted for the K8061

K8061_7_seg_x4_1_0.zip


   10 REM K8055_7-seg_x4
   20 REM Multiplex four 7-segment displays
   30 REM Jochen Lueg
   40 REM http://roevalley.com
   50 REM Limavady, May 2012
   60 REM Version 1.0
   70
   80
   90 ON ERROR PROCerror
  100 PROCK8055_init
  110 PROCinit
  120 SYS K8055_CloseDevice%,Board%
  130 SYS K8055_OpenDevice%,Board%
  140 PROCscreen(700,280)
  150 OFF
  160 ON CLOSE PROCclose
  170 *FONT Lucida Console,14,2
  180 PRINT
  190 PRINT "   Select from the following:"
  200 PRINT
  210 PRINT "   1 . . . . . . . . Display 1 counts from 0 to 9"
  220 PRINT "   2 . . . . . . . . Display 2 counts from 0 to 9"
  230 PRINT "   3 . . . . . . . . Display 3 counts from 0 to 9"
  240 PRINT "   4 . . . . . . . . Display 4 counts from 0 to 9"
  250 PRINT "   5 . . . . . . . . Multiplex"
  260 PRINT
  270 PRINT "   Q . . . . . . . . Return to this menu"
  280 PRINT
  290 REPEAT
  300   REPEAT
  310     Key$=INKEY$(0)
  320     IF Key$="1" PROCcount_display(1)
  330     IF Key$="2" PROCcount_display(2)
  340     IF Key$="3" PROCcount_display(3)
  350     IF Key$="4" PROCcount_display(4)
  360     IF Key$="5" PROCmultiplex
  370   UNTIL FALSE
  380   PROCclose
  390   END
  400  
  410  
  420  
  430   DEFPROCcount_display(d%)
  440   LOCAL Num%
  450   Stop$="Run"
  460   REPEAT
  470     Num%=Dis%(d%)OR N%(Zahl%)
  480     SYS K8055_WriteAllDigital%,Num%
  490     Zahl%+=1:IF Zahl%=10 Zahl%=0
  500     Key$=INKEY$(30)
  510     IF ASC(Key$)<>-1 Stop$="Stop"
  520   UNTIL Stop$="Stop"
  530   ENDPROC
  540  
  550  
  560   DEFPROCmultiplex
  570   LOCAL A%,B%,C%,D%
  580   FOR A%=0 TO 9
  590     FOR B%=0 TO 9
  600       FOR C%=0 TO 9
  610         FOR D%=0 TO 9
  620           TIME=0
  630           REPEAT
  640             PROCscan(D%,C%,B%,A%)
  650           UNTIL TIME>5
  660           IF INKEY(-17) SYS K8055_ClearAllDigital%:ENDPROC
  670         NEXT
  680       NEXT
  690     NEXT
  700   NEXT
  710   SYS K8055_ClearAllDigital%
  720   ENDPROC
  730  
  740  
  750   DEFPROCscan(D1%,D2%,D3%,D4%)
  760   SYS K8055_WriteAllDigital%,N%(D1%) OR Dis%(1)
  770   SYS K8055_WriteAllDigital%,N%(D2%) OR Dis%(2)
  780   SYS K8055_WriteAllDigital%,N%(D3%) OR Dis%(3)
  790   SYS K8055_WriteAllDigital%,N%(D4%) OR Dis%(4)
  800   ENDPROC
  810  
  820  
  830   DEFPROCclose
  840   SYS K8055_ClearAllDigital%,1
  850   SYS K8055_CloseDevice%,1
  860   SYS "FreeLibrary",K8055_Board%
  870   QUIT
  880   ENDPROC
  890  
  900  
  910   DEFPROCscreen(ScreenWidth%,ScreenHeight%)
  920   SYS "SetWindowPos",@hwnd%,0,0,0,ScreenWidth%,ScreenHeight%,6
  930   VDU 26
  940   COLOUR 128
  950   CLS
  960   COLOUR 15
  970   ENDPROC
  980  
  990  
 1000   DEFPROCerror
 1010   PRINT REPORT$;" at line ";ERL  :
 1020   SYS K8055_ClearAllDigital%,1
 1030   SYS K8055_ClearAllAnalog%,1
 1040   SYS K8055_CloseDevice%,1
 1050   SYS "FreeLibrary",K8055_Board%
 1060   END
 1070   ENDPROC
 1080  
 1090  
 1100   DEFPROCinit
 1110   Board%=0
 1120   T%=-3
 1130   Zahl%=0
 1140   DIM N%(11)     : REM Pattern for numerals
 1150   N%(0)=%1111
 1160   N%(1)=%1110
 1170   N%(2)=%0111
 1180   N%(3)=%0110
 1190   N%(4)=%1011
 1200   N%(5)=%1010
 1210   N%(6)=%0011
 1220   N%(7)=%0010
 1230   N%(8)=%1101
 1240   N%(9)=%1100
 1250   N%(10)=%0000 : REM segments All OFF
 1260  
 1270   DIM Dis%(4)
 1280   Dis%(0)=%11110000 : REM All four arrays OFF
 1290   Dis%(1)=%01110000
 1300   Dis%(2)=%10110000
 1310   Dis%(3)=%11100000
 1320   Dis%(4)=%11010000
 1330   ENDPROC
 1340  
 1350  
 1360   DEFPROCK8055_init
 1370   REM  Typing errors in routine name do not generate an error message - they just hang up the program.
 1380   REM These are all the system calls in the order found in the manual
 1390   SYS"LoadLibrary","K8055D.dll" TO K8055_Board%
 1400   SYS"GetProcAddress",K8055_Board%,"OpenDevice" TO K8055_OpenDevice%
 1410   SYS"GetProcAddress",K8055_Board%,"CloseDevice" TO K8055_CloseDevice%
 1420   SYS"GetProcAddress",K8055_Board%,"ReadAnalogChannel" TO K8055_ReadAnalogChannel%
 1430   SYS"GetProcAddress",K8055_Board%,"ReadAllAnalog" TO K8055_ReadAllAnalog%
 1440   SYS"GetProcAddress",K8055_Board%,"OutputAnalogChannel" TO K8055_OutputAnalogChannel%
 1450   SYS"GetProcAddress",K8055_Board%,"OutputAllAnalog" TO K8055_OutputAllAnalog%
 1460   SYS"GetProcAddress",K8055_Board%,"ClearAnalogChannel" TO K8055_ClearAnalogChannel%
 1470   SYS"GetProcAddress",K8055_Board%,"ClearAllAnalog" TO K8055_ClearAllAnalog%
 1480   SYS"GetProcAddress",K8055_Board%,"SetAnalogChannel" TO K8055_SetAnalogChannel%
 1490   SYS"GetProcAddress",K8055_Board%,"SetAllAnalog"  TO K8055_SetAllAnalog%
 1500   SYS"GetProcAddress",K8055_Board%,"WriteAllDigital" TO K8055_WriteAllDigital%
 1510   SYS"GetProcAddress",K8055_Board%,"ClearDigitalChannel" TO K8055_ClearDigitalChannel%
 1520   SYS"GetProcAddress",K8055_Board%,"ClearAllDigital" TO K8055_ClearAllDigital%
 1530   SYS"GetProcAddress",K8055_Board%,"SetDigitalChannel" TO K8055_SetDigitalChannel%
 1540   SYS"GetProcAddress",K8055_Board%,"SetAllDigital"  TO K8055_SetAllDigital%
 1550   SYS"GetProcAddress",K8055_Board%,"ReadDigitalChannel" TO K8055_ReadDigitalChannel%
 1560   SYS"GetProcAddress",K8055_Board%,"ReadAllDigital"  TO K8055_ReadAllDigital%
 1570   SYS"GetProcAddress",K8055_Board%,"ResetCounter"  TO K8055_ResetCounter%
 1580   SYS"GetProcAddress",K8055_Board%,"ReadCounter"  TO K8055_ReadCounter%
 1590   SYS"GetProcAddress",K8055_Board%,"SedtCounterDebouceTime"  TO K8055_SetCounterDebounceTime%
 1600   ENDPROC








Return to the interfacing index


Back to the Limavady home page

Tudor with sign