跑马灯

要求:。。。

连线:将P1口的八个端口依次接到八个灯上,提醒P1.7是高位,P1.0是低位

 1 #include<reg51.h>
 2 void delay(int k){
 3      int i=0,j=0;
 4      while(k--)
 5      {
 6      for(i;i<50;i++)
 7      {
 8         for(j;j<255;j++)
 9         {
10             
11         }
12      }
13
14      }
15      
16 }
17 void main(){
18         int n=0;
19         P1=0x01;
20         delay(5);
21         while(1)
22         {
23              if(n<=7)
24              {
25              P1=P1<<1;
26              delay(3000);
27              n++;
28              }
29              else
30              {
31               n=0;
32               P1=0x01;
33               delay(3000);
34              }
35         }
36 }

实验结果:能够实现一个简单在跑马灯的效果。

原文地址:https://www.cnblogs.com/dingxiaowei/p/3100961.html