Fun With 4-pin Common Anode RGB LED and XOR Logic Using ATtiny2313A in Assembly
by Santanu1310 in Circuits > LEDs
701 Views, 1 Favorites, 0 Comments
Fun With 4-pin Common Anode RGB LED and XOR Logic Using ATtiny2313A in Assembly
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:
- ATtiny2313A - 1 no.
- DIP 20-pin IC Base - 1 no.
- 12mm Tactile Push-button - 5 nos. (can be reduced to 3 nos.)
- Resistor (47K) - 5 nos. (can be reduced to 3 nos.)
- RGB LED - 1 no.
- Resistor (470 Ohm) - 3 nos.
- 10-pin FRC Shrouded Male Header - 1 no.
The following tools have been used:
- Multimeter
- Soldering Iron and Solder Wire
- Wire Cutter
- Tweezers
- USBasp AVR Programmer
The following Softwares have been used:
- AVR Studio 4
- PROGISP ver 1.72
What Is RGB LED
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
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
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.