home *** CD-ROM | disk | FTP | other *** search
/ The Net: Ultimate Internet Guide / WWLCD1.ISO / pc / java / ed8n1t2i / bcdtosevensegdecoder.java < prev    next >
Encoding:
Java Source  |  1996-08-14  |  6.0 KB  |  137 lines

  1. //****************************************************************************
  2. // ---- version information ----
  3. //
  4. // BCDToSevenSegDecoder.java   v 1.00 b1
  5. // Written by:                 I. van Rienen / E-mail ivr@bart.nl
  6. // URL:                        http://www/bart.nl/~ivr
  7. // Initial release:
  8. // Released in public domain:
  9. //
  10. // ---- Description ----
  11. // Java class containing methods for BCD to 7-seg decoder
  12. //
  13. // This program and the Java source is in the public domain.
  14. // Permission to use, copy, modify, and distribute this software
  15. // and its documentation for NON-COMMERCIAL purposes and
  16. // without fee is hereby granted.
  17. //
  18. //    Copyright 1996
  19. //
  20. //    Iwan van Rienen
  21. //    Joan Maetsuyckerstr. 145
  22. //    2593 ZG  The Hague
  23. //    The Netherlands
  24. //
  25. // I am not responsible for any bugs in this program and
  26. // possible damage to hard- or software when using this program.
  27. //****************************************************************************
  28. import java.applet.Applet;
  29. import java.awt.*;
  30. import java.util.Vector;
  31.  
  32. class BCDToSevenSegDecoder extends IntegratedCircuit {
  33.     static final int LE = 0;
  34.     static final int BI = 1;
  35.     static final int LT = 2;
  36.     static final int A = 3;
  37.     static final int B = 4;
  38.     static final int C = 5;
  39.     static final int D = 6;
  40.  
  41.     static final int a = 0;
  42.     static final int b = 1;
  43.     static final int c = 2;
  44.     static final int d = 3;
  45.     static final int e = 4;
  46.     static final int f = 5;
  47.     static final int g = 6;
  48.     static final int SegLev[][] = {
  49.         { 5, 5, 5, 5, 5, 5, 0} ,        // 0
  50.         { 0, 5, 5, 0, 0, 0, 0} ,        // 1
  51.         { 5, 5, 0, 5, 5, 0, 5} ,        // 2
  52.         { 5, 5, 5, 5, 0, 0, 5} ,        // 3
  53.         { 0, 5, 5, 0, 0, 5, 5} ,        // 4
  54.         { 5, 0, 5, 5, 0, 5, 5} ,        // 5
  55.         { 5, 0, 5, 5, 5, 5, 5} ,        // 6
  56.         { 5, 5, 5, 0, 0, 0, 0} ,        // 7
  57.         { 5, 5, 5, 5, 5, 5, 5} ,        // 8
  58.         { 5, 5, 5, 5, 0, 5, 5} ,        // 9
  59.         { 5, 5, 5, 0, 5, 5, 5} ,        // A
  60.         { 0, 0, 5, 5, 5, 5, 5} ,        // B
  61.         { 5, 0, 0, 5, 5, 5, 0} ,        // C
  62.         { 0, 5, 5, 5, 5, 0, 5} ,        // D
  63.         { 5, 0, 0, 5, 5, 5, 5} ,        // E
  64.         { 5, 0, 0, 0, 5, 5, 5}   };     // F
  65.     int ActVal = 0;
  66.  
  67. //----------------------------------------------------------------------------
  68. // The constructor of a new BCD to Seven-Segment decoder
  69. //----------------------------------------------------------------------------
  70.     public BCDToSevenSegDecoder(Pin PinGrid[][], int x, int y) {
  71.         super (x, y, 10, 13 , 3, 1, 4, 11, 7, 7);      // x,y,w,h HitBox x,y,w,h,I,O
  72.         IPin[LE] = new InputPin("LE", 1, 2, 2, 0, 0, 0, ComponentPin.PIN_NEGATIVE); // name, x, y, w, h, inv
  73.         IPin[BI] = new InputPin("BI", 1, 4, 2, 0, 0, 0, ComponentPin.PIN_NEGATIVE); // name, x, y, w, h, inv
  74.         IPin[LT] = new InputPin("LT", 1, 6, 2, 0, 0, 0, ComponentPin.PIN_NEGATIVE); // name, x, y, w, h, inv
  75.         IPin[A] = new InputPin("A", 1, 8, 2, 0, 0, 0, ComponentPin.PIN_NORMAL); // name, x, y, w, h, inv
  76.         IPin[B] = new InputPin("B", 1, 9, 2, 0, 0, 0, ComponentPin.PIN_NORMAL); // name, x, y, w, h, inv
  77.         IPin[C] = new InputPin("C", 1, 10, 2, 0, 0, 0, ComponentPin.PIN_NORMAL); // name, x, y, w, h, inv
  78.         IPin[D] = new InputPin("D", 1, 11, 2, 0, 0, 0, ComponentPin.PIN_NORMAL); // name, x, y, w, h, inv
  79.  
  80.         OPin[a] = new OutputPin("a", 9, 3, -2, 0, 0, 0, ComponentPin.PIN_NORMAL); // name, x, y, w, h, inv
  81.         OPin[b] = new OutputPin("b", 9, 4, -2, 0, 0, 0, ComponentPin.PIN_NORMAL); // name, x, y, w, h, inv
  82.         OPin[c] = new OutputPin("c", 9, 5, -2, 0, 0, 0, ComponentPin.PIN_NORMAL); // name, x, y, w, h, inv
  83.         OPin[d] = new OutputPin("d", 9, 6, -2, 0, 0, 0, ComponentPin.PIN_NORMAL); // name, x, y, w, h, inv
  84.         OPin[e] = new OutputPin("e", 9, 7, -2, 0, 0, 0, ComponentPin.PIN_NORMAL); // name, x, y, w, h, inv
  85.         OPin[f] = new OutputPin("f", 9, 8, -2, 0, 0, 0, ComponentPin.PIN_NORMAL); // name, x, y, w, h, inv
  86.         OPin[g] = new OutputPin("g", 9, 9, -2, 0, 0, 0, ComponentPin.PIN_NORMAL); // name, x, y, w, h, inv
  87.  
  88.         ComponentName = "BCD to 7-segment decoder";
  89.         ClassName = "BCDToSevenSegDecoder";
  90.         RegisterPins (PinGrid, x, y);
  91.     }
  92.  
  93. //----------------------------------------------------------------------------
  94. // The constructor of a new decoder, which is a copy of CompToCopy
  95. //----------------------------------------------------------------------------
  96.     public BCDToSevenSegDecoder (ElectronicComponent CompToCopy, int xo, int yo) {
  97.         super (CompToCopy, xo, yo);
  98.     }
  99.  
  100. //----------------------------------------------------------------------------
  101. // Method for copying this component.
  102. //----------------------------------------------------------------------------
  103.     public ElectronicComponent Copy(int xo, int yo) {
  104.         BCDToSevenSegDecoder NewComponent = new BCDToSevenSegDecoder(this, xo, yo);
  105.         return NewComponent;
  106.     }
  107.  
  108. //----------------------------------------------------------------------------
  109. // Here is the code that's simulating the component
  110. //----------------------------------------------------------------------------
  111.     public void SimulateLogic() {
  112.         int ix;
  113.         if (IPin[LT].getLevel() == 5) { // Lamp test
  114.             for (ix = 0; ix < 7; ix++) {
  115.                 OPin[ix].Level = 5;
  116.             }
  117.             return;
  118.         }
  119.         if (IPin[BI].getLevel() == 5) { // Blank input
  120.             for (ix = 0; ix < 7; ix++) {
  121.                 OPin[ix].Level = 0;
  122.             }
  123.             return;
  124.         }
  125.         if (IPin[LE].getLevel() == 5) { // Latch enable
  126.             ActVal = 0;
  127.             if (IPin[A].getLevel() == 5) ActVal += 1;
  128.             if (IPin[B].getLevel() == 5) ActVal += 2;
  129.             if (IPin[C].getLevel() == 5) ActVal += 4;
  130.             if (IPin[D].getLevel() == 5) ActVal += 8;
  131.         }
  132.  
  133.         for (ix = 0; ix < 7; ix++) {
  134.             OPin[ix].Level = SegLev[ActVal] [ix];
  135.         }
  136.     }
  137. }