找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 2651|回復(fù): 0
打印 上一主題 下一主題
收起左側(cè)

單片機來回流水燈制作 帶仿真和源程序

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:157563 發(fā)表于 2016-12-25 19:09 | 只看該作者 |只看大圖 回帖獎勵 |倒序瀏覽 |閱讀模式
來回流水燈制作


  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. }*/
復(fù)制代碼



實驗4.zip

34.82 KB, 下載次數(shù): 8, 下載積分: 黑幣 -5

流水燈

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機教程網(wǎng)

快速回復(fù) 返回頂部 返回列表