2-Bit D Latch Memory With Arduino and LCD
by adhillon in Circuits > Arduino
77 Views, 2 Favorites, 0 Comments
2-Bit D Latch Memory With Arduino and LCD
This project was made by Arveer Dhillon and Joshua Kamtasingh
Hello! This Instructable walks you through our final project, a 2-bit memory circuit using D latches, controlled by logic gates that read and write data using a dip switch, data is displayed with the stored values on LEDs, and real-time information is shown on an LCD screen.
This project builds a 2-bit memory circuit using NAND gate-based D latches, controlled by an Arduino. The circuit stores 2 bits of information, reads and writes data using a dip switch and a single push button, displays the stored values on two LEDs, and shows the current state and value on a 16×2 LCD screen.
Supplies
Here's everything you need to build this project, prices are for one piece.:
Arduino UNO R3 - $24.99
2x AND GATES - $1.43
1x NOT GATE - $1.53
LCD Display - $11.53
2 Push Buttons - $7.50
2 LEDs - $0.25
2x 1K Ohm Resistor - $0.19
4x 330 Ohm Resistor - $0.22
1x DIP Switch - $1.02
Understanding the D Latch
Before connecting any wires, it is important to understand how a D latch works. A D latch is a simple memory device that stores one bit of information. It has a data input (D), an enable or CLK input (EN), and an output (Q). When the enable input is active, the output Q follows the value at D, allowing new data to be written into the latch. When the enable input becomes inactive, the output stops changing and holds the last value that was stored.
Building the D Latches
The D latches are the heart of this project because they act as the memory cells that store data. Since each D latch can store one bit, we need two D latches to create our 2-bit RAM circuit.
Begin by placing the NAND gate ICs onto your breadboard and connecting power and ground to the appropriate pins. Follow your circuit schematic to construct the first D latch using the NAND gates. The latch should have three main connections: the Data input (D), the Enable input (EN), and the outputs (Q and /Q).
Once the first latch is complete, repeat the same process to build a second identical D latch. Double-check all wiring before powering the circuit. A single misplaced wire can prevent the latch from storing data correctly.
After both latches are assembled, test them individually. Apply different values to the D input and toggle the Enable input. When Enable is active, the output should follow the input value. When Enable is inactive, the output should remain unchanged and hold the last value that was written. This confirms that the latches are functioning properly and are ready to be used as the memory cells in the RAM circuit.
Setting the LCD Display Up
The 16×2 LCD screen is used to show what is happening inside the circuit in real time, including the current stored values and whether the system is in read or write mode.
Start by placing the LCD on the breadboard and wiring it to the Arduino using the correct digital pins. Make sure to connect power (5V) and ground properly, since the LCD will not function without stable power. Adjust the contrast pin using a potentiometer so the text becomes clearly visible on the screen.
Next, connect the data and control pins from the LCD to the Arduino according to the pin setup in the code. It is important that the wiring matches the LiquidCrystal configuration so the display can communicate correctly with the Arduino.
Once everything is wired, upload a simple test program or your main code to check the display. The LCD should power on and show the startup message, confirming that it is working properly. After this, it will continuously update to show the stored 2-bit value and the current system status as the circuit runs.
Arduino Code
Step 1: Include the LCD Library
Start by importing the LiquidCrystal library and creating the LCD object. This allows the Arduino to communicate with the 16×2 LCD display.
Step 2: Define All Pins and Variables
Next, define the pins used for the LEDs, D latch enable inputs, and data inputs. Also create arrays to store the state of each latch.
Step 3: Create the D Latch Function
Create a function that mimics the behavior of a D latch. This makes it more simple for the arduino to output current states on the LCD. When the enable signal is active, the latch stores the current input value.
Step 4: Create the LCD Update Function
This function updates the LCD with the current values stored in each latch and displays whether the latch is being edited or holding its value.
Step 5: Write the Setup Function
Configure the input and output pins, start serial communication, and initialize the LCD.
Step 6: Write the Main Loop
The loop continuously updates the latches, controls the LEDs, sends debugging information to the Serial Monitor, and refreshes the LCD.
Step 7: Upload and Test
Connect your Arduino to your computer, select the correct board and COM port in the Arduino IDE, and click Upload. Once uploaded, use the DIP switches and enable inputs to write values into the latches. The LEDs and LCD should immediately reflect the stored 2-bit value.
The .ino File with the code is attached below.
Downloads
Circuit Demonstration
Congratulations! You have successfully built a working 2-bit RAM circuit using NAND gate D latches, an Arduino, LEDs, and an LCD display. Your circuit can store two bits of data, hold those values in memory, and display them in real time.
To verify everything is working correctly, try different combinations on the DIP switches and activate the enable inputs to write new values. The LEDs should show the stored bits, while the LCD displays the current state of each latch.
By completing this project, you have created a simple form of RAM and gained hands-on experience with digital memory, logic gates, latches, and microcontroller integration. Great job!