Lesson 1. Logic in packages: 74HC00, 02, 04, 08, 32

In pictures

After this lesson the library has five real chips — with the same pin names as in the datasheet — and an alarm runs on them: open the door while the alarm is armed — the alarm lights up and the buzzer sounds, and the alarm stays on until someone presses Reset.


1.1. The idea: a chip is a package with gates

Wozniak built the Apple I not from separate gates but from 74-series chips: one package holds four or six identical gates. The package has 14 pins, each with a number and a name:

  • 1A, 1B are the inputs of the first gate, 1Y is its output; then 2A, 2B, 2Y and so on up to the fourth;
  • pin 7 is GND, pin 14 is VCC: power. Our power is shared by all chips, so these pins are not there.

The letters in the name are the family: HC are modern CMOS chips. Inside they have exactly what we build from transistors: P and N pairs. The digits say what is inside: 00 — NAND, 02 — NOR, 04 — NOT, 08 — AND, 32 — OR.

1 1AVCC 142 1B4B 133 1Y4A 124 2A4Y 115 2B3B 106 2Y3A 97 GND3Y 8pins 7 and 14 are power: our VCC and GND are shared, the chip has no such pins
74HC00 inside: four NAND gates in one package. Each gate has its own three pins (A, B, Y); the number before the name is the gate number. Pins are numbered from the notch counter-clockwise: 1–7 on the left top to bottom, 8–14 on the right bottom to top.
74HC024 × NOR11Y14VCC21A134Y31B124B42Y114A52A103Y62B93B7GND83A74HC046 × NOT11A14VCC21Y136A32A126Y42Y115A53A105Y63Y94A7GND84Y
The pins of 74HC02 and 74HC04 are placed differently from 74HC00: in 74HC02 the output comes first (1Y, 1A, 1B), 74HC04 has six "input — output" pairs. 74HC08, 74HC32 and 74HC86 have exactly the 74HC00 pins. A bar over a name in the pictures means "active 0"; in the simulator the name is written without the bar.

1.2. The idea: free inputs go to ground

On a board often only one gate of four is used. The inputs of the others must not be left in the air: a CMOS input has no level of its own, it "floats", and the gate output jitters. The rule from every datasheet: unused inputs go to GND (or to VCC). The same in the simulator: a hanging input gives an undefined value.

??input left openGND1input on ground
A free input of a CMOS gate is connected to nothing — it has no level, and the output "floats". So the free inputs of every gate in the package go to GND: the output becomes defined, even if nobody needs it.

1.3. The idea: a latch from one chip

Two NANDs from one 74HC00 connected crosswise make an SR latch: a zero on one input lights the output, a zero on the other clears it, and when both are ones the latch remembers the last state. That is how the alarm remembers.

nTRIPnRESETALARMALQN1A=nTRIP, 1B=ALQN, 1Y=ALARM · 2A=nRESET, 2B=ALARM, 2Y=ALQN
The alarm latch is two NANDs from one 74HC00, crossed. A 0 on nTRIP lights ALARM, a 0 on nRESET clears it; when both are 1 the latch holds what it had. That is why the alarm stays on even after the door is closed.

1.4. Building

The real build of lesson 1 — unstaged, sped up 8 times, 2 min 47 s.

A new project. You need the gates NOT, NAND, NOR, AND, OR — from any kit of the series or lesson 0.

Step 1. Chip 74HC00 — 4 × NAND

Package pins from the datasheet: 1 1A, 2 1B, 3 1Y, 4 2A, 5 2B, 6 2Y, 8 3Y, 9 3A, 10 3B, 11 4Y, 12 4A, 13 4B; 7 — GND, 14 — VCC (our power is shared, so these pins are not there). Port name = pin name: double-click a port → 1A and so on.

PartPinLabel
Input portoutput1A
Input portoutput1B
Input portoutput2A
Input portoutput2B
Input portoutput3A
Input portoutput3B
Input portoutput4A
Input portoutput4B
Output portinput1Y
Output portinput2Y
Output portinput3Y
Output portinput4Y
NANDI0
I1
O0
1A
1B
1Y
NANDI0
I1
O0
2A
2B
2Y
NANDI0
I1
O0
3A
3B
3Y
NANDI0
I1
O0
4A
4B
4Y

Ctrl+G → name 74HC00. Legs: inputs 1A, 1B, 2A, 2B, 3A, 3B, 4A, 4B; outputs 1Y, 2Y, 3Y, 4Y.

Step 2. Chip 74HC02 — 4 × NOR

Package pins from the datasheet: 1 1Y, 2 1A, 3 1B, 4 2Y, 5 2A, 6 2B, 8 3A, 9 3B, 10 3Y, 11 4A, 12 4B, 13 4Y; 7 — GND, 14 — VCC (our power is shared, so these pins are not there). Port name = pin name: double-click a port → 1A and so on.

PartPinLabel
Input portoutput1A
Input portoutput1B
Input portoutput2A
Input portoutput2B
Input portoutput3A
Input portoutput3B
Input portoutput4A
Input portoutput4B
Output portinput1Y
Output portinput2Y
Output portinput3Y
Output portinput4Y
NORI0
I1
O0
1A
1B
1Y
NORI0
I1
O0
2A
2B
2Y
NORI0
I1
O0
3A
3B
3Y
NORI0
I1
O0
4A
4B
4Y

Ctrl+G → name 74HC02. Legs: inputs 1A, 1B, 2A, 2B, 3A, 3B, 4A, 4B; outputs 1Y, 2Y, 3Y, 4Y.

Step 3. Chip 74HC04 — 6 × NOT

Package pins from the datasheet: 1 1A, 2 1Y, 3 2A, 4 2Y, 5 3A, 6 3Y, 8 4Y, 9 4A, 10 5Y, 11 5A, 12 6Y, 13 6A; 7 — GND, 14 — VCC (our power is shared, so these pins are not there). Port name = pin name: double-click a port → 1A and so on.

PartPinLabel
Input portoutput1A
Input portoutput2A
Input portoutput3A
Input portoutput4A
Input portoutput5A
Input portoutput6A
Output portinput1Y
Output portinput2Y
Output portinput3Y
Output portinput4Y
Output portinput5Y
Output portinput6Y
NOTI0
O0
1A
1Y
NOTI0
O0
2A
2Y
NOTI0
O0
3A
3Y
NOTI0
O0
4A
4Y
NOTI0
O0
5A
5Y
NOTI0
O0
6A
6Y

Ctrl+G → name 74HC04. Legs: inputs 1A, 2A, 3A, 4A, 5A, 6A; outputs 1Y, 2Y, 3Y, 4Y, 5Y, 6Y.

Step 4. Chip 74HC08 — 4 × AND

Package pins from the datasheet: 1 1A, 2 1B, 3 1Y, 4 2A, 5 2B, 6 2Y, 8 3Y, 9 3A, 10 3B, 11 4Y, 12 4A, 13 4B; 7 — GND, 14 — VCC (our power is shared, so these pins are not there). Port name = pin name: double-click a port → 1A and so on.

PartPinLabel
Input portoutput1A
Input portoutput1B
Input portoutput2A
Input portoutput2B
Input portoutput3A
Input portoutput3B
Input portoutput4A
Input portoutput4B
Output portinput1Y
Output portinput2Y
Output portinput3Y
Output portinput4Y
ANDI0
I1
O0
1A
1B
1Y
ANDI0
I1
O0
2A
2B
2Y
ANDI0
I1
O0
3A
3B
3Y
ANDI0
I1
O0
4A
4B
4Y

Ctrl+G → name 74HC08. Legs: inputs 1A, 1B, 2A, 2B, 3A, 3B, 4A, 4B; outputs 1Y, 2Y, 3Y, 4Y.

Step 5. Chip 74HC32 — 4 × OR

Package pins from the datasheet: 1 1A, 2 1B, 3 1Y, 4 2A, 5 2B, 6 2Y, 8 3Y, 9 3A, 10 3B, 11 4Y, 12 4A, 13 4B; 7 — GND, 14 — VCC (our power is shared, so these pins are not there). Port name = pin name: double-click a port → 1A and so on.

PartPinLabel
Input portoutput1A
Input portoutput1B
Input portoutput2A
Input portoutput2B
Input portoutput3A
Input portoutput3B
Input portoutput4A
Input portoutput4B
Output portinput1Y
Output portinput2Y
Output portinput3Y
Output portinput4Y
ORI0
I1
O0
1A
1B
1Y
ORI0
I1
O0
2A
2B
2Y
ORI0
I1
O0
3A
3B
3Y
ORI0
I1
O0
4A
4B
4Y

Ctrl+G → name 74HC32. Legs: inputs 1A, 1B, 2A, 2B, 3A, 3B, 4A, 4B; outputs 1Y, 2Y, 3Y, 4Y.

Step 6. Alarm: power and inputs

Switches ARM — the alarm is on, DOOR — the door is open, WIN — the window is open; the Reset button is RESET.

PartPinLabel
PoweroutputVCC
GroundoutputGND
Input (switch)outputARM
Input (switch)outputDOOR
Input (switch)outputWIN
Button «Reset»outputRESET

Step 7. Open: 74HC32

OPEN = door OR window. One gate of four works; the inputs of the other three go to GND: a CMOS chip input must not hang in the air, otherwise the output "floats". The same on a real board.

PartPinLabel
74HC321A
1B
1Y
2A
2B
3A
3B
4A
4B
DOOR
WIN
OPEN
GND
GND
GND
GND
GND
GND

Step 8. The alarm starts: 74HC08

TRIP = open AND the alarm is on.

PartPinLabel
74HC081A
1B
1Y
2A
2B
3A
3B
4A
4B
OPEN
ARM
TRIP
GND
GND
GND
GND
GND
GND

Step 9. Inversion: 74HC04

A NAND latch is triggered by a zero, so TRIP and the RESET button are inverted: nTRIP, nRESET.

PartPinLabel
74HC041A
1Y
2A
2Y
3A
4A
5A
6A
TRIP
nTRIP
RESET
nRESET
GND
GND
GND
GND

Step 10. Alarm latch: 74HC00

Two NANDs crossed — a latch: nTRIP = 0 lights ALARM, nRESET = 0 clears it. The alarm stays on even after the door is closed — until Reset is pressed.

PartPinLabel
74HC001A
1B
1Y
2A
2B
2Y
3A
3B
4A
4B
nTRIP
ALQN
ALARM
nRESET
ALARM
ALQN
GND
GND
GND
GND

Step 11. Ready: 74HC02

READY = NOR(open, alarm): lit when everything is closed and there is no alarm.

PartPinLabel
74HC021Y
1A
1B
2A
2B
3A
3B
4A
4B
READY
OPEN
ALARM
GND
GND
GND
GND
GND
GND
LEDinputALARM
LEDinputREADY
Speaker (buzzer, 880)SPKRALARM

Step 12. Lamps and chime

Speaker — buzzer mode, tone 880: it buzzes while ALARM = 1.

PartPinLabel
LEDinputALARM
LEDinputREADY
Speaker (buzzer, 880)SPKRALARM

1.5. Check

  1. Press Reset: ALARM is off, READY is lit — everything is closed, no alarm.
  2. DOOR = 1 (the alarm is off): READY goes out — the door is open, but there is no alarm. DOOR = 0 — READY is lit again.
  3. ARM = 1 — the alarm is on. WIN = 1: ALARM lights up, the buzzer sounds, READY goes out.
  4. WIN = 0 — the window is closed, but ALARM stays lit: the latch remembers the alarm.
  5. Reset — ALARM goes out, READY is lit.
  6. DOOR = 1 and Reset: the alarm does not go out — while the door is open, nTRIP holds the latch.
What you seeWhat it is
ALARM litsomething opened while the alarm was on
ALARM lit, all closedthe 74HC00 latch remembers — press Reset
READY liteverything closed, no alarm

Lesson 1 paste (Cmd+I)

You need the gates NOT, NAND, NOR, AND, OR (lesson 0 or its paste). The paste is five chips and the alarm; set the Speaker by hand — buzzer mode, tone 880.

# Lesson 1 — logic in packages: 74HC00, 74HC02, 74HC04, 74HC08, 74HC32 and an alarm built from them.# Paste: Cmd+I into a project with the gates NOT, NAND, NOR, AND, OR (lesson 0). chip 74HC00 {  portIn(1A)  portIn(1B)  portIn(2A)  portIn(2B)  portIn(3A)  portIn(3B)  portIn(4A)  portIn(4B)  portOut(1Y)  portOut(2Y)  portOut(3Y)  portOut(4Y)  NAND(1A, 1B, 1Y)  NAND(2A, 2B, 2Y)  NAND(3A, 3B, 3Y)  NAND(4A, 4B, 4Y)} chip 74HC02 {  portIn(1A)  portIn(1B)  portIn(2A)  portIn(2B)  portIn(3A)  portIn(3B)  portIn(4A)  portIn(4B)  portOut(1Y)  portOut(2Y)  portOut(3Y)  portOut(4Y)  NOR(1A, 1B, 1Y)  NOR(2A, 2B, 2Y)  NOR(3A, 3B, 3Y)  NOR(4A, 4B, 4Y)} chip 74HC04 {  portIn(1A)  portIn(2A)  portIn(3A)  portIn(4A)  portIn(5A)  portIn(6A)  portOut(1Y)  portOut(2Y)  portOut(3Y)  portOut(4Y)  portOut(5Y)  portOut(6Y)  NOT(1A, 1Y)  NOT(2A, 2Y)  NOT(3A, 3Y)  NOT(4A, 4Y)  NOT(5A, 5Y)  NOT(6A, 6Y)} chip 74HC08 {  portIn(1A)  portIn(1B)  portIn(2A)  portIn(2B)  portIn(3A)  portIn(3B)  portIn(4A)  portIn(4B)  portOut(1Y)  portOut(2Y)  portOut(3Y)  portOut(4Y)  AND(1A, 1B, 1Y)  AND(2A, 2B, 2Y)  AND(3A, 3B, 3Y)  AND(4A, 4B, 4Y)} chip 74HC32 {  portIn(1A)  portIn(1B)  portIn(2A)  portIn(2B)  portIn(3A)  portIn(3B)  portIn(4A)  portIn(4B)  portOut(1Y)  portOut(2Y)  portOut(3Y)  portOut(4Y)  OR(1A, 1B, 1Y)  OR(2A, 2B, 2Y)  OR(3A, 3B, 3Y)  OR(4A, 4B, 4Y)} power(VCC)ground(GND)input(ARM)input(DOOR)input(WIN)button{label="Reset"}(RESET)74HC32(1A=DOOR, 1B=WIN, 1Y=OPEN, 2A=GND, 2B=GND, 3A=GND, 3B=GND, 4A=GND, 4B=GND)74HC08(1A=OPEN, 1B=ARM, 1Y=TRIP, 2A=GND, 2B=GND, 3A=GND, 3B=GND, 4A=GND, 4B=GND)74HC04(1A=TRIP, 1Y=nTRIP, 2A=RESET, 2Y=nRESET, 3A=GND, 4A=GND, 5A=GND, 6A=GND)74HC00(1A=nTRIP, 1B=ALQN, 1Y=ALARM, 2A=nRESET, 2B=ALARM, 2Y=ALQN, 3A=GND, 3B=GND, 4A=GND, 4B=GND)74HC02(1Y=READY, 1A=OPEN, 1B=ALARM, 2A=GND, 2B=GND, 3A=GND, 3B=GND, 4A=GND, 4B=GND)led(ALARM)led(READY)speaker{mode="buzz", tone=880}(ALARM)

¿No te sale? Algo no funciona →