8051 and RGB LED example

In this example we connect an RGB LED to our 8051. In this case we used an RGB LED breakout, this was a common anode device. The schematic below shows the connection to the RGB LED breakout.

We will switch on the main colours individually in the example

 

Schematic

8051 RGB LED

Code

The code was written using mikro C PRO for 8051

void main()
{
do
{
P2 = 0xFF; // Turn OFF
Delay_ms(1000); // 1 second delay
P2 = 0xFE;
Delay_ms(1000);
P2 = 0xFD;
Delay_ms(1000);
P2 = 0xFB;
Delay_ms(1000);
P2 = 0xF8;
Delay_ms(1000);
P2 = 0xFF; // Turn OFF diodes on PORT2
Delay_ms(1000); // 1 second delay

} while(1); // Endless loop
}

 

Links

 


RGB LED Module for Arduino (Works with Official Arduino Boards) – $2.23

from: DealExtreme

Related posts

8051 and RGB led example using the SiLabs IDE

C8051F340 flashing led example

8051 7 Segment display program written in Basic