The 74169 IC is a 4-bit asynchronous up/down binary counter with a synchronous load capability. It is a commonly used integrated circuit in digital electronics and IoT projects. This documentation provides an overview of the 74169 IC, its pinout, and code examples to demonstrate its usage in various contexts.
The 74169 IC has 16 pins, with the following pinout:
| Pin | Function |
| --- | --- |
| 1 | Clock input (CLK) |
| 2 | Count enable input (EN) |
| 3 | Load input (LD) |
| 4 | Data input (D0) |
| 5 | Data input (D1) |
| 6 | Data input (D2) |
| 7 | Data input (D3) |
| 8 | Counter output (Q0) |
| 9 | Counter output (Q1) |
| 10 | Counter output (Q2) |
| 11 | Counter output (Q3) |
| 12 | Carry output (Cout) |
| 13 | Borrow output (Bout) |
| 14 | Asynchronous clear input (CLR) |
| 15 | VCC (Positive supply voltage) |
| 16 | GND (Ground) |
### Example 1: Basic Up/Down Counter
In this example, we will use the 74169 IC as a basic up/down counter. We will connect the clock input to a push-button, and the count enable input to a logic high. The output of the counter will be displayed on four LEDs.
Connect the clock input (pin 1) to a push-button. Connect the count enable input (pin 2) to VCC. Connect the load input (pin 3) to GND. Connect the data inputs (pins 4-7) to GND. Connect the counter outputs (pins 8-11) to four LEDs. Connect the carry output (pin 12) and borrow output (pin 13) to GND.
Code (Arduino)
```c
const int clockPin = 2; // Clock input
const int countEnablePin = 3; // Count enable input
const int ledPins[] = {4, 5, 6, 7}; // LED pins
void setup() {
pinMode(clockPin, INPUT);
pinMode(countEnablePin, OUTPUT);
digitalWrite(countEnablePin, HIGH);
for (int i = 0; i < 4; i++) {
pinMode(ledPins[i], OUTPUT);
}
}
void loop() {
if (digitalRead(clockPin) == HIGH) {
// Increment counter
digitalWrite(ledPins[0], !digitalRead(ledPins[0]));
digitalWrite(ledPins[1], !digitalRead(ledPins[1]));
digitalWrite(ledPins[2], !digitalRead(ledPins[2]));
digitalWrite(ledPins[3], !digitalRead(ledPins[3]));
}
delay(50);
}
```
### Example 2: load and count up/down with a manual switch
In this example, we will use the 74169 IC to load a 4-bit binary value and then count up or down based on a manual switch.
Connect the clock input (pin 1) to a push-button. Connect the load input (pin 3) to a manual switch (SW1). Connect the data inputs (pins 4-7) to four switches (SW2-SW5). Connect the counter outputs (pins 8-11) to four LEDs. Connect the carry output (pin 12) and borrow output (pin 13) to GND.
Code (Arduino)
```c
const int clockPin = 2; // Clock input
const int loadPin = 3; // Load input
const int dataPins[] = {4, 5, 6, 7}; // Data input pins
const int ledPins[] = {8, 9, 10, 11}; // LED pins
void setup() {
pinMode(clockPin, INPUT);
pinMode(loadPin, INPUT);
for (int i = 0; i < 4; i++) {
pinMode(dataPins[i], INPUT);
pinMode(ledPins[i], OUTPUT);
}
}
void loop() {
if (digitalRead(loadPin) == HIGH) {
// Load data from switches
byte data = 0;
for (int i = 0; i < 4; i++) {
if (digitalRead(dataPins[i]) == HIGH) {
data |= (1 << i);
}
}
// Display loaded data on LEDs
for (int i = 0; i < 4; i++) {
digitalWrite(ledPins[i], (data & (1 << i)) ? HIGH : LOW);
}
}
if (digitalRead(clockPin) == HIGH) {
// Count up/down based on switch state
bool up = digitalRead(12); // Switch state (up/down)
if (up) {
// Increment counter
for (int i = 0; i < 4; i++) {
digitalWrite(ledPins[i], !digitalRead(ledPins[i]));
}
} else {
// Decrement counter
for (int i = 0; i < 4; i++) {
digitalWrite(ledPins[i], !digitalRead(ledPins[i]));
}
}
}
delay(50);
}
```
Note: In this example, we assume that the manual switch (SW1) is connected to the load input (pin 3) and the data inputs (pins 4-7) are connected to four switches (SW2-SW5). The clock input (pin 1) is connected to a push-button. The output of the counter is displayed on four LEDs.