Echo typed keys on a TTY
The Keyboard and the TTY are a matched pair. Both have a clear input, a clock and an enable, and the Keyboard’s available output is exactly the signal the TTY wants as its write enable.
loc Logisim storesPorts as a table
| # | Port | Direction | Width | Offset from anchor |
|---|---|---|---|---|
| 1 | Clear | in | 1 | (20, 10) |
| 2 | Clock | in | 1 | (0, 0) |
| 3 | Read enable | in | 1 | (10, 10) |
| 4 | Available | out | 1 | (130, 10) |
| 5 | Data | out | 7 | (140, 10) |
loc Logisim storesPorts as a table
| # | Port | Direction | Width | Offset from anchor |
|---|---|---|---|---|
| 1 | Clear | in | 1 | (20, 10) |
| 2 | Clock | in | 1 | (0, 0) |
| 3 | Write enable | in | 1 | (10, 10) |
| 4 | Data | in | 7 | (0, -10) |
Place the parts
Put a Clock, a Keyboard and a TTY on the sheet (Input/Output library for the last two).
Wire the handshake
Send the same Clock to the Keyboard clock and to the TTY clock. Connect the Keyboard available output to the TTY write enable and to the Keyboard’s own read enable. Connect the Keyboard 7-bit data output to the TTY data input. Hold both clear inputs at 0.
Turn ticks on and type
Press Ctrl+K to switch ticks on, click the Keyboard component with the Poke tool so it has focus, then type. A character reaches the TTY about one clock period later.
Logisim-evolution 5.0.0 window at 2x zoom showing a Clock, a Keyboard component with a magenta focus ring and a grey TTY screen that displays the three typed characters, h, i and an exclamation mark.
What each port does
| Part | Port | Meaning, in our words |
|---|---|---|
| Keyboard | Clear | A 1 empties the buffer. |
| Keyboard | Clock | A trigger removes the front character if read enable is 1. |
| Keyboard | Read enable | 0 stops the clock from consuming characters. |
| Keyboard | Available | 1 while the buffer holds a character. |
| Keyboard | Data | ASCII code of the front character, 7 bits. |
| TTY | Clear | A 1 clears the screen. |
| TTY | Clock | A trigger adds the character on the data input. |
| TTY | Write enable | 0 stops the clock from adding characters. |
| TTY | Data | ASCII code of the next character, 7 bits. |
Keyboard and TTY attributes
| Part | Attribute | Default | Choices |
|---|---|---|---|
| Keyboard | Buffer Length | 32 | a number |
| Keyboard | Trigger | Rising Edge | Rising Edge, Falling Edge |
| TTY | Rows | 8 | a number |
| TTY | Columns | 32 | a number |
| TTY | Trigger | Rising Edge | Rising Edge, Falling Edge |
| TTY | Color | black | a colour |
| TTY | Background | transparent black | a colour |
Defaults read from the 5.0.0 jar (lab23). We did not test the limits of the number fields.
The data inputs are 7 bits wide, so only ASCII codes 0 to 127 are possible. In one run, typing a, b and Enter left ab on the first line and the cursor on the second, so Enter starts a new line. We did not test Backspace.
Print TTY text from the command line
The command-line --tty tty format sends the TTY component’s text to standard output, which is useful for autograders. Add halt so the run ends by itself. Our hello circuit prints five letters and stops:
$ java -jar logisim-evolution-5.0.0-all.jar --tty tty,halt circ-io-tty-hello.circ
HELLO
Describe this circuit
Components: Clock 1; Counter addr; ROM text; TTY tty; Constant 1; Constant 2; Output pin halt.
- Clock 1 connects to Counter addr, TTY tty (net clk).
- Counter addr connects to ROM text (net q), 8 bits wide.
- Counter addr connects to Output pin halt (net cy, halt).
- ROM text connects to TTY tty (net d), 8 bits wide.
- TTY tty connects to Constant 2.
- TTY tty connects to Constant 1.
Download circ-io-tty-hello.circ. It was saved by 5.0.0 and does not open in 2.7.1. The halt message goes to the error stream, so standard output holds only the text. A fuller guide to the format is in the command line page.
Common keyboard and TTY problems
- Nothing is printed. Write enable is 0, no clock reaches the TTY, or clear is held at 1.
- Characters print twice. Write enable stayed high for two triggers. Drive it from the Keyboard available output.
- The buffer empties by itself. The Keyboard clear input is wired to a floating or active signal. Tie it to a constant 0.
- Characters are missing. The buffer may be full. Raise Buffer Length; we did not test the full-buffer case.
LED matrix
The LED matrix component is named DotMatrix in the file. With the default Columns input format it has five inputs, each 7 bits wide, one per column.
loc Logisim storesPorts as a table
| # | Port | Direction | Width | Offset from anchor |
|---|---|---|---|---|
| 1 | in | in | 7 | (0, 0) |
| 2 | in | in | 7 | (10, 0) |
| 3 | in | in | 7 | (20, 0) |
| 4 | in | in | 7 | (30, 0) |
| 5 | in | in | 7 | (40, 0) |
In our test the five constants 0x7e, 0x11, 0x11, 0x11 and 0x7e drew a tall bar on each side joined by a middle bar. Bit 0 is the bottom row and bit 6 the top row.
A 5 by 7 LED matrix component in Logisim-evolution 5.0.0 drawn in green and grey, fed by five constants 0x7e, 0x11, 0x11, 0x11 and 0x7e shown below it.
Defaults we read: 5 columns, 7 rows, on colour green, off colour grey, Light Persistence 0 ticks, Dot Shape square (choices circle, square, cluster segment). Other input formats are Rows and Select. We did not test them or drive the matrix from a ROM. The ROM page shows how to store the pattern.
RGB Video
loc Logisim storesPorts as a table
| # | Port | Direction | Width | Offset from anchor |
|---|---|---|---|---|
| 1 | in | in | 1 | (0, 0) |
| 2 | in | in | 1 | (10, 0) |
| 3 | in | in | 1 | (20, 0) |
| 4 | in | in | 7 | (40, 0) |
| 5 | in | in | 7 | (50, 0) |
| 6 | in | in | 24 | (60, 0) |
The ports, in order, are reset, clock, write enable, X (7 bits), Y (7 bits) and colour (24 bits). The default colour model is 888 RGB (24 bit). The Color Model attribute also offers 555, 565, 444, 8-colour, Atari 2600, XTerm16, XTerm256, Grayscale and VGA256. Resolution defaults to 128 by 128 and offers 256x256, 320x240, 640x480, 960x540, 1024x768, 1280x720, 1920x1080 and Custom. Cursor, Reset Behavior and Scale are also attributes.
Joystick, buttons and switches
A Logisim sheet with a Button, a Joystick, an 8-way DIP switch, an RGB Video screen with one red pixel near its top left corner, and output pins showing their values.
| Part | Outputs | Behaviour we saw | Attributes we read |
|---|---|---|---|
| Button | one, 1 bit | 1 while the mouse is held on it, 0 after release | Logic level: active on press or passive |
| Joystick | two, x and y, 4 bits each | 1000 at rest; smaller values toward the top left; returns to the centre on release | Bit Width 2 to 5 |
| DIP Switch | 8 one-bit outputs by default | a click toggles a switch and it stays in position | Number of Switch |
| Matrix Keypad | four row inputs, four column outputs | holding a key connects its row input to its column output; unpressed columns stay undefined | Operating mode: raw or Pmod KYPD |
Matrix Keypad
The keypad has four inputs along the bottom edge and four outputs on the right edge. The inputs are rows, left to right for the keypad rows from top to bottom, and the outputs are columns, top to bottom for the keypad columns from left to right. Holding a key connects the input of its row to the output of its column, so a circuit scans it like a real keypad: drive one row, read the four columns. A column with no key held on a driven row reads undefined (U), not 0, so add a pull-down or treat U as no key.
The Matrix Keypad poke panel: four row input pins below the keypad, four column output pins on the right. With the second row input set to 1 and key 5 held with the mouse, the second column output shows 1 and the other three show U for undefined.
In Logisim 2.7.1 the same two parts behaved the same way (F133): the Button read 1 while held and 0 after release, and the Joystick read 1000 on both outputs at rest, 0100 on both with the knob pulled toward the top left, and 1100 toward the bottom right, then returned to 1000 on release.
A Logisim 2.7.1 window cut down to the Joystick with its knob toward the top left and the two 4-bit output pins JX and JY both showing 0100.
The Button is momentary and the DIP Switch keeps its position. We saw the Joystick values only roughly (about 2 for the top left and 8 at rest); read the pins yourself for exact numbers. For a plain on/off input see the pins page.
Version differences
| Feature | 2.7.1 | 5.0.0 |
|---|---|---|
| Keyboard, TTY, LED matrix | 2.7.1: yessame port layout in our data | 5.0.0: yestested (F116) |
| Button and Joystick | 2.7.1: yespoked (F133) | 5.0.0: yespoked (F125) |
| RGB Video, DIP Switch, Matrix Keypad | 2.7.1: nonot in 2.7.1 | 5.0.0: yesDIP switch and video (F125), keypad (F132) |
On a real board these parts are mapped in the FPGA guide window. See also all components and the 8-bit CPU project, which uses a TTY for output.