Fun With 4-pin Common Anode RGB LED and XOR Logic Using ATtiny2313A in Assembly

by Santanu1310 in Circuits > LEDs

623 Views, 1 Favorites, 0 Comments

Fun With 4-pin Common Anode RGB LED and XOR Logic Using ATtiny2313A in Assembly

20210606185527_IMG_3703.JPG

Actually, I am working on a large project where I have used RGB LEDs. Finding it easy but interesting I wrote this instructable separately. So, few components can be reduced.

Supplies

The following electronic components have been used:

  1. ATtiny2313A - 1 no.
  2. DIP 20-pin IC Base - 1 no.
  3. 12mm Tactile Push-button - 5 nos. (can be reduced to 3 nos.)
  4. Resistor (47K) - 5 nos. (can be reduced to 3 nos.)
  5. RGB LED - 1 no.
  6. Resistor (470 Ohm) - 3 nos.
  7. 10-pin FRC Shrouded Male Header - 1 no.

The following tools have been used:

  1. Multimeter
  2. Soldering Iron and Solder Wire
  3. Wire Cutter
  4. Tweezers
  5. USBasp AVR Programmer

The following Softwares have been used:

  1. AVR Studio 4
  2. PROGISP ver 1.72

What Is RGB LED

800px-LED,_5mm,_green_(en) 111.png
RGB-LEDs-Pinout.png
Common-Anode-RGB-LED-Pinout.png
Common-Cathode-RGB-LED-Pinout.png
image_2021-06-06_22-21-46.png

In a Single Color LED, there are 2 pins, (i) Anode (the longer one) and (ii) Cathode (the shorter one).

You can imagine the RGB LED as a combination of 3 Single Color LEDs of (i) Red, (ii) Green and (iii) Blue built into a single package. According to the common point, you will find 2 kinds of RGB LEDs, (i) Common Anode and (ii) Common Cathode. In my case, it is a Common Anode. Red, Green and Blue are the only three Primary colors, which means by mixing and changing the intensity, you can produce any color. For my usage, I don't need to produce several colors, so, I didn't add the intensity control but you can make it using PWMs. With just On/Off control, I can produce (2^3) - 1 total off condition = 7 colors.

The Circuit

RGB LED.png
20210606185527_IMG_3703.JPG

Until now, no dedicated power connection has been provided to the board, as it is a part of a large incomplete project. So, it is being powered from the ISP header.

Three current limiting resistors have been added in series with the LED cathodes to limit the current up to approx. 10mA if the diode gets malfunctioned. (5 Volts / 470 Ohms = 10.638 mAmps approx.)

The Power of XOR

image_2021-06-06_23-24-11.png
Untitled Workspace.png
image_2021-06-06_23-57-11.png
image_2021-06-07_00-00-49.png
image_2021-06-07_00-01-04.png
ezgif.com-gif-maker.gif

Follow the truth table of Exclusive-OR, it is quite unique. By using XOR, you can make a bit toggle without any condition checking.

Initially, the board starts with a combination of Red-Green-Blue being 000. The combination is stored on a register. With every press of one of the first three keys on the board, the corresponding bit toggles producing on of the seven colors. The combinations have been shown.

The Code

The code is written in Assembly Language using the AVR Studio 4 IDE and is only 156 Bytes.

Downloads