Complete optical cube Parsing

Source: Internet
Author: User

Reprinted please indicate the source: http://blog.csdn.net/ruoyunliufeng/article/details/37903899


This 4*4*4 tri-color Optical cube is a small project I made when I was a beginner in MCU. It is very suitable for beginners of single-chip microcomputer and C language, and the effect is very dazzling. There are a lot of irregularities in this code today, but as the hardware has been given away, it is impossible to continue debugging. I hope my friends will take it as a warning. This article mainly aims to let everyone know how it works and how it works. More importantly, it is important to know why it works.

Effect display: http://v.youku.com/v_show/id_XNjAyMTkwODE2.html


I. Summary


What is optical cube? In fact, the light cube is to fold the dot matrix and then stand it up. A beginner single-chip microcomputer can follow this idea: light a small light-> light a water light-> dot matrix display-> light a light cube. There is a connection between them. Let me talk about the principles below.

Light up a small light: Nothing to say, control an IO to a high or low level.

Light up the flow light: This is also simple, that is, to control the level of several Io.

Dot matrix display: this seems difficult, but it is not difficult. The core is to scan the data of the model first, and then display a column first, the next column is displayed in a very short time, and the entire dot matrix is displayed. Due to the temporary effect of human eyes, it will look static. In fact, LCD is similar to it. This is not to mention for the moment.

Light up the light Cube: Why do I say that the light cube is a lattice folded and then stand up again? Sell a customs gateway first. You will understand it after you finish the hardware. In fact, the principle is similar to that of dot matrix.


Ii. Hardware


Let's talk about it first. At that time, because the circuit design was really simple and didn't draw a schematic diagram, we just took the cave plate and seam it directly. You can draw a picture first, but you don't actually need to draw a picture.

1. Single Chip Microcomputer

It is recommended to choose 51 series of STC12C5A60S2-35I-PDIP40 single-chip microcomputer, because the 89C51 output current is insufficient to add three-level Tube expansion flow, I was doing so, bring me a lot of trouble, but also not beautiful. I hope my friends will learn the lessons. I won't talk about how to build the smallest system.

2. Two-color LED

Two-Color LEDs have three pins. One pin is the other two are the LED pins. Three colors are displayed. In fact, it is completely possible to change the color of the LED is that there are four pins, the effect is more dazzling, the microcontroller pin is enough. It's just that you don't have time to play now.

3. The dot matrix turns into a light place

Now let's talk about how to fold the dot matrix and then stand it up. Here I am posting a few images. Let's take a look at the production process. I think you can have a deep understanding of it.


After reading the picture above, you should understand why I said so. Okay. Let me talk about how to do it.


This is the most basic element. We need to make 16 of them. The Dongdong anode is connected, and the cathode is introduced and connected to the next unit.

A vertical face is like this.

The four faces are connected according to the first figure.


Iii. Software


1. Software Framework

To tell the truth, when I was doing something, I only knew that each single-chip microcomputer program had a while (1 ). Haha, the light cube program I wrote mainly loops through various practical effects in while (1.

Void main () {While (1) {hongbegin (); // red from Bright to dark hongend (); // red from dark to bright P2 = 0xff; // turn P2 off to avoid affecting the effect of the following yellow light huangbegin (); // yellow breathing light huangend (); chengsedeng (); // orange light huangsebianhongse (); // yellow to red miansheng (); // The face is raised by mianjiang (); // The face is dropped by mianzuodaoyou (); // The face is left to the right; mianyoudaozuo (); // shuidi () from the right to the left of the surface; // imitate the water drop effect (falling from the mouth) luoxuansheng (); // spiral up luoxuanjiang (); // screw down pingheng (); // balance wood yinxiangshang (); // audio effect up and down yinxiangzuo (); // audible effect left and right sxingsaomian (); // S-shaped scanning surface litixuanzhuan (); // stereo rotating zuoshangliang (); // sijiaoneishou () is highlighted from the top left corner to the whole corner (); // shuidijiandong () is collected in the four corners (); // shuibo (); // FeiJi (); // flight chaojimali (); // super Mary chengsedeng (); // orange light huangbegin (); // yellow breathing light huangend (); hongend (); // red light hongbegin (); // red light from Bright to dark jiesu (); // end function }}


2. Breathing lights

It is said to be a breathing lamp, which is gradually ON and OFF. It is actually a PWM when it is said to be so tall, and the ground is to control the conduction time in a cycle, the cycle's conduction time gradually increases, and naturally becomes brighter. Gradually decrease, and naturally become increasingly dark, and the path completely goes out. If you use stc12, it can be very simple, that is, a D/A conversion. Converts a digital signal to a analog signal. Of course, I didn't quite understand this yet. I directly used 89C52 and 52 without a D/A conversion chip. The software I used to simulate PWM is actually the principle of delay. The following is part of the implementation code.

/* P1 is yellow and P2 is red. P0 is the cathode */uchar code table [] = {// For breathing lights 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,18, 19,20, 21,22,, 99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117, 118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150 ,}; void delay (uint Z) {uint X, Y; For (x = 5; x> 0; X --) for (y = z; y> 0; Y --);} void hongbegin () // completely enable respiration destroy {int I; for (I = 0; I <140; I ++) {honglight2 (I );} p0 = 0x00; // the P2 = 0xff; P1 = 0xff;} void honglight2 (uchar num2) // from the light to the light (it can be understood that the light time is from the light to the short. From short to long) {uchar J; p0 = 0xff; // first, disable P0 P2 = 0x00; // open P2 J = table [num2]; delay (j); // latency (from short to long) p0 = 0x00; // open P0 and call it bright P2 = 0x00; delay (150-j ); // The latency ranges from long to short}


3. Code explanation

First of all, we know that an animation is played quickly by an image. This is also the principle that light cube relies on.


Unsigned char code tabp0 [] = {0xfe, 0xfd, 0xfb, 0xf7, 0xef, 0xdf, 0xbf, 0x7f}; // low-level scanning, only one line (one P0 port) of void mianjiang () {unsigned char code tabp2 [3] [8] = {// defines an array at a time. Store Data {0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff}, {0 x, 0x00, 0xff, 0xff, 0x00,0x00, 0xff, 0xff}, {0x00,0x00,0x00, 0xff, 0x00,0x00,0x00, 0xff},}; Int J, K, i; // define three variables for (j = 0; j <3; j ++) // Number of J images {for (k = 0; k <20; k ++) // K indicates the time for each image to exist. The larger the value of K, the longer the time for a single image to exist. {for (I = 0; I <8; I ++) // each image consists of eight frames. {P2 = 0xff; // This function and residual shadows are eliminated. // p0 = 1; p0 = tabp0 [I]; // retrieve the cathode P0 P2 = tabp2 [J] [I]; // extract the array anode p1 = 0xff; // disable P1 to avoid affecting the red effect ys (2 ); // depending on the temporary effect of the human eye .. Increase the entire lighting process and reduce the light to display stable images }}}}


All code and touch software have been packaged and uploaded.





Reference: modulus software source: http://user.qzone.qq.com/1323811540/blog/1376456811

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.