thecodingidiot.com

Digital BasicsBinary and LEDs

Binary and LEDs

Before wiring any logic chip, understand what a 0 and a 1 mean in a physical circuit — and what counting in binary looks like when each bit is a separate LED.

High and low

A digital circuit operates with two voltage levels:

  • HIGH — a voltage close to the supply voltage. In a 5V circuit, anything above roughly 3V is read as a logical 1.
  • LOW — a voltage close to ground. Anything below roughly 1.0V is read as a logical 0.

The exact thresholds depend on the chip family. For 74HC-series chips at 5V, the guaranteed output levels are ≥4.4V for HIGH and ≤0.1V for LOW — well away from the ambiguous middle. A signal in the middle is not a valid digital level and causes unpredictable behaviour.

An LED gives a visual representation of these levels. Connect the anode (longer leg) of a LED through a 1kΩ resistor to a wire. Connect the cathode (shorter leg) to the ground rail. When the wire is HIGH (connected to +5V), current flows through the resistor and LED — it lights. When the wire is LOW (connected to GND), no current flows — it is off.

+5V ──[wire]──[1kΩ]──[LED anode → cathode]── GND

Wire one LED this way and touch the input wire to the +5V rail: the LED lights. Touch it to GND: the LED goes off. That is a one-bit display.

The bit

One LED represents one bit. A lit LED is a 1. An unlit LED is a 0.

Four LEDs in a row represent a four-bit number — the four bits of a nibble. Conventionally the leftmost LED is the most significant bit (bit 3, value 8) and the rightmost is the least significant bit (bit 0, value 1).

bit 3  bit 2  bit 1  bit 0
 [8]    [4]    [2]    [1]

The value of any combination is the sum of the bit values where the LED is lit. Both bit 3 and bit 1 lit means 8 + 2 = 10.

Wiring four LEDs

Wire four LEDs side by side. Each LED's anode connects through its own 1kΩ resistor to a separate input wire. All four cathodes connect to the ground rail.

bit 3           bit 2           bit 1           bit 0
 wire3           wire2           wire1           wire0
  │               │               │               │
[1kΩ]           [1kΩ]           [1kΩ]           [1kΩ]
  │               │               │               │
[LED]           [LED]           [LED]           [LED]
  │               │               │               │
 GND             GND             GND             GND

Counting to 15

With four input wires and four LEDs, work through every value from 0 to 15 by connecting each wire to either +5V (bit = 1) or GND (bit = 0).

DecimalBit 3Bit 2Bit 1Bit 0
00000
10001
20010
30011
40100
50101
60110
70111
81000
91001
101010
111011
121100
131101
141110
151111

Set each row in order. Verify that the correct LEDs light. At decimal 15 (binary 1111) all four should be lit.

When the 6502 places an address on its address bus, it is doing exactly this across sixteen lines simultaneously — A0 through A15. The address $8000 in binary is 1000 0000 0000 0000: A15 is high, A14 through A0 are low. A15 being high is what the address decode circuit will detect to select the ROM.