3

A month ago, i asked this about multiplexing a string of numbers with 4 7-segment displays. But now, I'm trying to update the code to multiplex a string of letters using 7 7-segment displays in python.

This is the new circuit. When i send data using the parallel port, the Latch Enable receives the most significant bit (pin 9). In the second latch, the Latch Enable receives it also but negated, that is the reason of the 7404.

That is either address is set (/LE==False) or data is set (/LE=True).

This is what I'm trying to do. The 'X' represents that the 7-segment display is off. But can't archive it.

XXXXXXX
XXXXXXS
XXXXXST
XXXXSTA
XXXSTAC
XXSTACK
XSTACKX
STACKX0
TACKX0V
ACKX0V3
CKX0V3R
KX0V3RF
X0VERFL
0VERFL0
VERFL0W
ERFL0WX
RFL0WXX
FL0WXXX
L0WXXXX
0WXXXXX
WXXXXXX
XXXXXXX

That would be the output for the string "STACK 0V3RFL0W".

Also the past code:

import sys
import parallel

class Display(object):

def __init__(self):
    '''Init and blank the "display".'''
    self.display = [' '] * 4
    self._update()

def setData(self,data):
    '''Bits 0-3 are the "value".
       Bits 4-7 are positions 0-3 (first-to-last).
    '''
    self.display = [' '] * 4
    value = data & 0xF
    if data & 0x10:
        self.display[0] = str(value)
    if data & 0x20:
        self.display[1] = str(value)
    if data & 0x40:
        self.display[2] = str(value)
    if data & 0x80:
        self.display[3] = str(value)
    self._update()

def _update(self):
    '''Write over the same four terminal positions each time.'''
    sys.stdout.write(''.join(self.display) + '\r')

if __name__ == '__main__':
p = Display()
pp=parallel.Parallel()
nums = raw_input("Enter a string of numbers: ")

# Shift over the steam four-at-a-time.
stream = 'XXXX' + nums + 'XXXX'
data = [0] * 4
for i in range(len(stream)-3):
    # Precompute data
    for pos in range(4):
        value = stream[i+pos]
        data[pos] = 0 if value == 'X' else (1<<(pos+4)) + int(value)
    # "Flicker" the display...
    for delay in xrange(1000):
        # Display each position briefly.
        for d in data:
            pp.setData(d)
    # Clear the display when done
    p.setData(0)
Community
  • 1
  • 1
aerojun
  • 1,206
  • 3
  • 15
  • 28
  • 1
    Have you looked at PySerial's [PyParallel](http://pyserial.sourceforge.net/pyparallel.html)? Seems pretty straightforward. – jedwards Apr 29 '12 at 01:00

1 Answers1

0

Algorithm outline:

string = "07831505"

while True:
    for i in range(7):
        # switch display `i` on
        notlatch.set(True)
        data.set(1 << i)
        notlatch.set(False)
        time.sleep(<very little>)
        notlatch.set(True)
        # display character on display `i`
        data.set(char_to_7segment(string[i]))
        time.sleep(0.01)
Dima Tisnek
  • 11,241
  • 4
  • 68
  • 120