Proteus +keilC51 to make bagua matrix

preface

This paper demonstrates the process of making a bagua array with Keil C51 + Proteus.

At the end of this article, engineering documents and other information are available. It is recommended to read this article in conjunction with Keil Project.

The effect

composition

MCU

Due to the limitation of Proteus and the author’s computer performance, stM32 model runs very slowly, so 51 single chip microcomputer is used here to complete this simple task. In order to avoid the interference of eight trigrams and yin-yang fish, two independent 51 chips are used.

latch

In order to achieve a set of pins to control multiple leds and lattice, a latch is used here. The use method is very simple, OE is set to 0, when LE pin input high level, Q[0 7]=D[0 7], when LE pin input low level, Q[0 7] is locked.

According to

Because it is in Proteus, the single chip pin is directly connected to the positive pole of LED, and logic 1 is lit up. In fact, 51 single chip may not have enough driving ability to light up LED. Generally, the pin is connected to the negative pole, the positive pole is connected to the pull resistor, and logic 0 is lit up.

There are 16 pins in total, 8 to control the NTH line and 8 to control the N point in a line. The specific operation can be experimented by yourself. All the above models can be found and placed in Proteus.

Yin and Yang fish

Arrange the LED according to the order of bagua array. Because the eyes of the Yin and Yang fish are opposite to the surrounding color, the middle circle is set as a group, and the inner and outer circles are set as a group.

Create project 51, add predefined, here choose P2.0, P2.1 connect two LE pins, and define the array and sequence number, convenient for the following loop.

sbit Elock=P2^0; // sbit Llock=P2^1; / / control latch uchar code of Yin and Yang Yang [8] = {x1e x87 0, 0 x0f, 0, 0 x3c, 0 x78, 0 xf0, 0 xe1, 0 xc3}; Uchar code eye [8] = {0 xa5, 0 x4b, 0 x96, 0 x2d, 0 x5a, 0 xb4, 0 x69, 0 xd2}; uchar i=1;Copy the code

Manually add the delay function, which in this case is about 1 millisecond

Void delay(unsigned int num) // delay function {unsigned x, y; for(x=num; x>0; x--) for(y=120; y>0; y--); }Copy the code

LED control function, according to the order of I read two arrays, let I in 0 7 cycle, you can achieve the effect of Yin and Yang fish in rotation.

void circle() { Llock=1; P1= Yang [I]; P1= Yang [I]; Llock=0; Elock=1; P1=eye[i]; Elock=0; i++; If (I ==8) // array loop, I =0; }Copy the code

In the main function, first let the LED off, and then start the cycle.

void main(void) { P1 = 0xff; // P1=eye[2]; // Start position, you can try other positions; Elock=0; P1=yang[2]; Llock=1; Llock=0; while(1) { circle(); delay(999); }}Copy the code

At this point, the bagua array is ready, click start simulation, you can display the circular effect.

wuzhuang

Eight latches are required for eight lattice arrays. P0 is selected as le control for eight latches. Note that P0 of this 51 microcontroller needs to be connected to a pull resistor to output signals.

Here, port P2 is used to control which line is displayed in the lattice, and port P1 is used to control which point is displayed. When the loop reaches one lattice, the latches of other lattice are closed and locked, and then control the display content. Define eight arrays and some variables.

Uchar code Qian [8] = {0 x00 to 0 x00 to 0 XFF, 0 x00 to 0 XFF, 0 x00 to 0 XFF, 0 x00}; Uchar code Xun [8] = {x24 x48 0 x10, 0, 0, 0 x92, 0 x49, 0 x04, 0 x12, 0 x08}; Uchar code Kan [8] = {0 x00 to 0 x00 to 0 xe7, 0 x00 to 0 XFF, 0 x00 to 0 xe7, 0 x00}; Uchar code Gen [8] = {x24 x48 0 x10, 0, 0, 0 x82, 0 x41, 0 x04, 0 x12, 0 x08}; Uchar code Kun [8] = {0 x00 to 0 x00 to 0 xe7, 0 x00 to 0 xe7, 0 x00 to 0 xe7, 0 x00}; Uchar code Zhen [8] = {x48 0 x10, 0, 0 x20, 0 x82, 0 x41, 0 x24, 0 x12, 0 x08}; Uchar code Li [8] = {0 x00 to 0 x00 to 0 XFF, 0 x00 to 0 xe7, 0 x00 to 0 XFF, 0 x00}; Uchar code Dui [8] = {x48 0 x10, 0, 0 x20, 0 x92, 0 x49, 0 x24, 0 x12, 0 x08}; uchar i=0,j=1; uint l=0;Copy the code

Variable I is the symbol of the number of rows, j is the symbol of the next lattice and the grouping lattice, and L is the variable that records the time in the main function. Due to the limitation of Proteus or hardware performance, the visual effect of the eight-lattice cycle is very poor, so the set logic is four diagonal lattice display, and after a period of time l, the other four diagonal lattice display.

Void ddelay(uint num) {uint x,y; for(x=num; x>0; x--) for(y=45; y>0; y--); }Copy the code

Manual delay, when the visual effect is not ideal can try to change the Y value.

The following is one of the eight lattice corresponding control functions, the others are shown in the project, j represents the label of the next lattice, and judgment is called in the later switch.

void bagua_Q() { P2=1<<i; P1=~Qian[i]; ddelay(1); i++; if(i>7){i=0; j=3; }}Copy the code

The whole cycle function, each time after the first refresh to determine which lattice.

void bagua_circle() { P1=0xff; P2=0x00; switch(j) { case 1:P0=0x01; bagua_Q(); break; case 2:P0=0x02; bagua_X(); break; case 3:P0=0x04; bagua_K(); break; case 4:P0=0x08; bagua_G(); break; case 5:P0=0x10; bagua_KU(); break; case 6:P0=0x20; bagua_Z(); break; case 7:P0=0x40; bagua_L(); break; case 8:P0=0x80; bagua_D(); break; }}Copy the code

Bagua circle() is called inside the main function loop; The eight trigrams array is displayed circulatedly, and only four hexagrams [Gan Kun Kun li] or [Xungen zhen du] can be seen at the same time. At the same time, the L variable is timed, and when the corresponding value is exceeded, one group can be switched, and the single group display time can be changed by changing the corresponding value.

void main(void) { P2=0x00; ddelay(1); while(1) { P2=0x00; bagua_circle(); l++; if(l>999) { l=0; if(j==2) { j=1; } else if(j==1) { j=2; }}}}Copy the code

This bagua array is a part of the author’s 51 MCU big homework, the whole file has been updated to the web disk.

MCU operation – Taiji bagua array

At this point, the Taiji Bagua matrix is completed. One item for a faster one such as STM32: A plus-one item for a PCB design (●’◡’●)

Download link

Link: https://pan.baidu.com/s/1oXmYgVkh0gdzHd46MvwZ4Q extraction code: tEGO copy after this paragraph open baidu cloud mobile phone App, operation more convenientCopy the code