標(biāo)題: 心型流水燈程序 [打印本頁]

作者: 風(fēng)鈴草f    時(shí)間: 2020-11-21 19:17
標(biāo)題: 心型流水燈程序
  1. #include<reg52.h>
  2. #include<intrins.h>
  3. #define uint unsigned int
  4. void delay(uint z);
  5. void hy1();
  6. void hy2();
  7. void hy3();
  8. void main()
  9. {
  10.         while(1)
  11.         {
  12.                 hy1();
  13.                 hy2();
  14.                 hy3();
  15.         }
  16.        
  17. }
  18. void delay(uint z)
  19. {
  20.   uint i,j;
  21.         for (i=0;i<z;i++)
  22.              for(j=0;j<120;j++);
  23. }
  24. void hy1()//逆時(shí)針流水燈
  25. {
  26.         char h;
  27.         P3=0x7F;
  28.         delay(1000);
  29.         for(h=0;h<7;h++)
  30.         {
  31.                 P3=(P3>>1);
  32.           delay(1000);
  33.         }
  34.         P2=0x7F;
  35.         delay(1000);
  36.         for(h=0;h<7;h++)
  37.         {
  38.                 P2=(P2>>1);
  39.           delay(1000);
  40.         }
  41.         P1=0x7F;
  42.         delay(1000);
  43.         for(h=0;h<7;h++)
  44.         {
  45.                 P1=(P1>>1);
  46.           delay(1000);
  47.         }
  48.         P0=0x7F;
  49.         delay(1000);
  50.         for(h=0;h<7;h++)
  51.         {
  52.                 P0=(P0>>1);
  53.           delay(1000);
  54.         }
  55.         P3=0XFF;
  56.         P2=0XFF;
  57.         P1=0XFF;
  58.         P0=0XFF;
  59. }
  60. void hy2()//千里來相會(huì)
  61. {
  62.         char h;
  63.         P3=0x7F;
  64.         P0=0XFE;
  65.         delay(1000);
  66.         for(h=0;h<7;h++)
  67.         {
  68.                 P3=(P3>>1);
  69.                 P0=(P0<<1);
  70.           delay(1000);
  71.         }
  72.         P2=0x7F;
  73.         P1=0XFE;
  74.         delay(1000);
  75.         for(h=0;h<7;h++)
  76.         {
  77.                 P2=(P2>>1);
  78.                 P1=(P1<<1);
  79.           delay(1000);
  80.         }
  81.         P3=0XFF;
  82.         P2=0XFF;
  83.         P1=0XFF;
  84.         P0=0XFF;
  85. }
  86. void hy3()//全亮
  87. {
  88.         P3=0X00;
  89.         P2=0X00;
  90.         P1=0X00;
  91.         P0=0X00;
  92. }
復(fù)制代碼







歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1