登录|立即注册|使用QQ帐号登录
论坛 > 51单片机
发帖|
看2623|回0|收藏
楼主 ID:157563 只看他
2016-12-25 19:09
来回流水灯制作
0.png

代码:

  1. #include<reg51.h>
  2. #define uint unsigned int
  3. #define uchar unsigned char
  4. void delay(uint z)
  5. {
  6.         uint x,y;
  7.         for(x=z;x>0;x--)
  8.                 for(y=125;y>0;y--);
  9. }
  10. uchar code tab[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd};
  11. void main()
  12. {
  13.         uchar i;
  14.         while(1)
  15.         {
  16.                 for(i=0;i<14;i++)
  17.                 {
  18.                         P2=tab[i];
  19.                         delay(500);
  20.                 }
  21.         }
  22. }
  23. /*#include <reg51.h>
  24. #define uchar unsigned char
  25. #define uint unsigned int
  26. uchar zhancun;
  27. void delay(uint x)
  28. {
  29.   uchar t;
  30.   while(x--)  for(t = 0; t<120; t++);
  31. }
  32. void main( )
  33. {  
  34.   uchar i;
  35.   while(1)
  36.   {                 
  37.           zhancun = 0x01;
  38.         for(i = 0; i < 8; i++)
  39.         {
  40.                 P2 = ~zhancun;
  41.                 delay(200);
  42.                 zhancun <<= 1;                       
  43.         }
  44.         zhancun = 0x80;
  45.         for( i = 0; i < 8;i++)
  46.         {
  47.                 P2 = ~zhancun;
  48.                 delay(200);
  49.                 zhancun >>= 1;       
  50.         }
  51.   }
  52. }
  53. #include <reg51.h>
  54. #define uchar unsigned char
  55. #define uint unsigned int
  56.         //uchar k;
  57.    uint a;
  58. void delay(uint x)
  59. {
  60.   uchar t;
  61.   while(x--)  for(t = 0; t<120; t++);
  62. }
  63. void main()
  64. {uchar k;
  65.                 while(1)
  66.                 {
  67.     a=0x7f;
  68.                 for(k=0;k<7;k++)
  69.                 {
  70.                         P2=a;
  71.                         delay(500);       
  72.                         a=(a>>1)|0x80;
  73.                 //        a=a|0x80;
  74.                
  75.                 }  
  76.                 a=0xfe;
  77.                 for(k=0;k<7;k++)
  78.                 {
  79.                         P2=a;
  80.                         delay(500);       
  81.                         a=(a<<1)|0x01;
  82.                 //        a=a|0x01;
  83.                
  84.                 }
  85.         }
  86. }
  87. #include<reg51.h>
  88. #include<intrins.h>
  89. #define uint unsigned int
  90. #define uchar unsigned char
  91. void delay(uint z)
  92. {
  93.         uint x,y;
  94.         for(x=100;x>0;x--)
  95.                 for(y=z;y>0;y--);
  96. }
  97. void main()
  98. {
  99.         uchar i;
  100.         for(;;)
  101.         {
  102.                 P2=0xfe;
  103.                 for(i=0;i<7;i++)
  104.                         {
  105.                                 delay(500);P2=_crol_(P2,1);
  106.                                
  107.                         }
  108.                 P2=0x7f;
  109.                 for(i=0;i<7;i++)
  110.                         {
  111.                                 delay(500);P2=_cror_(P2,1);
  112.                                
  113.                         }
  114.         }
  115. }*/



附件列表

实验4.zip (2016-12-25 19:08 上传)

34.82 KB, 下载次数: 8, 下载积分: 黑币 -5

流水灯

51黑电子论坛

Powered by Discuz! X3.1

首页|标准版|触屏版|电脑版