Blue Bridge Cup race preparation [MCU] travel diary series of LED light water

table of Contents

1 Introduction
2, cyclic displacement of the advantages and disadvantages
3. Improvement Strategies
4, a light pattern to achieve water

1 Introduction

  Saying that the lighting is like programming microcontrollers run Hello World, like the circulation of water lights Hello world, hello Ward that it's that simple everyone would run, not go into details, today to talk about on CT107D "cycle run Hello World" it.

  Today's task list that is very clear, do it.
  
  
2, cyclic displacement of the advantages and disadvantages

  I dare say, you run the first water lights must be used to achieve the cycle of displacement, like this:

 P2=0x80;P0=0x7f;
 Delay1000ms();
 while(1)
 {
  for(i=0;i<7;i++)
  {
   P0=_cror_(P0,1);
   Delay1000ms();
  }
  for(i=0;i<7;i++)
  {
   P0=_crol_(P0,1);
   Delay1000ms();
  }
 }

  Indeed it is, the advantage is clear, easy to understand, it is public; the downside, read the Blue Bridge Cup third preliminary round on the obvious question: Since the for loop stubborn temper, it does not finish the lap will not stop, so resulting in uncontrolled flow direction.

 So with the following modifications.
  
  
3. Improvement Strategies

  Independent key mode by the control water flow direction S4, the lower portion of FIG post codes can understand a series ado.

Here Insert Picture Description
  
  
4, a light pattern to achieve water

  Finished body heat, please right out of today's hero, description of the problem:

(1).第一次循环为L1-L8流水
(2).第二次循环为L1L2-L2L3-...-L7L8流水
(3).第三次循环为L1L2L3-L2L3L4-...-L6L7L8流水
...以此类推


Thinking:
  ①: Throughout the implementation process, a total of eight cycles (mode from 0-7), a total of N cycles N lamp is lit;
  ②: N number of times and the first cycle, the required displacement (Times) to 7-mode.

Ever: This question is a model we simplified to:

(1).第一次循环
1111 1110->1111 1101->1111 1011......
(2).第二次循环
1111 1100->1111 1001->1111 0011......
(3).......


Law not found, the first N cycles put the N LED tied movement, i.e.

  Take a second example water, and for the first time in a point that:

 1. The initial value is not the same, the first initial value is ~ (0x01), the second is ~ (0x01 | 0x02); so
 2 cycles are not the same, the first (mode = 0 when) Shift 7, a second (mode = 1 when) shifted 6 times N times (mode = N-1) 7-mode shift times

So with the following algorithm:

Here Insert Picture Description
For two nested loop control result is an initial value P0 of each of the water.

  
  
  It's done. Complete source code venue to [ my github ] download.

Released four original articles · won praise 7 · views 451

Guess you like

Origin blog.csdn.net/weixin_43894786/article/details/105175813