From d0a37fc2392880eafe74a4ea5a85b4ae29483523 Mon Sep 17 00:00:00 2001 From: hneemann Date: Mon, 6 Mar 2017 17:55:48 +0100 Subject: [PATCH] added a common cathode input to the seven segment display. --- .../de/neemann/digital/core/element/Keys.java | 12 +++++ .../digital/core/element/PinDescriptions.java | 2 +- .../java/de/neemann/digital/core/io/Out.java | 47 +++++++++++++------ .../digital/draw/shapes/SevenSegShape.java | 35 +++++++++++++- src/main/resources/lang/lang_de.xml | 8 ++++ src/main/resources/lang/lang_en.xml | 9 ++++ 6 files changed, 96 insertions(+), 17 deletions(-) diff --git a/src/main/java/de/neemann/digital/core/element/Keys.java b/src/main/java/de/neemann/digital/core/element/Keys.java index ed53ab04c..2c9bb58ce 100644 --- a/src/main/java/de/neemann/digital/core/element/Keys.java +++ b/src/main/java/de/neemann/digital/core/element/Keys.java @@ -274,4 +274,16 @@ public final class Keys { public static final Key RELAY_NORMALLY_CLOSED = new Key<>("relayNormallyClosed", false); + /** + * Used to indicate if the 7-seg display has a common cathode output + */ + public static final Key COMMON_CATHODE + = new Key<>("commonCathode", false); + + /** + * Used to enable the storage of the last state in the Seven Seg display. + */ + public static final Key LED_PERSISTENCE + = new Key<>("ledPersistence", false); + } diff --git a/src/main/java/de/neemann/digital/core/element/PinDescriptions.java b/src/main/java/de/neemann/digital/core/element/PinDescriptions.java index ae0383702..fbc5969dc 100644 --- a/src/main/java/de/neemann/digital/core/element/PinDescriptions.java +++ b/src/main/java/de/neemann/digital/core/element/PinDescriptions.java @@ -30,7 +30,7 @@ public class PinDescriptions extends ImmutableList { * @param key the key to set * @return this for chained calls */ - PinDescriptions setLangKey(String key) { + public PinDescriptions setLangKey(String key) { for (PinDescription pd : this) { if (pd instanceof PinInfo) { ((PinInfo) pd).setLangKey(key); diff --git a/src/main/java/de/neemann/digital/core/io/Out.java b/src/main/java/de/neemann/digital/core/io/Out.java index e21be729d..a8363b6cf 100644 --- a/src/main/java/de/neemann/digital/core/io/Out.java +++ b/src/main/java/de/neemann/digital/core/io/Out.java @@ -1,10 +1,7 @@ package de.neemann.digital.core.io; import de.neemann.digital.core.*; -import de.neemann.digital.core.element.Element; -import de.neemann.digital.core.element.ElementAttributes; -import de.neemann.digital.core.element.ElementTypeDescription; -import de.neemann.digital.core.element.Keys; +import de.neemann.digital.core.element.*; import static de.neemann.digital.core.element.PinInfo.input; @@ -47,23 +44,14 @@ public class Out implements Element { /** * The seven segment display description */ - public static final ElementTypeDescription SEVENDESCRIPTION - = new ElementTypeDescription("Seven-Seg", - attributes -> { - return new Out(1, 1, 1, 1, 1, 1, 1, 1); - }, - input("a"), input("b"), input("c"), input("d"), input("e"), input("f"), input("g"), input("dp")) - .addAttribute(Keys.LABEL) - .addAttribute(Keys.COLOR); + public static final ElementTypeDescription SEVENDESCRIPTION = new SevenSegTypeDescription(); /** * The seven segment hex display description */ public static final ElementTypeDescription SEVENHEXDESCRIPTION = new ElementTypeDescription("Seven-Seg-Hex", - attributes -> { - return new Out(4, 1); - }, input("d"), input("dp")) + attributes -> new Out(4, 1), input("d"), input("dp")) .addAttribute(Keys.LABEL) .addAttribute(Keys.COLOR); @@ -112,4 +100,33 @@ public class Out implements Element { public void registerNodes(Model model) { model.addOutput(new Signal(label, value).setDescription(description)); } + + private final static class SevenSegTypeDescription extends ElementTypeDescription { + private SevenSegTypeDescription() { + super("Seven-Seg", attributes -> { + if (attributes.get(Keys.COMMON_CATHODE)) + return new Out(1, 1, 1, 1, 1, 1, 1, 1, 1); + else + return new Out(1, 1, 1, 1, 1, 1, 1, 1); + }); + addAttribute(Keys.LABEL); + addAttribute(Keys.COLOR); + addAttribute(Keys.COMMON_CATHODE); + addAttribute(Keys.LED_PERSISTENCE); + } + + @Override + public PinDescriptions getInputDescription(ElementAttributes attributes) throws NodeException { + if (attributes.get(Keys.COMMON_CATHODE)) { + return new PinDescriptions( + input("a"), input("b"), input("c"), + input("d"), input("e"), input("f"), + input("g"), input("dp"), input("cc")).setLangKey(getPinLangKey()); + } else + return new PinDescriptions( + input("a"), input("b"), input("c"), + input("d"), input("e"), input("f"), + input("g"), input("dp")).setLangKey(getPinLangKey()); + } + } } diff --git a/src/main/java/de/neemann/digital/draw/shapes/SevenSegShape.java b/src/main/java/de/neemann/digital/draw/shapes/SevenSegShape.java index e6cbd77e2..745efde5d 100644 --- a/src/main/java/de/neemann/digital/draw/shapes/SevenSegShape.java +++ b/src/main/java/de/neemann/digital/draw/shapes/SevenSegShape.java @@ -4,13 +4,17 @@ import de.neemann.digital.core.ObservableValue; import de.neemann.digital.core.ObservableValues; import de.neemann.digital.core.Observer; import de.neemann.digital.core.element.ElementAttributes; +import de.neemann.digital.core.element.Keys; import de.neemann.digital.core.element.PinDescriptions; import de.neemann.digital.draw.elements.IOState; import de.neemann.digital.draw.elements.Pin; import de.neemann.digital.draw.elements.Pins; +import de.neemann.digital.draw.graphics.Graphic; +import de.neemann.digital.draw.graphics.Style; import de.neemann.digital.draw.graphics.Vector; import static de.neemann.digital.draw.shapes.GenericShape.SIZE; +import static de.neemann.digital.draw.shapes.GenericShape.SIZE2; /** * A seven seg display with seven single controllable inputs @@ -19,8 +23,12 @@ import static de.neemann.digital.draw.shapes.GenericShape.SIZE; */ public class SevenSegShape extends SevenShape { private final PinDescriptions inputPins; + private final boolean commonCatode; + private final boolean persistence; + private final boolean[] data; private ObservableValues inputs; private Pins pins; + private ObservableValue ccin; /** * Creates a new instance @@ -32,6 +40,9 @@ public class SevenSegShape extends SevenShape { public SevenSegShape(ElementAttributes attr, PinDescriptions inputs, PinDescriptions outputs) { super(attr); this.inputPins = inputs; + commonCatode = attr.get(Keys.COMMON_CATHODE); + persistence = attr.get(Keys.LED_PERSISTENCE); + data = new boolean[8]; } @Override @@ -46,6 +57,8 @@ public class SevenSegShape extends SevenShape { pins.add(new Pin(new Vector(SIZE, SIZE * HEIGHT), inputPins.get(5))); pins.add(new Pin(new Vector(SIZE * 2, SIZE * HEIGHT), inputPins.get(6))); pins.add(new Pin(new Vector(SIZE * 3, SIZE * HEIGHT), inputPins.get(7))); + if (commonCatode) + pins.add(new Pin(new Vector(SIZE * 4, SIZE * HEIGHT), inputPins.get(8))); } return pins; } @@ -55,15 +68,35 @@ public class SevenSegShape extends SevenShape { inputs = ioState.getInputs(); for (ObservableValue o : inputs) o.addObserverToValue(guiObserver); + if (commonCatode) + ccin = inputs.get(8); return null; } + @Override + public void drawTo(Graphic graphic, boolean highLight) { + super.drawTo(graphic, highLight); + if (commonCatode) + graphic.drawLine( + new Vector(SIZE * 4 - SIZE2, SIZE * HEIGHT - 1), + new Vector(SIZE * 4, SIZE * HEIGHT - 1), Style.NORMAL); + } @Override protected boolean getStyle(int i) { if (inputs == null) return true; - else return inputs.get(i).getValueIgnoreBurn() > 0; + + if (persistence && commonCatode) { + if (!ccin.isHighZ() && !ccin.getBool()) + data[i] = inputs.get(i).getValueIgnoreBurn() > 0; + return data[i]; + } else { + if (commonCatode && (ccin.isHighZ() || ccin.getBool())) + return false; + + return inputs.get(i).getValueIgnoreBurn() > 0; + } } } diff --git a/src/main/resources/lang/lang_de.xml b/src/main/resources/lang/lang_de.xml index 4dc8459f3..ba4d8f8e7 100644 --- a/src/main/resources/lang/lang_de.xml +++ b/src/main/resources/lang/lang_de.xml @@ -258,6 +258,7 @@ Die gesammte Speichergröße beträgt damit damit dx*dy*2 Speicherworte.Dieser Eingang steuert die obere linke vertikale Linie. Dieser Eingang steuert die mittlere horizontale Linie. Dieser Eingang steuert den Dezimalpunkt. + Gemeinsame Kathode. Nur wenn hier eine Null anliegt, können die LEDs leuchten. Siebensegmentanzeige Hex Siebensegmentanzeige mit einem 4 Bit hexadezimalen Eingang. Der 4-Bit-Wert dieses Eingangs wird als Hex-Ziffer dargestellt. @@ -511,6 +512,13 @@ Zur Analyse können Sie die Schaltung im Gatterschrittmodus ausführen. Anzeigeformat der Ausdrücke. Relais ist ein Öffner Wenn gesetzt ist das Relais unbestromt geschlossen. + Gemeinsame Kathode + Wenn gesetzt hat die Anzeige einen Ausgang mit einer gemeinsamen Kathode. + Träges Auge + Die Schaltfrequenz am Bildschirm kann in der Simulation nicht so hoch werden, + dass das Auge kein Flimmern mehr wahrnimmt. Um dennoch das Flackern zu unterdrücken, können die LEDs auf + "nachleuchten" geschaltet werden. + Logisch Arithmetik FlipFlops diff --git a/src/main/resources/lang/lang_en.xml b/src/main/resources/lang/lang_en.xml index da7d4e1d4..7d95c8004 100644 --- a/src/main/resources/lang/lang_en.xml +++ b/src/main/resources/lang/lang_en.xml @@ -251,6 +251,7 @@ This input controls the upper, left, vertical line. This input controls the middle, horizontal line. This input controls the decimal point. + Common Cathode. To turn on the LEDs, this input needs to be low. Seven-Segment-Hex Display Seven Segment Display with a 4 bit input The value at this input is visualized at the display. @@ -497,6 +498,14 @@ To analyse you can run the circuit in single gate step mode. Screen format of expressions. Relay is normally closed. If set the relay is closed if the input is low. + Common Cathode + If selected the common cathode input is also simulated. + Slow Eye + It is not possible to increase the frequency so much that the flickering disappears. + With this option you can stabilize the display by keeping the LEDs on until the common cathode goes down again. + This simulates a frequency above the critical flicker fusion frequency. + + Logic Arithmetic FlipFlops