Project: AT89S52-based Multi-Coloured LED Heart Kit

As my radio kit-building adventures have reached the “bottom” of the eBay well, with most of the kits available being built, I decided to branch out into other “low cost” kits to see what they are like. Most of the really low-cost kits were only modules with very few components, so I decided to pass on them to something a little more substantial.

That’s when I stumbled on an unbranded kit, featuring 32 colour-changing LEDs arranged in a heart shape and an Atmel AT89S52 80C51 microcontroller for just AU$4.66 including postage. For that price, I couldn’t even get the microcontroller or the LEDs locally, so I thought it would be good even if just for parts. But on the whole, I usually don’t want to have such garish items.

But instead of scrapping it for parts, I decided to take the challenge. It was like an “endurance” race – the kit was going to be repetitive and tedious, but at the same time, it was something I wanted to do to prove that I could do it. Another reason this particular sort of kit appeals to me is because of the Velleman kit known as the Flashing LED Sweetheart. This was just a flasher with 28 single-coloured red LEDs, but it was part of the high-school electronics program, which we adapted to a blinking outline of another shape (by drilling LEDs into perspex and wiring them up to the heart-shaped PCB). To actually build something more sophisticated, and cheaper, over 10-years later is a sign of technological progress.

The Bits

2016110409239059

Another day and it’s another semi-anonymous zip-lock plastic bag filled with “bits”. As usual, it’s bring-your-own solder, iron and side-cutters.

2016110409249060

Rather surprisingly, inside, we get a few tape section resistors, a smattering of capacitors, a crystal, a power switch, a DC jack, a USB to barrel jack cable (which will be handy for other things), a bag of LEDs and the IC with its corresponding socket. It is poked into foam to protect it in transit, although it doesn’t look like any ESD precautions were taken.

2016110409349071

Taking the chip out of the foam, it shows that it wasn’t even carefully put in – two of the pins were quite bent. Some careful manipulation restored their alignment without breaking them.

2016110409279061

The board itself is roughly square in size, and is of very good physical build quality. It’s a single layer board, with silkscreen on the top and a fibreglass substrate, but the top seems to have a very smooth, almost coated finish. It makes it both shiny and smooth, which is nice. The silkscreen has values printed, which is good as no notes accompany the board. The board does have several silkscreen glitches though – the label for C3 is where the drill-holes are, the word “LED” is just sitting in the middle of nowhere, and D31’s text is sitting inside D32’s footprint. Nothing show-stopping, as the numbering of the components really doesn’t matter anyway. The board also has many holes which are not indicated for components and terminate in either isolated pads or solid areas – in some sense, similar to protoboard. If you like, you could use them to build additional external mods, or it could be used educationally as a “test solder area”.

2016110409279062

The pads on the rear are finished in a nice shiny tin coating, and bright-blue soldermask is applied which should make soldering a breeze, although some of the spacings can be a little narrow for the beginner. Everything used is through-hole, so it should be a breeze.

Reverse Engineering

The Board

This project is so simple, that I can’t even be bothered to draw a schematic. Basically, the 5v positive supply comes in via the DC jack and is interrupted by the switch. From there, it feeds all the LEDs in a ring, and the IC. The IC is also connected to the negative. Each LED occupies one output of the IC and is driven through a 510 ohm resistor for current limiting (to avoid damage to the IC predominantly). Of the 40 pins, 32 are used by LEDs, leaving 8 pins. Of these eight pins, three are used for power supply (Vcc,Vpp,GND), two are used for crystal driving for time reference, two are not connected (/PROG,/PSEN) and the last pin is RESET which is tied down with a resistor. In all, the IC is directly driving each LED and will be sinking/sourcing all current. A small 10uF capacitor is supplied to bypass the power supply at the IC. The negative is supplied through a wire link. It’s rather disappointing to see no voltage regulation or reverse polarity protection – in fact, the wire link could easily be replaced with a power diode to provide the latter.

Which leads me to the question of how many solder joints are involved in completing the kit?

32 LEDs = 64 joints
33 Resistors = 66 joints
3 Capacitors = 6 joints
1 Crystal = 2 joints
1 IC = 40 joints
1 Power Socket = 3 joints
1 Switch = 6 joints
1 Wire Link = 2 joints
Total = 189 joints

I suppose that could make for very quick boredom for some, but I enjoy doing these sorts of things …

The Program

Before I build the device, I wanted to see what the IC was holding inside. Using my trusty MiniPro TL866CS, it seems that the device was unlocked, allowing for a full dump and (likely) future reprogramming if desired. That’s a very nice feature.

readout-chip

Those who are interested, the software can be downloaded here. As I’m not particularly familiar with 80C51 code, a quick glance seems to show only 4357 bytes of the 8192 bytes available are used, so there could be space to add more features to it. I decided to load it into IDA Pro for a quick squiz, and it seems the program has a main loop which calls subfunctions in sequence – this is probably it calling each of the lighting effect sequences in turn. The other code structures are probably set-up or debug code which I’m not sure how it’s being invoked.

ida-breakdown

The LEDs

Normally when I think of colourful LEDs, I think of RGB LEDs which have either a common anode or common cathode and four connections. Instead, these LEDs only had two connections, which immediately led me to think “have I been ripped off?”

2016110516029097

2016110516039098A closer look at the LED makes it clear that I haven’t. In fact, these LEDs are a little different. Notice the large black rectangle inside?

A look straight over the top provides a distorted view of the internals with some visual disturbances because of the plastic itself. It seems the complex structures inside have led to air bubbles in the moulded plastic lens as well. Tilting it somewhat allows us to get a closer look at the components inside.

2016110516039099

This grey rectangle is a silicon die which controls the whole show. Basically the LEDs each have their own IC. A total of five wire bonds attach to the LED, namely the anode and cathode connection, and the anodes of each of the three LEDs – red, green and blue. The chip itself autonomously sequences the LEDs to create the colour-change effects, and probably also limits the current to some degree.

2016110516059100

Each of the three LED chips can be seen at the end of their wire bonds, which is just a small square inside their respective air-bubbles. The resulting light sequence looks like this:

single-led-animIt’s not particularly good looking, and it’s a bit blinky towards the end. But because the LED is being directly imaged, the “mixing” of the colours isn’t apparent. Just testing a single LED and resistor combination powered at 5v on my Picoscope shows the following

flashing-led-current-overview

Each LED on a channel is expected to consume about 4.5mA at its highest. The patterns cause rather significant swings in current, so the average current is likely to be lower. A full cycle of the LED takes about 10 seconds to complete.

Because of this, it’s not possible to individually “address” and set the LEDs to a given colour. The colour changing effects rendered have to be a careful combination of power-on/off time based on the LED’s nominal colour cycling behaviour.

Construction Experience

There’s really nothing to it – everything is straightforward and success is almost assured provided you take note of LED and capacitor polarity. Construction time is approximately 1.5 hours, or roughly one joint every 30 seconds. Interestingly, this kit uses the IC socket to provide Z-height clearance under the chip for the crystal and capacitors to mount. Note that the electrolytic is to be mount bent-over. The middle leg of the crystal is a can-ground leg, and no provision is made on the board to accommodate it, so it must be clipped flush to the can.

2016110411049083

The above is the board prior to mounting the IC. Nice and neat. Ensuring the LED’s alignments did need some care, although even then, perfection is not to be expected. Some of the LEDs had mould-flash protrusions which prevented them from sitting flush, so some attention with a knife was required.

2016110411049084

The pads soldered up mostly easily, although sometimes the close spacing did make getting the iron into optimal contact with the pads a little difficult.

2016110411069085

A slight tweak to the chip legs, and it’s safely put into the socket and ready for powering up. A nice perk is that the guys haven’t been bean-counters and seemed to have just “thrown in” some extras just in case.

2016110411069086

There are a total of 18 spare 510 ohm resistors, one spare 10k ohm resistor, two spare 22pF capacitors and two spare LEDs. I can’t complain about that! That’s almost too many spares.

Testing

Plugging it in and turning it on, and it works first time. So I took the opportunity to make this short demo video of it running, to thank my readers:

The LEDs are water-clear lensed, so they put out a very focused beam. Looking at it without any diffusing is quite glary and unpleasant, so I wrapped it in paper to diffuse it and help mix the colours better. I wondered how long the effects go for, so I scoped the LED25’s pin to see what the waveform looked like.

loop-led25

From the scope trace, the effect seems to go for 2 minutes and 35 seconds before repeating itself. I decided to look more closely at the voltages on the pins.

h-to-l-curr

Because the LEDs are provided positive on the outer ring, the LEDs are off when the chip output is high, as there is no potential difference over the LED. However, when the drive pin goes low, then the LED is powered up.

We normally think of high and low as being 5v and 0v in such a system, but in reality, there is a range of acceptable voltages, and due to the internal resistances in the chip, when high currents are being drawn, the voltages will stray from their ideal voltages. In the trace above, we can see that the voltage across the LED initially is about 2.75v, increasing to the full 5v at the end as the loading of the LED and loading on the chip changes (e.g. other LEDs turn off).

pwm-fade

Looking at the current itself, we can see that the LED utilizes its own internal PWM for dimming, at a rate of about 245Hz.

How stressed is the chip? Well given that I previously ascertained that each LED can draw about 4.5mA given the full 5v, each pin could be exposed to this much current. In reality, it’s likely less as the average current is less, and the pin wouldn’t be providing a perfect low output for the full 5v across the LED and resistor combination.

The chip is rated for a maximum of 10mA per pin, up to 15mA absolute maximum before damage occurs. This level is roughly half the maximum of each pin, so it checks out. The total of all current on each 8-bit port is 26mA for Port 0 and 15mA for Ports 1, 2 and 3. This seems to be violated, as eight LEDs at 4.5mA could potentially draw 36mA. The total current for all pins is 71mA, which is also exceeded, as all LEDs on will draw 144mA or around twice as much as the limit.

However, this probably is still okay, as the sheet states that the pins are not guaranteed to sink current greater than the test conditions – under 1.6mA current on a low output, the voltage is to be a maximum of 0.45v. It’s likely this just means that the output voltage will fall at least 0.45v, and the current to the LEDs will be accordingly reduced somewhat. Even if you do go over-spec a little, as long as the chip’s power dissipation is limited, damage is probably unlikely. It is a little hard on the chip and it’s why LED driving is better done with dedicated chips or MOSFETs where currents are not trivial and brightness is a requirement.

Conclusion

Another cheap kit is done and dusted. This one is cheap, and not very “useful” in the strict sense of usefulness. It’s also somewhat repetitive and boring to construct. But it does use a fairly beefy microcontroller, and each of the LEDs was its own little “surprise” in having its own control IC internally. It’s a wonder how they could make and supply the whole kit at the price that they do, especially when there are a few extra components as well. The board quality is also exemplary. The result is rather glary, but I suppose there’s some flexibility if you develop your own code for the 80C51. I suppose if you have a hankering to do lots of through-hole joints for not-much-of-a-reward, or it’s almost Valentine’s Day, maybe it’s worthwhile.

As it turns out, I have a second kit … that I’ve kept for parts … but maybe one day, I could challenge my future girlfriend to construct it. A love test, maybe?

About lui_gough

I'm a bit of a nut for electronics, computing, photography, radio, satellite and other technical hobbies. Click for more about me!
This entry was posted in Electronics and tagged , , , , , . Bookmark the permalink.

13 Responses to Project: AT89S52-based Multi-Coloured LED Heart Kit

  1. Everything about this post made me smile. That you do such thorough analyses of things that seem trivial at first glance is such a delight. Any time I see an IC or epoxy blob on little trinkets like this my gut reaction is always “I want to dump and disassemble the code”, but I’ve never had access to any of the tools nor knowledge of how to do it. So thank you for allowing me to vicariously enjoy tearing down various odd gadgets!

    We’ll all patiently wait for the follow-up wherein the future Mrs. Lui assembles the other kit.

    On an unrelated side note, this post marks the second time (as far as I could ascertain) that you’ve used the word “squiz”, which my American ears were totally unfamiliar with until a few weeks ago when my wife and I recorded an “Australian Slang Challenge” video for our vlog. With your permission I’ll post a link to it, in hopes that hearing one of your readers mangle your local idiomatics will make you also smile.

    • lui_gough says:

      Thanks for the positive comment, and by all means, happy for you to share. I’m sure we’ll all enjoy it.

      – Gough

        • lui_gough says:

          Definitely an … interesting way to interpret those words. As an Australian-educated person, these words are almost second-nature to us, and it’s amazing to see them misinterpreted. The logic is quite funny – but it does point to an obvious problem with language, namely that words that sound similar often have completely different meanings! Ideal way to cause some embarrassment … especially for those otherwise unaware.

          I’m sure that you guys could equally compile a list of American-English terms that would flummox most of the Aussies as well :).

          – Gough

  2. William Harrington says:

    I am glad I ran across this post for the DIY SCM heart kit. I purchased three of these and two of them had a program that faded the LEDs simultaneously. The third chip I tested had the program with a few different routines and provided a nice light show. Once the programmer arrives, I’ll program the other chips and perhaps write my own program. Depending on the source of product, I ordered mine through Banggood, I’m suspecting that they have a giant bin of these parts with different programs in the microcontrollers. http://www.banggood.com/DIY-SCM-Colorful-Glare-Heart-shaped-Light-Kit-Electronic-Teaching-Training-Kit-p-1078378.html

  3. Ahmadhennawi says:

    Can i use only red leds?

    • lui_gough says:

      Of course. There is a version of the kit without the multi-coloured LEDs from memory, but basically each of the multi-coloured LEDs are internally changing colours on their own accord, so switching all of them to a single colour will result in a different visual effect which will flash according to the output from the AT89S52 microcontroller.

      – Gough

  4. ahmadhennawi says:

    from where can i get the code of the microcontroller because the file that you had put it is not opening

    • lui_gough says:

      The file is the code for the microcontroller dumped from my own one. It is not source code – it is a ROM dump, so you don’t open it … you program it to a blank chip with a programmer device.

      – Gough

  5. Panda says:

    // https://www.programmersought.com/article/51905447102/

    #include
    #include

    #define uint unsigned int
    #define uchar unsigned char

    uchar code table0[] = { 0xfe, 0xfd, 0xfb, 0xf7, 0xef, 0xdf, 0xbf, 0x7f}; //LED shifts from low to high
    uchar code table1[] = { 0x7f, 0xbf, 0xdf, 0xef, 0xf7, 0xfb, 0xfd, 0xfe}; //LED shifts from high to low
    uchar code table2[] = { 0xfe, 0xfc, 0xf8, 0xf0, 0xe0, 0xc0, 0x80, 0x00}; //LED lights from 1 to 8 lights (from the low Up)
    uchar code table3[] = { 0x7f, 0x3f, 0x1f, 0x0f, 0x07, 0x03, 0x01, 0x00}; //LED lights from 1 to 8 lights (from high Lower)
    uchar code table4[] = { 0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff}; //LED from 8 all on to no light on ((From low to high)
    uchar code table5[] = { 0x00, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xff}; //LED from 8 all on to no one on ((From high to low)
    uchar code table6[] = { 0xfe, 0xfc, 0xfa, 0xf6, 0xee, 0xde, 0xbe, 0x7e}; //LED shifts from low to high (the lowest bit is always 0)
    uchar code table7[] = { 0x7f, 0x3f, 0x5f, 0x6f, 0x77, 0x7b, 0x7d, 0x7e}; //LED shifts from high to low (the highest bit is always 0)

    uchar i, j; //Define loop variables
    uint tt = 70; //Define time index

    void delay(uint time) //Delay function
    {
    uint x, y;

    for (x = time; x > 0; x–)
    for (y = 110; y > 0; y–);
    }

    void disp0() //State 0 All LEDs flash 3 times
    {
    for (i = 0; i < 3; i++)
    {
    P0 = 0x00;
    P2 = 0x00;
    P3 = 0x00;
    P1 = 0x00;
    delay(300);

    P0 = 0xff;
    P2 = 0xff;
    P3 = 0xff;
    P1 = 0xff;
    delay(300);
    }
    }

    void disp1() //State 1 LED turns clockwise
    {
    for (i = 0; i < 8; i++)
    {
    P2 = table1[i];
    delay(100);
    }
    P2 = 0xff;

    for (i = 0; i < 8; i++)
    {
    P3 = table1[i];
    delay(100);
    }
    P3 = 0xff;

    for (i = 0; i < 8; i++)
    {
    P1 = table1[i];
    delay(100);
    }
    P1 = 0xff;

    for (i = 0; i < 8; i++)
    {
    P0 = table0[i];
    delay(100);
    }
    P0 = 0xff;
    }

    void disp2() //Status 2 LED turns counterclockwise
    {
    for (i = 0; i < 8; i++)
    {
    P0 = table1[i];
    delay(100);
    }
    P0 = 0xff;

    for (i = 0; i < 8; i++)
    {
    P1 = table0[i];
    delay(100);
    }
    P1 = 0xff;

    for (i = 0; i < 8; i++)
    {
    P3 = table0[i];
    delay(100);
    }
    P3 = 0xff;

    for (i = 0; i < 8; i++)
    {
    P2 = table0[i];
    delay(100);
    }
    P2 = 0xff;
    }

    void disp3() //State 3 4 LEDs move 1/4 turn clockwise and counterclockwise at the same time
    {
    for (i = 0; i < 8; i++)
    {
    P0 = table1[i];
    P1 = table1[i];
    P2 = table1[i];
    P3 = table0[i];
    delay(100);
    }

    for (i = 0; i < 8; i++)
    {
    P0 = table0[i];
    P1 = table0[i];
    P2 = table0[i];
    P3 = table1[i];
    delay(100);
    }

    P3 = 0xff;
    P0 = 0xff;
    }

    void disp4() //State 4 2 LEDs move clockwise half a circle at the same time
    {
    for (i = 0; i < 8; i++)
    {
    P2 = table1[i];
    P1 = table1[i];
    delay(100);
    }
    P2 = 0xff;
    P1 = 0xff;

    for (i = 0; i < 8; i++)
    {
    P3 = table1[i];
    P0 = table0[i];
    delay(100);
    }
    P3 = 0xff;
    P0 = 0xff;
    }

    void disp5() //State 5 2 LEDs move half a circle counterclockwise at the same time
    {
    for (i = 0; i < 8; i++)
    {
    P0 = table1[i];
    P3 = table0[i];
    delay(100);
    }
    P0 = 0xff;
    P3 = 0xff;

    for (i = 0; i < 8; i++)
    {
    P1 = table0[i];
    P2 = table0[i];
    delay(100);
    }
    P1 = 0xff;
    P2 = 0xff;
    }

    void disp6() //Status 6 LED gradually lights up from top to bottom (half lit and half off)
    {
    for (i = 0; i < 8; i++)
    {
    P0 = table3[i];
    P2 = table3[i];
    delay(100);
    }
    P0 = 0xff;
    P2 = 0xff;

    for (i = 0; i < 8; i++)
    {
    P1 = table2[i];
    P3 = table3[i];
    delay(100);
    }
    P1 = 0xff;
    P3 = 0xff;
    }

    void disp7() //Status 7 LED gradually lights up from bottom to top (until all lights up)
    {
    for (i = 0; i < 8; i++)
    {
    P1 = table3[i];
    P3 = table2[i];
    delay(100);
    }

    for (i = 0; i < 8; i++)
    {
    P0 = table2[i];
    P2 = table2[i];
    delay(100);
    }
    }

    void disp8() //The 4 LEDs in the 8 intermittent state 8 are on and rotate counterclockwise
    {
    for (j = 0; j < 2; j++)
    {
    for (i = 0; i < 8; i++)
    {
    P0 = table1[i];
    P2 = table0[i];
    P1 = table0[i];
    P3 = table0[i];
    delay(100);
    }
    P0 = 0xff;
    P2 = 0xff;
    P1 = 0xff;
    P3 = 0xff;

    for (i = 0; i < 8; i++)
    {
    P0 = table1[i];
    P2 = table0[i];
    P1 = table0[i];
    P3 = table0[i];
    delay(100);
    }
    P0 = 0xff;
    P2 = 0xff;
    P1 = 0xff;
    P3 = 0xff;
    }
    }

    void disp9() //The 4 LEDs in state 9 intermittently light up with 8 grids, and then gradually light up counterclockwise (until all light up)
    {
    for (i = 0; i < 8; i++)
    {
    P0 = table3[i];
    P2 = table2[i];
    P1 = table2[i];
    P3 = table2[i];
    delay(100);
    }
    delay(500);
    }

    void disp10() //State 10 from all the LEDs on to all off (the 4 LEDs with 8 intervals start to go out counterclockwise)
    {
    for (i = 0; i < 9; i++)
    {
    P0 = table5[i];
    P2 = table4[i];
    P1 = table4[i];
    P3 = table4[i];
    delay(100);
    }
    delay(300);
    }

    void disp11() //The 4 LEDs in state 11 intermittently turn on and rotate clockwise
    {
    for (j = 0; j < 2; j++)
    {
    for (i = 0; i < 8; i++)
    {
    P0 = table0[i];
    P2 = table1[i];
    P1 = table1[i];
    P3 = table1[i];
    delay(100);
    }
    P0 = 0xff;
    P2 = 0xff;
    P1 = 0xff;
    P3 = 0xff;

    for (i = 0; i < 8; i++)
    {
    P0 = table0[i];
    P2 = table1[i];
    P1 = table1[i];
    P3 = table1[i];
    delay(100);
    }
    P0 = 0xff;
    P2 = 0xff;
    P1 = 0xff;
    P3 = 0xff;
    }
    }

    void disp12() //The 4 LEDs with 8 intermittent grids light up, and then gradually light up clockwise (until all light up)
    {
    for (i = 0; i < 8; i++)
    {
    P0 = table2[i];
    P2 = table3[i];
    P1 = table3[i];
    P3 = table3[i];
    delay(100);
    }
    delay(1000);
    }

    void disp13() //State 13 from all the LEDs on to all off (the 4 LEDs with 8 intervals start to turn off clockwise)
    {
    for (i = 0; i < 9; i++)
    {
    P0 = table4[i];
    P2 = table5[i];
    P1 = table5[i];
    P3 = table5[i];
    delay(100);
    }
    delay(300);
    }

    void disp14() //State 14 From off-to-all LED (lighting gradually from P0.0, P1.0, P2.0, P3.7)
    {
    for (i = 0; i < 8; i++)
    {
    P0 = table2[i];
    P1 = table2[i];
    P2 = table2[i];
    P3 = table3[i];
    delay(100);
    }
    }

    void disp15() //State 15 from all LEDs on to all off (gradually extinguished from P0.7, P1.7, P2.7, P3.0)
    {
    for (i = 0; i < 9; i++)
    {
    P0 = table5[i];
    P1 = table5[i];
    P2 = table5[i];
    P3 = table4[i];
    delay(100);
    }
    delay(300);
    }

    void disp16() //State 16 LED lights flash alternately (the frequency becomes slower and faster)
    {
    for (i = 0; i < 5; i++)
    {
    P0 = 0xaa;
    P1 = 0xaa;
    P2 = 0xaa;
    P3 = 0xaa;
    delay(100);

    P0 = ~P0;
    P1 = ~P1;
    P2 = ~P2;
    P3 = ~P3;
    delay(100);
    }

    for (i = 0; i < 5; i++)
    {
    P0 = 0xaa;
    P1 = 0xaa;
    P2 = 0xaa;
    P3 = 0xaa;
    delay(200);

    P0 = ~P0;
    P1 = ~P1;
    P2 = ~P2;
    P3 = ~P3;
    delay(200);
    }

    for (i = 0; i < 5; i++)
    {
    P0 = 0xaa;
    P1 = 0xaa;
    P2 = 0xaa;
    P3 = 0xaa;
    delay(300);

    P0 = ~P0;
    P1 = ~P1;
    P2 = ~P2;
    P3 = ~P3;
    delay(300);
    }
    P0 = 0xff;
    P2 = 0xff;
    P1 = 0xff;
    P3 = 0xff;
    delay(300);
    }

    void disp17() //Status 17 LED gradually lights up counterclockwise from P0.7, (cycle 2 times) and the speed will gradually increase
    {
    for (i = 0; i < 8; i++)
    {
    P0 = table3[i];
    delay(100);
    }

    for (i = 0; i < 8; i++)
    {
    P1 = table2[i];
    delay(100);
    }

    for (i = 0; i < 8; i++)
    {
    P3 = table2[i];
    delay(100);
    }

    for (i = 0; i < 8; i++)
    {
    P2 = table2[i];
    delay(100);
    }
    P0 = 0xff;
    P1 = 0xff;
    P3 = 0xff;
    P2 = 0xff;

    /*******************************/
    for (i = 0; i < 8; i++)
    {
    P0 = table3[i];
    delay(50);
    }

    for (i = 0; i < 8; i++)
    {
    P1 = table2[i];
    delay(50);
    }

    for (i = 0; i < 8; i++)
    {
    P3 = table2[i];
    delay(50);
    }

    for (i = 0; i < 8; i++)
    {
    P2 = table2[i];
    delay(50);
    }
    P0 = 0xff;
    P1 = 0xff;
    P3 = 0xff;
    P2 = 0xff;
    }

    void disp18() //Status 18 LED gradually lights up counterclockwise from P0.7 (turns off every 8 bits)
    {
    for (i = 0; i < 8; i++)
    {
    P0 = table3[i];
    delay(100);
    }
    P0 = 0xff;

    for (i = 0; i < 8; i++)
    {
    P1 = table2[i];
    delay(100);
    }
    P1 = 0xff;

    for (i = 0; i < 8; i++)
    {
    P3 = table2[i];
    delay(100);
    }
    P3 = 0xff;

    for (i = 0; i < 8; i++)
    {
    P2 = table2[i];
    delay(100);
    }
    P2 = 0xff;
    }

    void disp19() //Status 19 LED gradually lights up clockwise from P2.7, (cycle 2 times) and the speed will gradually increase
    {
    for (i = 0; i < 8; i++)
    {
    P2 = table3[i];
    delay(100);
    }

    for (i = 0; i < 8; i++)
    {
    P3 = table3[i];
    delay(100);
    }

    for (i = 0; i < 8; i++)
    {
    P1 = table3[i];
    delay(100);
    }

    for (i = 0; i < 8; i++)
    {
    P0 = table2[i];
    delay(100);
    }
    P0 = 0xff;
    P1 = 0xff;
    P3 = 0xff;
    P2 = 0xff;

    /*******************************/
    for (i = 0; i < 8; i++)
    {
    P2 = table3[i];
    delay(50);
    }

    for (i = 0; i < 8; i++)
    {
    P3 = table3[i];
    delay(50);
    }

    for (i = 0; i < 8; i++)
    {
    P1 = table3[i];
    delay(50);
    }

    for (i = 0; i < 8; i++)
    {
    P0 = table2[i];
    delay(50);
    }
    P0 = 0xff;
    P1 = 0xff;
    P3 = 0xff;
    P2 = 0xff;
    }

    void disp20() //Status 20 LED gradually lights up clockwise from P2.7 (turns off after every 8 bits)
    {
    for (i = 0; i < 8; i++)
    {
    P2 = table3[i];
    delay(100);
    }
    P2 = 0xff;

    for (i = 0; i < 8; i++)
    {
    P3 = table3[i];
    delay(100);
    }
    P3 = 0xff;

    for (i = 0; i < 8; i++)
    {
    P1 = table3[i];
    delay(100);
    }
    P1 = 0xff;

    for (i = 0; i < 8; i++)
    {
    P0 = table2[i];
    delay(100);
    }
    P0 = 0xff;
    }

    void disp21() //State 21 2 LEDs start to move up and down half a circle
    {
    for (i = 0; i < 8; i++)
    {
    P0 = table1[i];
    P2 = table1[i];
    delay(100);
    }
    P0 = 0xff;
    P2 = 0xff;

    for (i = 0; i < 8; i++)
    {
    P1 = table0[i];
    P3 = table1[i];
    delay(100);
    }

    for (i = 0; i < 8; i++)
    {
    P1 = table1[i];
    P3 = table0[i];
    delay(100);
    }
    P1 = 0xff;
    P3 = 0xff;

    for (i = 0; i < 8; i++)
    {
    P0 = table0[i];
    P2 = table0[i];
    delay(100);
    }
    }

    void disp22() //Installed state 22 2 LEDs move from top to bottom (cycle 5 times, and the frequency becomes faster, continue to cycle 16 times at the fastest, then cycle 5 times and then gradually reduce the frequency)
    {
    for (j = 0; j < 5; j++)
    {
    for (i = 0; i < 8; i++)
    {
    P0 = table1[i];
    P2 = table1[i];
    delay(tt);
    }
    P0 = 0xff;
    P2 = 0xff;

    for (i = 0; i < 8; i++)
    {
    P1 = table0[i];
    P3 = table1[i];
    delay(tt);
    }
    P1 = 0xff;
    P3 = 0xff;

    tt = tt – 10;
    }

    for (j = 0; j < 16; j++)
    {
    for (i = 0; i < 8; i++)
    {
    P0 = table1[i];
    P2 = table1[i];
    delay(20);
    }
    P0 = 0xff;
    P2 = 0xff;

    for (i = 0; i < 8; i++)
    {
    P1 = table0[i];
    P3 = table1[i];
    delay(20);
    }
    P1 = 0xff;
    P3 = 0xff;
    }

    tt = 20;
    for (j = 0; j < 5; j++)
    {
    for (i = 0; i < 8; i++)
    {
    P0 = table1[i];
    P2 = table1[i];
    delay(tt);
    }
    P0 = 0xff;
    P2 = 0xff;

    for (i = 0; i < 8; i++)
    {
    P1 = table0[i];
    P3 = table1[i];
    delay(tt);
    }
    P1 = 0xff;
    P3 = 0xff;

    tt = tt + 10;
    }

    tt = 70;

    }

    void disp23() //State 23 LED flashes alternately up and down
    {
    for (i = 0; i < 2; i++)
    {
    P0 = 0x00;
    P2 = 0x00;
    delay(1000);

    P0 = 0xff;
    P2 = 0xff;

    P1 = 0x00;
    P3 = 0x00;
    delay(1000);

    P1 = 0xff;
    P3 = 0xff;
    }
    }

    void disp24() //Status 24 LED flashes alternately left and right
    {
    P1 = 0xff;
    P3 = 0xff;
    P0 = 0xff;
    P2 = 0xff;

    for (i = 0; i < 2; i++)
    {
    P0 = 0x00;
    P1 = 0x00;
    delay(1000);

    P0 = 0xff;
    P1 = 0xff;

    P2 = 0x00;
    P3 = 0x00;
    delay(1000);
    P2 = 0xff;
    P3 = 0xff;
    }
    }

    void disp25() //Status 25 LED flashes alternately
    {
    for (i = 0; i < 5; i++)
    {
    P0 = 0xaa;
    P1 = 0xaa;
    P2 = 0xaa;
    P3 = 0xaa;
    delay(1000);

    P0 = ~P0;
    P1 = ~P1;
    P2 = ~P2;
    P3 = ~P3;
    delay(1000);
    }
    }

    void disp26() //State 26 2 LEDs start to move up and down a half circle (LED is not bright and water)
    {
    P0 = 0x00;
    P1 = 0x00;
    P2 = 0x00;
    P3 = 0x00;

    for (i = 0; i < 8; i++)
    {
    P0 = ~table1[i];
    P2 = ~table1[i];
    delay(200);
    }
    P0 = 0x00;
    P2 = 0x00;

    for (i = 0; i < 8; i++)
    {
    P1 = ~table0[i];
    P3 = ~table1[i];
    delay(200);
    }

    for (i = 0; i < 8; i++)
    {
    P1 = ~table1[i];
    P3 = ~table0[i];
    delay(200);
    }
    P1 = 0x00;
    P3 = 0x00;

    for (i = 0; i < 8; i++)
    {
    P0 = ~table0[i];
    P2 = ~table0[i];
    delay(200);
    }
    }

    void disp27() //State 27 gradually turn on the LEDs of P2 and P1 clockwise, and then turn on the LEDs of P0 and P3 clockwise
    {
    P0 = 0xff;
    P1 = 0xff;
    P2 = 0xff;
    P3 = 0xff;

    for (j = 0; j < 2; j++)
    {
    for (i = 0; i < 8; i++)
    {
    P2 = table3[i];
    P1 = table3[i];
    delay(100);
    }
    P2 = 0xff;
    P1 = 0xff;

    for (i = 0; i < 8; i++)
    {
    P0 = table2[i];
    P3 = table3[i];
    delay(100);
    }
    P0 = 0xff;
    P3 = 0xff;
    }
    }

    void disp28() //State 28 P1, P2 and P0, P3 flash alternately
    {
    for (i = 0; i < 2; i++)
    {
    P1 = 0x00;
    P2 = 0x00;
    P0 = 0xff;
    P3 = 0xff;
    delay(1000);

    P1 = 0xff;
    P2 = 0xff;
    P0 = 0x00;
    P3 = 0x00;
    delay(1000);
    }
    P1 = 0xff;
    P2 = 0xff;
    P0 = 0xff;
    P3 = 0xff;
    }

    void disp29() //State 29 gradually turn on the LEDs of P2 and P1 clockwise, then turn off the LEDs clockwise, then turn on the LEDs of P0, P3 clockwise, and then turn off clockwise
    {
    P0 = 0xff;
    P1 = 0xff;
    P2 = 0xff;
    P3 = 0xff;

    for (j = 0; j < 2; j++)
    {
    for (i = 0; i < 8; i++)
    {
    P2 = table3[i];
    P1 = table3[i];
    delay(100);
    }

    for (i = 0; i < 9; i++)
    {
    P2 = table5[i];
    P1 = table5[i];
    delay(100);
    }

    for (i = 0; i < 8; i++)
    {
    P0 = table2[i];
    P3 = table3[i];
    delay(100);
    }

    for (i = 0; i < 9; i++)
    {
    P0 = table4[i];
    P3 = table5[i];
    delay(100);
    }
    }
    delay(200);
    }

    void disp30() //State 30 gradually turn on the LEDs of P2 and P1 counterclockwise, and then turn on the LEDs of P0 and P3 counterclockwise after it is off
    {
    P0 = 0xff;
    P1 = 0xff;
    P2 = 0xff;
    P3 = 0xff;

    for (j = 0; j < 2; j++)
    {
    for (i = 0; i < 8; i++)
    {
    P2 = table2[i];
    P1 = table2[i];
    delay(100);
    }
    P2 = 0xff;
    P1 = 0xff;

    for (i = 0; i < 8; i++)
    {
    P0 = table3[i];
    P3 = table2[i];
    delay(100);
    }
    P0 = 0xff;
    P3 = 0xff;
    }
    }

    void disp31() //State 31 gradually turn on the LEDs of P2 and P1 counterclockwise, then turn off the LEDs counterclockwise, then turn on the LEDs of P0, P3 counterclockwise, and then turn them off counterclockwise
    {
    P0 = 0xff;
    P1 = 0xff;
    P2 = 0xff;
    P3 = 0xff;

    for (j = 0; j < 2; j++)
    {
    for (i = 0; i < 8; i++)
    {
    P2 = table2[i];
    P1 = table2[i];
    delay(100);
    }

    for (i = 0; i < 9; i++)
    {
    P2 = table4[i];
    P1 = table4[i];
    delay(100);
    }

    for (i = 0; i < 8; i++)
    {
    P0 = table3[i];
    P3 = table2[i];
    delay(100);
    }

    for (i = 0; i < 9; i++)
    {
    P0 = table5[i];
    P3 = table4[i];
    delay(100);
    }
    }
    delay(200);
    }

    void disp32() //Status 32 LED gradually lights up from top to bottom, and then gradually goes out from bottom to top
    {
    for (i = 0; i < 8; i++)
    {
    P0 = table3[i];
    P2 = table3[i];
    delay(100);
    }

    for (i = 0; i < 8; i++)
    {
    P1 = table2[i];
    P3 = table3[i];
    delay(100);
    }

    for (i = 0; i < 9; i++)
    {
    P1 = table5[i];
    P3 = table4[i];
    delay(100);
    }

    for (i = 0; i < 9; i++)
    {
    P0 = table4[i];
    P2 = table4[i];
    delay(100);
    }
    }

    void disp33() //Status 33 LED starts to light up from left to right (until all on), and then goes off from the left and right sides (until all are off)
    {
    for (i = 0; i < 8; i++)
    {
    P0 = table2[i];
    P1 = table2[i];
    delay(100);
    }

    for (i = 0; i < 8; i++)
    {
    P2 = table3[i];
    P3 = table2[i];
    delay(100);
    }
    delay(500);

    for (i = 0; i < 9; i++)
    {
    P2 = table4[i];
    P3 = table5[i];
    P1 = table4[i];
    P0 = table4[i];
    delay(100);
    }
    delay(300);
    }

    void disp34() //Status 34 LED lights up from left to right (until all lights up), and then goes out from the middle to left and right
    {
    for (i = 0; i < 8; i++)
    {
    P2 = table2[i];
    P3 = table3[i];
    delay(100);
    }

    for (i = 0; i < 8; i++)
    {
    P0 = table3[i];
    P1 = table3[i];
    delay(100);
    }
    delay(500);

    for (i = 0; i < 9; i++)
    {
    P2 = table5[i];
    P3 = table4[i];
    P1 = table5[i];
    P0 = table5[i];
    delay(100);
    }
    delay(300);
    }

    void disp35() //State 35 Starting from P2.7 and P1.7, rotate clockwise at the same time until the LEDs are all on
    {
    for (i = 0; i < 8; i++)
    {
    P2 = table3[i];
    P1 = table3[i];
    delay(100);
    }

    for (i = 0; i < 8; i++)
    {
    P3 = table3[i];
    P0 = table2[i];
    delay(100);
    }
    }

    void disp36() //State 36 Starting from P0.7 and P3.1, rotate counterclockwise at the same time, until the LEDs are all on
    {
    for (i = 0; i < 8; i++)
    {
    P0 = table3[i];
    P3 = table2[i];
    delay(100);
    }

    for (i = 0; i < 8; i++)
    {
    P1 = table2[i];
    P2 = table2[i];
    delay(100);
    }
    }

    void disp37() //State 37 2 LEDs move from top to bottom, and light up the bottom 2 LEDs, then 2 LEDs go back from bottom to top, and 4 LEDs (2 LEDs up and down) move back and forth again at the same time
    {
    for (i = 0; i < 8; i++)
    {
    P0 = table1[i];
    P2 = table1[i];
    delay(100);
    }
    P0 = 0xff;
    P2 = 0xff;

    for (i = 0; i < 8; i++)
    {
    P1 = table0[i];
    P3 = table1[i];
    delay(100);
    }

    for (i = 0; i < 8; i++)
    {
    P1 = table7[i];
    P3 = table6[i];
    delay(100);
    }
    P1 = 0x7f;
    P3 = 0xfe;

    for (i = 0; i < 8; i++)
    {
    P0 = table0[i];
    P2 = table0[i];
    delay(100);
    }

    for (i = 0; i < 8; i++)
    {
    P0 = table1[i];
    P2 = table1[i];
    P1 = table1[i];
    P3 = table0[i];
    delay(200);
    }

    for (i = 0; i < 8; i++)
    {
    P0 = table0[i];
    P1 = table0[i];
    P2 = table0[i];
    P3 = table1[i];
    delay(200);
    }
    P0 = 0xff;
    P1 = 0xff;
    P2 = 0xff;
    P3 = 0xff;
    }

    void disp38() //Status 38 gradually turn on the LEDs of P2 and P1 clockwise, and then turn on the LEDs of P0, P3 clockwise
    {
    P0 = 0xff;
    P1 = 0xff;
    P2 = 0xff;
    P3 = 0xff;

    for (j = 0; j < 2; j++)
    {
    for (i = 0; i < 8; i++)
    {
    P2 = table3[i];
    P1 = table3[i];
    delay(100);
    }
    P2 = 0xff;
    P1 = 0xff;

    for (i = 0; i < 8; i++)
    {
    P0 = table2[i];
    P3 = table3[i];
    delay(100);
    }
    P0 = 0xff;
    P3 = 0xff;
    }
    }

    void disp39() //State 39 P1, P3 LED (lower part) are always on, the upper part of the LED expands outward, and then flashes 3 times
    {
    P1 = 0x00;
    P3 = 0x00;

    for (i = 0; i < 8; i++)
    {
    P0 = table3[i];
    P2 = table3[i];
    delay(150);
    }

    for (i = 0; i < 8; i++)
    {
    P0 = table3[i];
    P2 = table3[i];
    delay(300);
    }

    for (i = 0; i < 4; i++)
    {
    P0 = ~P0;
    P2 = ~P2;
    delay(300);
    }
    delay(1000);
    }

    void disp40() //State 40 LEDs are turned off at the same time from P3.0 and P0.7 counterclockwise until all the LEDs are turned off
    {
    for (i = 0; i < 9; i++)
    {
    P3 = table4[i];
    P0 = table5[i];
    delay(100);
    }

    for (i = 1; i < 9; i++)
    {
    P2 = table4[i];
    P1 = table4[i];
    delay(100);
    }
    delay(300);
    }

    void disp41() //Status 41 LED turns off at the same time clockwise from P2.7 and P1.7 until all are off
    {
    for (i = 0; i < 9; i++)
    {
    P2 = table5[i];
    P1 = table5[i];
    delay(100);
    }

    for (i = 1; i < 9; i++)
    {
    P0 = table4[i];
    P3 = table5[i];
    delay(100);
    }
    delay(300);
    }

    void main()
    {
    while (1)
    {
    disp22(); //Installation 22 2 LEDs move from top to bottom (cycle 5 times, and the frequency becomes faster, continue to cycle 16 times at the fastest, then cycle 5 times and then gradually reduce the frequency)
    disp0(); //State 0 all LEDs flash 3 times
    disp1(); //State 1 LED turns clockwise
    disp2(); //State 2 LED turns counterclockwise
    disp3(); //State 3 4 LEDs move 1/4 turn clockwise and counterclockwise at the same time
    disp4(); //State 4 2 LEDs move a half circle clockwise at the same time
    disp5(); //State 5 2 LEDs move half a circle counterclockwise at the same time
    disp6(); //Status 6 LED lights up gradually from top to bottom (half lit and half off)
    disp7(); //Status 7 LED gradually lights up from bottom to top (until all lights up)
    disp0(); //State 0 all LEDs flash 3 times
    disp8(); //The 4 LEDs of 8 intermittent state 8 are on and rotate counterclockwise
    disp9(); //The 4 LEDs in the state 9 intermittently with 8 bars light up, and then light up gradually counterclockwise (until all light up)
    disp10(); //State 10 from all the LEDs on to all off (the 4 LEDs with 8 intervals start to turn off counterclockwise)
    disp11(); //The 4 LEDs in state 11 intermittently turn on and rotate clockwise
    disp12(); //The 4 LEDs with 8 intermittent intervals light up, and then light up gradually clockwise (until all light up)
    disp13(); //State 13 is from all the LEDs on to all off (the 4 LEDs with 8 intervals start to turn off clockwise)
    disp14(); //State 14: LED off to full light (lighting up from P0.0, P1.0, P2.0, P3.7)
    disp15(); //State 15 from all LEDs on to all off (gradually extinguished from P0.7, P1.7, P2.7, P3.0)
    disp16(); //State 16 LED lights flash alternately (the frequency becomes slower and faster)
    disp17(); //State 17 LED gradually lights up counterclockwise from P0.7, and the speed will gradually increase
    disp18(); //Status 18 LED gradually lights up counterclockwise starting from P0.7 (turns off after every 8 bits)
    disp19(); //Status 19 LED gradually lights up clockwise from P2.7, (cycle 2 times) and the speed will gradually increase
    disp20(); //Status 20 LED gradually lights up clockwise from P2.7 (turns off every 8 bits)
    disp21(); //State 21 2 LEDs start to move up and down half a circle
    disp22(); //Installation 22 2 LEDs move from top to bottom (cycle 5 times, and the frequency becomes faster, continue to cycle 16 times at the fastest, then cycle 5 times and then gradually reduce the frequency
    disp23(); //State 23 LED flashes alternately up and down
    disp39(); //State 39 P1, P3 LED (lower part) are always on, the upper part of the LED expands outward, and then flashes 3 times
    disp24(); //State 24 LED flashes alternately left and right
    disp25(); //Status 25 LED flashes alternately
    disp8(); //The 4 LEDs of 8 intermittent state 8 are on and rotate counterclockwise
    disp9(); //The 4 LEDs in the state 9 intermittently with 8 bars light up, and then light up gradually counterclockwise (until all light up)
    disp10(); //State 10 from all the LEDs on to all off (the 4 LEDs with 8 intervals start to turn off counterclockwise)
    disp26(); //State 26 2 LEDs start to move up and down half a circle (LED is not bright and running water)
    disp27(); //State 27 gradually turn on the LEDs of P2 and P1 clockwise, and then turn on the LEDs of P0 and P3 clockwise
    disp28(); //State 28 P1, P2 and P0, P3 flash alternately
    disp38(); //State 38 gradually turn on the LEDs of P2 and P1 clockwise, and then turn on the LEDs of P0, P3 clockwise
    disp29(); //State 29 gradually turn on the LEDs of P2 and P1 clockwise, then turn off the LEDs clockwise, then turn on the LEDs of P0, P3 clockwise, and then turn off clockwise
    disp30(); //State 30 gradually turn on the LEDs of P2 and P1 counterclockwise, and then turn on the LEDs of P0, P3 counterclockwise after it is off
    disp31(); //State 31 gradually turn on the LEDs of P2 and P1 counterclockwise, then turn off the LEDs counterclockwise, then turn on the LEDs of P0, P3 counterclockwise, and then turn off counterclockwise
    disp32(); //Status 32 LED lights up gradually from top to bottom, and then turns off gradually from bottom to top
    disp33(); //Status 33 LED lights up from left to right (until all on), and then goes out from the left and right sides (until all off)
    disp37(); //State 37 2 LEDs move from top to bottom, and light up the bottom 2 LEDs, then the 2 LEDs go back from bottom to top, and 4 LEDs (upper and lower each 2 LEDs) Move back and forth again
    disp36(); //State 36 Starting from P0.7 and P3.0, rotate counterclockwise at the same time, until the LEDs are all on
    disp40(); //Status 40 LEDs are turned off at the same time from P3.0 and P0.7 counterclockwise until all the LEDs are turned off
    disp35(); //Status 35 Starting from P2.7 and P1.7, rotate clockwise at the same time until the LEDs are all on
    disp41(); //Status 41 LED starts from P2.7 and P1.7 and goes out clockwise at the same time until they all go out
    disp34(); //State 34 LED lights up from left to right (until all lights up), and then goes out from the middle to left and right
    disp28(); //State 28 P1, P2 and P0, P3 flash alternately
    }
    }

Leave a Reply to lui_goughCancel reply