Template:Mcrs diagrams
红石电路与现实生活中的数字电路(基于布尔逻辑代数)基本可以等同看待。如果您熟悉高等教育中的数字电路与初等计算机科学的知识的话,本篇目对您来说将较为容易理解。
计算机
在Minecraft中,一些游戏内的系统在计算机科学中与图灵机等价——也就是说这样您可以建构信息处理的装置。这些系统包括:水,沙子,矿车,活塞与红石。
这些系统中只有红石是特别为信息处理而设计的,主要以红石信号的方式来表示。
红石与电力类似,具有高适应性与较快的切换速度。就像在现实世界中电力取代了蒸汽动力成为高科技的基石一样,前述的这些特性使红石力压其他机械系统,成为Minecraft中最具有科技含量的部分。
现代数字电路与红石工程在复杂信息处理的应用时。都被简化为抽象的从基本到复杂的多层次结构。
第一层是最基本的组件:红石粉、红石火把、红石中继器、活塞、按钮、拉杆与压力板等所有与红石信号相关的方块。
第二层是二进制逻辑门;他们是能够处理有限位(一般是1-3位)的混合装置。
第三层是由逻辑门组合而成的高阶组件。这些组件用于处理模式化的位数据,一般能够将其编码为更加易读的数字。例如数学加法器,组合锁具,寄存器等。
第四层,也是最后一层,是由一系列的高阶组件组合成的功能型计算机系统,通常能够在不需要人工维护的情况下处理任意数据。
一个8位寄存器,属于第三层结构
半加器
逻辑门:同或,蕴含
红石火把数量:12
红石粉数量:7
方块数量:19
尺寸:5X4X4
这个半加器能够输出两个一位二进制数的和。结果位输出到输出端S(英文Sum,加法和之意)。如果两个数字都是1,那么会产生进位1到输出端C(Carry,进位之意)(C会变为0)。这个半加器可以被修改为具有同相输出的C端,但图中这种结构在全加器链中可以照搬。
注:由于红石线的新特性,本结构已经失效!
全加器(1位)
逻辑门:同或(2),蕴含,非,或,与
红石火把数量:16
红石粉数量:32
方块数量:48
尺寸:从上到下6X12X5,包括输入/输出端。
这个全加器能够将两个一位二进制数与前一个加法器的进位C相加(事实上是C而不是C,第一层的左下部),产生一个和(S端)和进位(事实上是C而不是C)。
如果要改造为减法器,把其中一个二进制输入取反(第一个或第二个数)即可。如果输入被取反,输出也是反向的。在现实世界中的计算机里,二进制带符号数的第一位(也被称为“标志位”)决定了该二进制数的正负,如果你把这个特性(应用相同的反相规则)引入,你就可以得知该数字是负数,还仅仅只是一个较大的数字。
当使用上述的逻辑门时,注意输入与输出,您可能会对为什么这里使用了如此多的反相信号而不是同相信号有疑问。这个全加器使用了比异或门更能实现压缩的同或门,同理,蕴含门比与门更为压缩。因此如果您想压缩全加器的体积,必须使用反相信号。如果用能够表示2层方格的符号来表示,图像将十分复杂,因此我们将每一层都单独用图表表示了出来,而且也方便您分层次地建造。
活塞全加器
红石火把数量:3
粘性活塞数量:2
红石中继器数量:8
红石粉数量:16
方块数量:7
交替全加器
进位输入与输出端对称,这样您能够方便的压缩并组合多个这样的单元。
红石火把数量:14
红石线数量:15
尺寸:5x6x3
4位加法器
注意!重要性最低的那一位数就是图表中的最左边那位(即“个位”)。这里之所以标明,是为了向您清楚地说明全加器比起半加器的功能优势——半加器无法处理比其低一数位的进位。如果您想依据一般的使用习惯把个位放在右边,那么将图表左右镜像处理即可。
逻辑门:同或(7),蕴含(4),非(4),或(3),与(3)
红石火把数量:56
红石粉数量:108
方块数量:164
尺寸:23X12X5
这个加法器能够将两个四位二进制数相加(A与B),产生每一位数的和(S)与整个和的进位(C,相当于第五位)。和的位数顺序与加数的顺序相同,这也就是说,最左侧的S是和的最低位。这个4位加法器仅仅是一个全加器链的示例,您可以通过同样的构造来建造具有更多位数加法或减法能力的计算单元。
逻辑单元(2-4译码器)
在电路中,有时候您可能需要建造能够依据输入来选择输出的逻辑单元。这样的逻辑单元能够用于更复杂的电路中,比如说算术逻辑单元(ALU)。下面介绍的逻辑单元又被称为2-4译码器。
这是一个2位逻辑单元,依输入不同可以有4种状态。
输出端在最上面一行,依照11、00、01、10的顺序排列(输入端顺序为上侧的是第一位,下侧第二位)。
下面是另一种采用格雷码的简化版本。输出端为顶部那行末端的红石火把。本设计能够被扩展到任意位,但会受到电路延时的限制。相对地,输出排序为11、01、00、10。
二进制转换为八进制(3-8译码器)
3位二进制转换为1位八进制
这个装置是一系列逻辑门的组合,分为8部分。当组合起来时能够将一个3位二进制数输入转换为一位八进制数输出,功能等同于3-8译码器。由于其最大占地面积不过5x5x3,所以有很强的适应性。
右图的每一部分都可以将输入端连接到共同的输入源,但建议您在每一个输入端都加一个反相器以使在该电路与其他电路协同工作时,输入端保持独立性。
某些部分也可以作为三态缓冲器使用,或至少您能够方便地将其改造为三态缓冲器。
下表与右上图的8部分一一对应。
| 对应八进制数字 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
|---|---|---|---|---|---|---|---|---|
| 尺寸 | 5x3x2 | 5x3x3 | 5x5x3 | 5x5x3 | 5X3X3 | 5x4x3 | 5x5x3 | 5x5x3 |
| 红石火把数量 | 1 | 2 | 2 | 3 | 2 | 3 | 3 | 4 |
| 红石粉数量 | 7 | 7 | 12 | 10 | 7 | 7 | 10 | 10 |
二进制转换为十进制/十六进制
4Bit Binary to Decimal/HexaDecimal gates.
A series of gates that convert a 4bit binary input from inputs into a decimal or HexaDecimal output from 0-9(if you are using Decimal) or 0-F(if you are using HexaDecimal). Useful in many ways as they are compact 3x5x2 at the largest.
These can be linked in a series from one input source but it is recommended to place an inverter before each input into the circuit to keep them isolated from interacting with the other circuits since some drive a combination of High and Low current.
Following the image, the first input is the second Lever on the right. The second input is the first Lever on the right. The third is the first lever on the left. The fourth, and last, input is the second Lever on the left.
| Number | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | A | B | C | D | E | F |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Size | 3x3x2 | 3x4x2 | 3x4x2 | 3x4x2 | 3x4x2 | 3x5x2 | 3x5x2 | 3x5x2 | 3x4x2 | 3x5x2 | 3x5x2 | 3x5x2 | 3x5x2 | 3x5x2 | 3x5x2 | 3x5x2 |
| Torches | 1 | 2 | 2 | 3 | 2 | 3 | 3 | 4 | 2 | 3 | 3 | 4 | 3 | 4 | 4 | 5 |
| Redstone | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 |
十六进制转换为二进制
You also can convert a Hexadecimal signal to a 4bit-binary signal. Here you don't need any gates, except separating ORs. Therefore you have to put the input trough a block. From this put lines trough the bit lines. And separate these from input via (Not-Not)-gate or a diode. The most suitable point to separate is directly after the point you differentiate the input trough the output lines. You have to separate these lines, in order that the bit-illustration will be correct.
| Number | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | A | B | C | D | E | F |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 4-bit | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
| 3-bit | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 1 |
| 2-bit | 0 | 0 | 1 | 1 | 0 | 0 | 1 | 1 | 0 | 0 | 1 | 1 | 0 | 0 | 1 | 1 |
| 1-bit | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 1 |
Now you got the 4-bit converted signal in the four lines. To get a Octal2Binary-MUXer, just ignore the entries, where the 4-bit-line is 1.
范例
Logic for a 3-digit key log, with digits 0-9. It's order-sensitive
The example on the right uses ORs (>=1), XNORs (=), RS-NOR latches (SR) and some delays (dt*). For the XNORs I would prefer the C-design.
The example on the right uses a 4-bit design, so you can handle a hexa-decimal key. So you can use 15 various digits, [1,F] or [0,E]. You only can use 15, because the state (0)h == (0000)2 won't activate the system. If you want to handle 16 states, you edit the logic, to interact for a 5-bit input, where the 5th bit represents the (0)h state.
In the following we'll use (0)h := (1111)2. And for [1,9] the MUX-table upon. So the key uses decimal digits. Therefore we have to mux the used buttons to binary data. Here look trough the first two columns. The first represents the input-digit in (hexa)decimal, the second represents the input-digit in binary code. Here you can add also buttons for [A,E], but I disclaimed them preferring a better arranging. The /b1\-box outputs the first bit, the /b2\-box the second, and so on.
Now you see Key[i] with i=1..3, here you set the key you want to use. The first output of them is the 1-bit, the second the 2-bit and so on. You can set your key here with levers in binary-encryption. Use here the MUX-table upon, and for (0)h := (1111)2. If we enter the first digit, we have to compare the bits by pairs (b1=b1, b2=b2, b3=b3, b4=b4). If every comparison is correct, we set the state, that the first digit is correct.
Therefore we combine (((b1=b1 & b2=b2) & b3=b3) & b4=b4) =: (b*=b*). In minecraft we have to use four ANDs like the left handside. Now we save the status to the RS-latch /A\. The comparison works the same way for Key[2], and Key[3].
Now we have to make sure, that the state will be erased, if the following digit is wrong. Therefore we handle a key-press-event (--/b1 OR b2 OR b3 OR b4\--/dt-\--/dt-\--). Search the diagram for the three blocks near "dt-". Here we look, if any key is pressed, and we forward the event with a minor delay. For resetting /A\, if the second digit is wrong, we combine (key pressed) & (not B). It means: any key is pressed and the second digit of the key is entered false. Therewith /A\ will be not reseted, if we enter the first digit, /A\ only should be reseted, if /A\ is already active. So we combine (B* & A) =: (AB*). /AB*\ now resets the memory-cell /A\, if the second digit is entered false and the first key has been already entered. The major delay /dt+\ must be used, because /A\ resets itself, if we press the digit-button too long. To prevent this failure for a little bit, we use the delay /dt+\. The OR after /AB*\ is used, for manually resetting, i.e. by a pressure plate.
Now we copy the whole reset-circuit for Key[2]. The only changes are, that the manually reset comes from (not A) and the auto-reset (wrong digit after), comes from (C). The manual reset from A prevents B to be activated, if the first digit is not entered. So this line makes sure, that our key is order-sensitive.
The question is, why we use the minor-delay-blocks /dt-\. Visualize /A\ is on. Now we enter a correct second digit. So B will be on, and (not B) is off. But while (not B) is still on, the key-pressed-event is working yet, so A will be reseted, but it shouldn't. With the /dt-\-blocks, we give /B\ the chance to act, before key-pressed-event is activated.
For /C\ the reset-event is only the manual-reset-line, from B. So it is prevented to be activated, before /B\ is true. And it will be deactivated, when a pressure-plate resets /A\ and /B\.
pros and cons:
| + | you can change the key in every digit, without changing the circuit itself. |
| + | you can extend the key by any amount of digits, by copying the comparison-circuit. Dependencies from previous output only. |
| + | you can decrease the amount of digits by one by setting any digit (except the last) to (0000)b. |
| + | you can open the door permanently by setting the last digit to (0000)b |
| - | the bar to set the key will be get the bigger, the longer the key you want to be. The hard-coded key-setting is a compromise for a pretty smaller circuit, when using not too long keys. If you want to use very long keys, you also should softcode the key-setting. But mention, in fact the key-setting-input will be very small, but the circuit will be much more bigger, than using hard-coded key-setting. |
Not really a con: in this circuit the following happens with maybe the code 311: 3 pressed, A activated; 1 pressed, B activated, C activated. To prevent this, only set a delay with a repeater between (not A) and (reset B). So the following won't be activated with the actual digit.
If you fix this, the circuit have the following skill, depending on key-length. ( ||digit|| = 2n-1, possibilities: ||digit||Length )
| Length | 1 | 2 | 3 | 4 | 5 |
|---|---|---|---|---|---|
| 2 bit | 3 | 9 | 27 | 81 | 243 |
| 3 bit | 7 | 49 | 343 | 2.401 | 16.807 |
| 4 bit | 15 | 225 | 3.375 | 50.625 | 759.375 |
| 5 bit | 31 | 961 | 29.791 | 923.521 | 28.629.151 |
杂项
对顺序不敏感的组合锁具
A door that opens when a certain combination of buttons/levers are on.
(Note: A moderate understanding of logic gates is needed for this device.)
Combination Lock Tutorial(easy to follow)
RS或非锁具
Connect a series of buttons to the S-input of RS Latches. Feed the Q or Q (choose which one for each latch to set the combination) outputs of the RS Latches into a series of AND gates, and connect the final output to an iron door. Finally, connect a single button to all the R-inputs of the RS Latches. The combination is configured by using either Q or Q for each button (Q means that the button would need to be pressed, Q don't press) Example:
With the automated reset it causes the correct combo to cause a pulse instead of a "always on" until reset.
与门锁具
The AND based combo lock uses switches and NOT gate inverters instead of the RSNOR latches in the previous design. This makes for a simpler design but becomes less dynamic in complicated systems and it also lacks an automated reset. The AND design is configured by adding inverters to the switches.
Example:
或门锁具
The OR combo lock is actually an AND combo lock without unnecessary repeaters, override lever and last inverter. Output is off when the code is correct.
Due to its compact size and fast response time, this combination lock is also ideal for use as an address decoder in the construction of addressable memory (RAM)
Design A. Code is set by torches on inputs (1001):
It is possible to remove the spacing between the levers by replacing redstone wire behind the levers with delay 1 repeaters.
You can expand on this by creating a new level on top of the first and using the same principle as the first level, keep creating them.
Design B. Code is set by inverters in the blue area (001001):
N - number of inputs. K - number of 1's in code.
| Design | A | B |
|---|---|---|
| Size | 2N-1x3x1 | Nx6x2 |
| Torches | K | 2N-K |
| Redstone | 3N-K-1 | 2.5N + 2K |
分类设备
This is a device which sorts the inputs, putting 1's at the bottom and 0's at the top.
In effect counting how many 1s and how many 0s there are.
The diagram is designed so that it is easily expandable, as shown in the diagram. The bright squares shows how to expand it, and also where the in- and outputs are.
Truth table for a three-bit sorting device:
| A | B | C | 1 | 2 | 3 |
|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0 |
| 1 | 0 | 0 | 1 | 0 | 0 |
| 0 | 1 | 0 | 1 | 0 | 0 |
| 0 | 0 | 1 | 1 | 0 | 0 |
| 1 | 1 | 0 | 1 | 1 | 0 |
| 0 | 1 | 1 | 1 | 1 | 0 |
| 1 | 0 | 1 | 1 | 1 | 0 |
| 1 | 1 | 1 | 1 | 1 | 1 |
顺序敏感的RS或非锁具
A door that opens when buttons are pressed in certain order.
(Note: A moderate understanding of logic gates is needed for this device.)
Make a series of buttons, and connect only one to an RSNOR latch. Then connect both the RSNOR latch and a second button to an AND Gate, which feeds to another RSNOR latch. Do this continually until you have either filled all of the buttons or are satisfied with the lock. Connect the final RSNOR latch to a separate AND Gate with a signal from an enter button. Feed that to the output RSNOR latch. Then connect any of the left-over buttons to the enter button and send reset signals to all of the RSNOR latches. A pressure plate next to a door can reset the door. This type of lock has severe limitations its security. For example, not all the buttons could be used in the pin or there would be nothing to reset the system.
For a lock that can have a combination of any size, using all the buttons, and still have a wrong entry reset the system, you need a different way for it to reset. To construct this, hook up a panel of buttons (any number, but four or more is preferred) to a parallel series of adjacent repeaters. Invert as necessary so that all the repeaters are powered and are unpowered by the press of the corresponding button. These repeaters power a row of blocks. On top of the blocks, place a torch corresponding to the incorrect buttons for the fist number in the PIN. For the correct button/number, place dust under the powered block which leads to a RS NOR Latch. Place a row of blocks above the torches for the incorrect buttons, with redstone dust on top. Then connect this dust to the reset of the first RS NOR Latch. Only the correct button will set the RS NOR Latch and all others will reset it. Connect the output of the RS NOR LATCH to half of an AND gate. After the first row of blocks with the reset torches, place another row of repeaters and another row of blocks. Again place torches for the incorrect buttons and dust under the correct button's line. Power will be fed from the buttons through the rows of repeaters and blocks for as many rows as there are digits in the PIN number. Connect the dust from the correct button to the other half of the AND gate coming from the first RS NOR Latch. Only if the two conditions are met, that the first button was pushed correctly, setting the first RS NOR Latch, and the second button is pushed correctly will the AND gate send a signal to set the second RS NOR Latch. Again, connect a reset line from the incorrect button's torches to the reset of the second RS NOR Latch. NOTE: Delay the reset signals by one full repeater to give time for the next RS NOR Latch to be set before the reset happens. Continue building the array in the same manner until you reach the desired number of digits. In operation, when a button is hit, each RS NOR Latch checks (through the AND gate) to see if the previous RS NOR Latch is set, and the correct button for this RS NOR Latch has been pushed. Only when the correct buttons are pressed in order, will the signal progress through the conditional RS NOR Latches to the end. Connect the output of the last RS NOR Latch to a door and attach a line to a pressure plate inside the door to reset the last RS NOR Latch. See the video demonstration linked below. (Where?) (Yes where? A video would be very helpful)







