by [Theo Verelst] A latch is a memory, composed of a number of bits, which either feeds information through from its input pins to its corresponding output pins, or stores the last information on its output pins, no matter what the inputs do, under the control of a clock signal. It is a digital circuit which is essential in computer circuits, and it is used in the page [LED display driven by the parallel port under tcl control], where it is interesting to use the Tk canvas based [bwise] to make a circuit diagram which is interactive, simulates block behaviour, and can even on block and pin level communicate with the parallel port hardware. First on this page lets start making a block with 8 input and 8 output bits (0 or 1), and a clock signal input, assuming bwise has been started. newproc {} latch {i0 i1 i2 i3 i4 i5 i6 i7 cl} {o0 o1 o2 o3 o4 o5 o6 o7} Because the pins carry signals which are either 0 or 1 in this case, we can use the space inside the block to show their value. So we make text fields, linked with the block name by common first tag (so we can keep moving the block around) foreach i [tag_and {latch pin typeout}] { set c [lrange [$mc coords [tag_and "latch $i pin"]] 2 3] ; $mc create text [expr [lindex $c 0] -3] [lindex $c 1] -anchor se -text X -tag "latch added value [lindex [$mc itemcget $i -tag] 3]" } foreach i [tag_and {latch pin typein}] { set c [lrange [$mc coords [tag_and "latch $i pin"]] 2 3] ; $mc create text [expr [lindex $c 0] +3] [lindex $c 1] -anchor sw -text X -tag "latch added value [lindex [$mc itemcget $i -tag] 3]" } Now we can update all 'value' tagged text items from their corresponding pin variables by: foreach i [tag_and {latch value}] {$mc itemco $i -text "[set latch.[lindex [$mc itemcget $i -tag] 3]]"} We can bind a procedure to the block value texts so that when we click on them, their value inverts: $mc bind value { global mc; set c [$mc find withtag current] ; set d [lindex [$mc itemcget $c -tag] 3]; set e [lindex [$mc itemcget $c -tag] 0]; if {[set $e.$d] == "1"} {set $e.$d 0} {set $e.$d 1}; $mc itemco $c -text [set $e.$d] ; } The texts are initialized with 'X' to indicate undefined, when clicked, and X becomes a 1, when clicked again, the 1 becomes 0. After clicking, the pin-corresponding variables, easily reachable by on the yellow block using the right-mouse --> data menu, which displays all of them in a list of editable fields, are automatically updated to the inverted value. The other way around, the update sweep from above is needed. We still need to supply the block function for this latch block, which we could have done by specifying the first argument to the newproc procedure, but can always update manually: set latch.bfunc {if {${latch.cl} == 1} {for {set i 0} {$i<8} {incr i} {set latch.o$i [set latch.i$i]}}} At this moment this test block function can be used in a bwise canvas network which is run either by Run or Funprop (see block right mouse button menu) methods, and pass its input bits to the output bits when it is Eval-ed with a '1' clock signal, and remember its values otherwise.