找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2371|回复: 0
打印 上一主题 下一主题
收起左侧

单片机模拟霓虹灯控制器设计(40只光柱的动态显示)源程序

[复制链接]
跳转到指定楼层
楼主
ID:640283 发表于 2019-11-12 11:14 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
通过51单片机控制40只光柱的动态显示

霓虹灯作为夜幕下最常见、最闪亮的风景,是当代社会广泛应用的电子产品之一。本次实训拟运用所学的单片机原理及应用的基本知识,设计一模拟霓虹灯控制器,实现对40段LED光柱的动态显示和动态速度的人工控制。系统结构框图如图0-1所示:

二、设计任务

(罗列自己完成的任务项目)

1、按附件1硬件原理图,利用Altium Designer制作PCB版,3D图如附件2所示,焊接电路,实物图如附件3所示;

2、编写程序:根据读入的4位拨码开关的状态来控制40位LED光柱的不同显示方案,详细显示方案说明见附件4;

3、编写程序:由按键控制40位LED光柱的动态切换速度,并将表示该速度值的动态切换时间大小显示在2位数码管上。

4、在任何点亮方案的控制时,要维持两位数码管的正常显示;实时响应任何时刻按键、拨码的人工操作;并且使每次拨码状态的改变,从附件4方案规定的第一个显示状态开始显示。

5、编写程序:自选方案,①龟兔赛跑

                                                                                                    ②新龟兔赛跑

                                                                                                    ③花绽放的平铺

3、LED光柱的控制思路

要想达到对上述多个外设的实时控制功能,必须做到在较短时间内对所有外设都要控制一次,并要使对每个外设的控制时间不要过长,以免影响其他外设的实时控制效果(这里特别提醒必须妥善做好按键去抖动的处理),另外要设置每个外设控制程序的调用条件,以缩短主程序循环控制所有外设的时间周期,达到最好的实时控制效果。仔细斟酌并设计主程序及各外设控制程序,主程序流程参考如图6-2所示。


任务要求1
当拨码开关没有一位合上时,使光带的第一只发光管点亮。

任务要求2
当拨码开关的第一位合上时,使光带的第一、二、三只发光管点亮。

任务要求3
当拨码开关的第二位合上时,使光带的第一只发光管0.5S亮0.5S暗。

任务要求4

当拨码开关的第一、第二位合上时,使光带的第一、第二只发光管以当前设定速度交替点亮。


任务要求5
当拨码开关的第三位合上时,按当前设定速度使光带的第一、第二?第四十只发光管循环点亮,点亮第四十只后,蜂鸣器发声一下,再点亮第一只?,依次类推。

任务要求6
当拨码开关的第一、三位合上时,按当前设定速度递增循序点亮光带的第一、第二?第四十只发光管,点亮第四十只后,蜂鸣器发声一下,再按递减循序点亮第三十九、第三十八只?第一只发光管,依次类推。

任务要求7
当拨码开关的第二、三位合上时,按当前设定速度由两边向中央点亮光带发光管,即由第一和第四十只发光管亮至第二和第三十九只发光管亮?第二十和第二十一只发光管亮,再至第一和第四十只亮?,依次类推。

任务要求8

当拨码开关的第一、二、三位合上时,按当前设定速度由两边向中央、再由中央向两边点亮光带发光管,即由第一和第四十只发光管亮至第二和第三十九只发光管亮?第二十和第二十一只发光管亮,再至第十九和第二十二只亮?,依次类推。


任务要求9

当拨码的第二、四位合上时,点亮方式同方案5,点亮速度由快(点亮第一只)变慢(点亮第四十只时)再变快(点亮第一只),依次类推。点亮速度的最快速度由按键设定,其他速度由实际点亮效果调试后决定。


任务要求10

当拨码的第一、二、四位合上时,点亮方式同方案8,点亮速度由慢(点亮第一和第四十只)变快(点亮第二十和第二十一时)再变慢(点亮第一和第四十只),依次类推。点亮速度的最快速度由按键设定,其他速度由实际点亮效果调试后决定。



自行设计方案的说明(如果有的话)

任务要求11
当拨码的第三、四位合上时,按当前设定的速度,从左向又一个以两格的速度(称为乌龟),一个以六格的速度(称为兔子),当兔子离终点还有12格时,停下来睡觉了,乌龟开始加速,以三格的速度前进,当乌龟离终点还有三格的时候,兔子醒了,但是乌龟已经到达了终点。

任务要求12
当拨码的第一、三、四位合上时,按当前设定的速度,从左向又一个以两格的速度(称为乌龟),一个以六格的速度(称为兔子),当兔子离终点还有12格时,停下来睡觉了,乌龟开始加速,以三格的速度前进,这次乌龟看到兔子在休息,也停下来休息,兔子醒了,轻松的跑向了终点。

任务要求13
当合上第二、三、四位时,按照当前设定的速度,由中间向两边两个两个点亮光带发光管,即由第二十和二十一只发光管点亮,再至第十九、二十、二十一和二十二只发光管点亮….再至发光管全部点亮,以此类推。

实验总结:

这次实训是设计一个模拟霓虹灯控制器,实现对40段LED光柱的动态显示和动态速度的人工控制。运用到的软件有Altium Designer、Proteus、Keil5,涉及到的知识有:Altium Designer的PCB制板,Proteus的电路图仿真,Keil5的编程运行,有关单片机知识。

经过这次实训,我明白了以下三点,一,编程首先要明白自己想要实现什么功能,会用到哪些函数,把基本框架搭建好,并不是一开始就很长的一个程序要你写出来,可以由实现一个方案开始,慢慢累积,不断完善标志位和子函数等,逐渐变成一个可以实现十三个功能的程序。还有参考很重要,在不知道如何下手的时候可以看一下别人的程序,理解别人的思路,在别人的基础上加入自己的理解。二,有些知识,要温故才能知新,要通过实践,才能知道自己哪里不足,哪里不懂,比如AD这个软件,在去年暑假的时候已经自己利用AD做好了一个板子,但在今年实训的时候制板的还是出现了点问题,最后自己把去年的视频翻出来重新看了一遍,才制作完成。有关单片机编程也是比较模糊,特别是中断这一部分,结合书和清翔单片机的视频,才对编程有点眉目。三,要有耐心和做好实训的决心,软件和硬件的结合,本身就有点麻烦,没准哪里就出了点问题,要把能想到的问题都试一遍,排查问题,找出解决办法。


附件1、总原理图(指导书)


附件2:3D

附件3:实物图


附件4:基本要求:

1、当拨码开关没有一位合上时,使光带的第一只发光管点亮。

2、当拨码开关的第一位合上时,使光带的第一、二、三只发光管点亮。

3、当拨码开关的第二位合上时,使光带的第一只发光管0.5S亮0.5S暗。

4、当拨码开关的第一、第二位合上时,使光带的第一、第二只发光管以当前设定速度交替点亮。

5、当拨码开关的第三位合上时,按当前设定速度使光带的第一、第二?第四十只发光管循环点亮,点亮第四十只后,蜂鸣器发声一下,再点亮第一只?,依次类推。

6、当拨码开关的第一、三位合上时,按当前设定速度递增循序点亮光带的第一、第二?第四十只发光管,点亮第四十只后,蜂鸣器发声一下,再按递减循序点亮第三十九、第三十八只?第一只发光管,依次类推。

稍高要求:

7、当拨码开关的第二、三位合上时,按当前设定速度由两边向中央点亮光带发光管,即由第一和第四十只发光管亮至第二和第三十九只发光管亮?第二十和第二十一只发光管亮,再至第一和第四十只亮?,依次类推。

8、当拨码开关的第一、二、三位合上时,按当前设定速度由两边向中央、再由中央向两边点亮光带发光管,即由第一和第四十只发光管亮至第二和第三十九只发光管亮?第二十和第二十一只发光管亮,再至第十九和第二十二只亮?,依次类推。

再高要求:

9、当拨码的第二、四位合上时,点亮方式同方案5,点亮速度由快(点亮第一只)变慢(点亮第四十只时)再变快(点亮第一只),依次类推。点亮速度的最快速度由按键设定,其他速度由实际点亮效果调试后决定。

10、当拨码的第一、二、四位合上时,点亮方式同方案8,点亮速度由慢(点亮第一和第四十只)变快(点亮第二十和第二十一时)再变慢(点亮第一和第四十只),依次类推。点亮速度的最快速度由按键设定,其他速度由实际点亮效果调试后决定。


附件5:程序

  1. include<reg51.h>
  2. #define uint unsigned int
  3. #define uchar unsigned char
  4. uchar LED_P2[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};//方案5
  5. uchar LED_P0[]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};//方案6
  6. uchar LED_F7[]={0x81,0x42,0x24,0x18};//方案7
  7. uchar LED_F8[]={0x18,0x24,0x42,0x81};//方案8
  8. uchar LED_P6[]={0x0f,0xf0};
  9. uchar LED_P3[]={0x18,0x3c,0x7e,0xff};//方案13.light2
  10. uchar LED_P33[]={0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff};//方案13,lingt1,light0
  11. uchar LED_P7[]={0x01,0x03,0x07,0x0f,0x1f,0x3f,0x7f,0xff};//方案13,light3,light4
  12. uchar LED_P1[5]={0xfe,0xfd,0xfb,0xf7,0xef};
  13. uchar LED_P4[5]={0xfe,0xfc,0xf8,0xf0,0xe0};
  14. uchar LED_P8[2]={0xfc,0xe7};
  15. uchar code tab[11]={ 0x6f,0x06,0xcb,0xc7,0xa6,0xe5,0xec,0x07,0xef,0xa7,0x00};//共阴数码管显示
  16. sbit key1=P0^0;//控制
  17. sbit key2=P0^1;//调速+
  18. sbit key3=P0^2;//调速-
  19. sbit wei0=P1^0;//第0条led位控
  20. sbit wei1=P1^1;//第1条led位控
  21. sbit wei2=P1^2;//第2条led位控
  22. sbit wei3=P1^3;//第3条led位控
  23. sbit wei4=P1^4;//第4条led位控
  24. sbit weil=P1^5;//数码管com1,左边数码管位选
  25. sbit weir=P1^6;//数码管com2,右边数码管位选
  26. sbit bell=P1^7;
  27. uint ABC=0;//中断标志位
  28. uint temp;//中断标志位,数码管上的速度
  29. uchar sw_value,flag0=0,c=0,av=0;
  30. bit sw_05s=5;//周期为0.5的中断标志位
  31. uchar shum;//数码管控制位,我假设的,硬件里不存在,0的时候是设置状态,1的时候是正常发光状态
  32. uchar shuml=0,shumr=5;//数码管右边的,数码管左边的
  33. uchar sw_zdy=0;//自定义周期的中断标志位
  34. uchar sw_f9,sw_f10;//方案9,10的中断标志位
  35. uchar keydeal;//按键中断标志位
  36. uchar count=0;//按键中断标志位
  37. uchar set_control=0;//key1设置键中断标志位,1设置,0跳出
  38. uchar light0=0,light1=0,light2=0,light3=0,light4=0;
  39. bit f4_flag=0;///
  40. uchar f5_flag=0,f6_flag=0,f7_flag=0,f9_slow,f10_slow=0,f11_flag=0,f12_flag=0,f13_flag=0;
  41. void f_1();//方案1
  42. void f_2();//方案2
  43. void f_3();
  44. void f_4();
  45. void f_5();
  46. void f_6();
  47. void f_7();
  48. void f_8();
  49. void f_9();
  50. void f_10();
  51. void f_11();//龟兔赛跑
  52. void f_12();//新龟兔赛跑,兔子先掉进陷阱,乌龟在掉进去,乌龟让兔子踩着自己上来,完成了比赛,然后叫来了动物,救起了乌龟
  53. void f_13();//两个由中间向两边
  54. void f_14();
  55. void f_15();
  56. void f_16();

  57. void key_deal(void)
  58. {
  59.               keydeal=P0&0x07;
  60.               if (keydeal!=0x07)//有键按下
  61.               {
  62.                             count ++;
  63.                             if (count >= 6)
  64.                             {
  65.                                           count=0;
  66.                                          
  67.                                          
  68.                                                         if (key1 == 0)//按下key1设置键
  69.                                                         {
  70.                                                                      
  71.                                                                       set_control=!set_control;//进入设置时间状态,或者跳出设置状态
  72.                                                         }
  73.                                                         if (set_control == 1&&key2 == 0&&((shuml*10+shumr)<=14))//在15限速内,按下设置后按下+键
  74.                                                         {
  75.                                                                       while(key2==0);
  76.                                                                       shumr++;
  77.                                                                       if (shumr == 10)
  78.                                                                       {
  79.                                                                                     shuml++;
  80.                                                                                     shumr=0;
  81.                                                                       }
  82.                                                         }
  83.                                                         if (set_control == 1&&key3 == 0&&((shuml*10+shumr)>01))//在01限速内,按下设置后按下-键
  84.                                                         {
  85.                                                                       while (key3 == 0);
  86.                                                                       shumr--;
  87.                                                                       if(shumr == 255)
  88.                                                                       {
  89.                                                                                     shumr=9;
  90.                                                                                     shuml--;
  91.                                                                       }
  92.                                                         }
  93.                                           }
  94.                            
  95.               }
  96. }

  97. void delay(unsigned char x)
  98. {              unsigned char i,j;            
  99. for(i=125;i>0;i--)            
  100. for(j=x;j>0;j--);
  101. }

  102. void sw_deal()//按键扫描程序
  103. {   sw_value=P0;
  104.                 sw_value=(sw_value>>4);
  105.                             switch(sw_value)            
  106.               {              case 0x0f:f_1();break;            
  107.                             case 0x0e:f_2();break;            
  108.                             case 0x0d:f_3();break;            
  109.                             case 0x0c:f_4();break;            
  110.     case 0x0b:f_5();break;            
  111.                             case 0x0a:f_6();break;            
  112.                 case 0x09:f_7();break;
  113.                 case 0x08:f_8();break;
  114.                             case 0x05:f_9();break;
  115.                             case 0x04:f_10();break;
  116.                             case 0x03:f_11();break;
  117.                             case 0x02:f_12();break;
  118.                                           case 0x01:f_13();break;
  119.                                           }
  120. }



  121. void time_0(void)interrupt 1 using 1
  122. {  
  123.               TH0=(65536-2000)/256;            
  124.               TL0=(65536-2000)%256;
  125.   if (ABC > 60000)
  126.     {ABC=1;}
  127.   else                                                      
  128.                             {ABC++;}                                                                     
  129.   if(ABC%250==0)
  130.                 {sw_05s=!sw_05s;}//周期为0.5s
  131.               if(ABC%((shuml*10+shumr)*50) == 0)//按照数码管上的时间切换周期
  132.                                                                       sw_zdy=!sw_zdy;
  133.               if(ABC%((shuml*10+shumr)*50+5*f5_flag)==0)
  134.                                                                       f9_slow=!f9_slow;
  135.               if(ABC%((shuml*10+shumr)*50-5*f7_flag+20*5)==0)
  136.                                                                       f10_slow=!f10_slow;

  137.                             switch(flag0)
  138.     {case 0:{
  139.                                                 flag0++;
  140.                                                                                     P1=0xff;
  141.                                                                                     P2=0x00;//消影
  142.                                                                                     weil=0;//开左边数码管的位控
  143.                                                                                     if(set_control == 1&&sw_05s==0 || set_control == 0)//处于非设置状态,或者设置状态下的正常发光
  144.                                                                                     {
  145.                                                                                                   P2=tab[shuml]+0x10;
  146.                                                                                     }
  147.                                                                                     else
  148.                                          P2=tab[10];//熄灭
  149.                  break;
  150.                                     }
  151.                             case 1:{
  152.                                                                                                   flag0++;
  153.                                                                                                   P1=0xff;
  154.                                                                                                   P2=0x00;
  155.                                                                                                   weir=0;//开右边数码管的位控
  156.                                                                                                   if(set_control == 1&&sw_05s==0 || set_control == 0)
  157.                                                                                     {
  158.                                                                                                   P2=tab[shumr];
  159.                                                                                     }
  160.                                                                                                   else
  161.                                                                                                   P2=tab[10];//熄灭
  162.                                                                                                   break;
  163.                                                            }
  164.                                                                      
  165.                             case 2:{
  166.                                                                                     flag0 ++;
  167.                                                                                     weir=1;
  168.                                          
  169.                                                                                     P2=0x00;
  170.                                                                                     wei0=0;
  171.                                                                                     if(set_control==0)//非设置状态led常亮
  172.                                                                                     {
  173.                                                                                                   P2=light0;
  174.                                                                                     }
  175.                                                                      
  176.                                                                                     if(set_control==1)//设置状态led常灭
  177.                                                                                     {
  178.                                                                                                 
  179.                                                                                                   P2=0x00;
  180.                                                                                     }
  181.                                                                                     break;
  182.                                                                      
  183.                                                            }
  184.                                                       
  185.                                           case 3:
  186.                                                                       {
  187.                                                                                     flag0 ++;
  188.                                                                                     wei0=1;
  189.                                                                                    
  190.                                                                                     P2=0x00;
  191.                                                                                     wei1=0;
  192.                                                                                     if(set_control==0)//非设置状态led常亮
  193.                                                                                     {
  194.                                                                                                   P2=light1;
  195.                                                                                     }
  196.                                                                                     if(set_control==1)//设置状态led常灭
  197.                                                                                     {
  198.                                                                                                 
  199.                                                                                                   P2=0x00;
  200.                                                                                     }
  201.                                                                                     break;
  202.                                                                       }
  203.                                                                      
  204.                                                                       case 4:
  205.                                                                       {
  206.                                                                                     flag0 ++;
  207.                                                                                     wei1=1;
  208.                                                                      
  209.                                                                                     P2=0x00;
  210.                                                                                     wei2=0;
  211.                                                                                     if(set_control==0)//非设置状态led常亮
  212.                                                                                     {
  213.                                                                                                   P2=light2;
  214.                                                                                     }
  215.                                                                                     if(set_control==1)//设置状态led常灭
  216.                                                                                     {
  217.                                                                                                 
  218.                                                                                                   P2=0x00;
  219.                                                                                     }
  220.                                                                                     break;
  221.                                                                       }
  222.                                                                      
  223.                                                                       case 5:
  224.                                                                       {
  225.                                                                                     flag0 ++;
  226.                                                                                     wei2=1;
  227.                                                                                    
  228.                                                                                     P2=0x00;
  229.                                                                                     wei3=0;
  230.                                                                                     if(set_control==0)//非设置状态led常亮
  231.                                                                                     {
  232.                                                                                                   P2=light3;
  233.                                                                                     }
  234.                                                                                     if(set_control==1)//设置状态led常灭
  235.                                                                                     {
  236.                                                                                                 
  237.                                                                                                   P2=0x00;
  238.                                                                                     }
  239.                                                                                     break;
  240.                                                                       }
  241.                                                                      
  242.                                                                       case 6:
  243.                                                                       {
  244.                                                                                     flag0=0;
  245.                                                                                     wei3=1;
  246.                                                                                     P2=0x00;
  247.                                                                                     wei4=0;
  248.                                                                                     if(set_control==0)//非设置状态led常亮
  249.                                                                                     {
  250.                                                                                                   P2=light4;
  251.                                                                                     }
  252.                                                                                     if(set_control==1)//设置状态led常灭
  253.                                                                                     {
  254.                                                                                                 
  255.                                                                                                   P2=0x00;
  256.                                                                                     }
  257.                                                                                     break;
  258.                                                           }
  259.                                                         }
  260.           if (sw_zdy%10==0)
  261.                                                                       {
  262.                                                                                     P0=0xff;
  263.                                                                                     sw_value=P0&0xf0;
  264.                                                                                     keydeal=P0&0x07;
  265.                                                                                     key_deal();
  266.                                                                       }                                                                                                                                                                  
  267. }            
  268.                             void main(void)
  269. {            
  270.   TMOD=0x01;            
  271.   TH0=(65536-2000)/256;
  272.               TL0=(65536-2000)%256;            
  273.               IE=0x82;
  274.               TR0=1;
  275.               P1=0xff;
  276.               P2=0x00;
  277.               while(1)
  278.               {            
  279.     sw_deal();
  280.               }
  281. }

  282. void f_1 (void)
  283. {
  284.                   light0=0x01;
  285.                   light1=0x00;
  286.                   light2=0x00;
  287.                   light3=0x00;
  288.                   light4=0x00;
  289.             
  290. }
  291. void f_2(void)//合上s1,亮三盏
  292.               {
  293.                               light0=0x07;
  294.                                           light1=0x00;
  295.                   light2=0x00;
  296.                   light3=0x00;
  297.                   light4=0x00;
  298.                  }
  299.             
  300. void f_3(void)//合上s2,0.5s交替亮灭
  301.               {            
  302.     if(sw_05s==0)
  303.                             {
  304.                               light0=0x01;
  305.                                           light1=0x00;
  306.                   light2=0x00;
  307.                   light3=0x00;
  308.                   light4=0x00;
  309.                             }
  310.                             if(sw_05s==1)
  311.                             {
  312.                               light0=0x00;
  313.                                           light1=0x00;
  314.                   light2=0x00;
  315.                   light3=0x00;
  316.                   light4=0x00;
  317.                             }
  318.               }
  319.             
  320. void f_4(void)//交替点亮
  321.               {            
  322.     if(sw_zdy==0)
  323.                             {
  324.                               light0=0x01;
  325.                                           light1=0x00;
  326.                   light2=0x00;
  327.                   light3=0x00;
  328.                   light4=0x00;
  329.                             }
  330.                             if(sw_zdy==1)
  331.                             {
  332.                               light0=0x02;
  333.                                           light1=0x00;
  334.                   light2=0x00;
  335.                   light3=0x00;
  336.                   light4=0x00;
  337.                             }
  338.                                           }
  339.             
  340. void f_5(void)//循环点亮
  341. {            
  342.               uint i;
  343.               if(sw_zdy == 0)
  344.               {            
  345.     f5_flag++;
  346.                             if(f5_flag>=0&&f5_flag<8)            
  347.                             {
  348.       light0=LED_P2[f5_flag];
  349.                                           light1=0;
  350.                                           light2=0;
  351.                                           light3=0;
  352.                                           light4=0;
  353.                             }                           
  354.                             if(f5_flag>=8&&f5_flag<16)            
  355.                             {
  356.                                           light0=0;
  357.       light1=LED_P2[f5_flag%8];
  358.                                           light2=0;
  359.                                           light3=0;
  360.                                           light4=0;
  361.                             }                           
  362.                             if(f5_flag>=16&&f5_flag<24)            
  363.                             {
  364.                                           light0=0;
  365.                                           light1=0;
  366.       light2=LED_P2[f5_flag%8];
  367.                                           light3=0;
  368.                                           light4=0;
  369.                             }
  370.                             if(f5_flag>=24&&f5_flag<32)            
  371.                             {
  372.                                           light0=0;
  373.       light1=0;
  374.                                           light2=0;
  375.                                           light3=LED_P2[f5_flag%8];
  376.                                           light4=0;
  377.                             }            
  378.                             if(f5_flag>=32&&f5_flag<40)            
  379.                             {
  380.                                           light0=0;
  381.       light1=0;
  382.                                           light2=0;
  383.                                           light3=0;
  384.                                           light4=LED_P2[f5_flag%8];
  385.                             }                           
  386.                             if(f5_flag==39)
  387.                             {
  388.                                           light0=0;
  389.       light1=0;
  390.                                           light2=0;
  391.                                           light3=0;
  392.                                           light4=LED_P2[f5_flag%8];
  393.                                           bell=0;
  394.                                           for(i=0;i<100;i++)
  395.                                           {
  396.                            
  397.                                                         bell=!bell;
  398.                                                         delay(2);
  399.                                           }
  400.      }
  401.                             if(f5_flag>=40)
  402.                             {
  403.                                          
  404.                                           f5_flag=0;
  405.                                           light0=0x01;
  406.                             }

  407.               while(sw_zdy == 0);

  408.               }

  409.               }
  410.                                          

  411. void f_6(void)
  412. {
  413.               uint i;
  414.               if(sw_zdy == 0)
  415.               {            
  416.     f6_flag++;
  417.                             if(f6_flag>=0&&f6_flag<8)            
  418.                             {
  419.       light0=LED_P2[f6_flag];
  420.                                           light1=0;
  421.                                           light2=0;
  422.                                           light3=0;
  423.                                           light4=0;
  424.                             }                           
  425.                             if(f6_flag>=8&&f6_flag<16)            
  426.                             {
  427.                                           light0=0;
  428.       light1=LED_P2[f6_flag%8];
  429.                                           light2=0;
  430.                                           light3=0;
  431.                                           light4=0;
  432.                             }                           
  433.                             if(f6_flag>=16&&f6_flag<24)            
  434.                             {
  435.                                           light0=0;
  436.                                           light1=0;
  437.       light2=LED_P2[f6_flag%8];
  438.                                           light3=0;
  439.                                           light4=0;
  440.                             }
  441.                             if(f6_flag>=24&&f6_flag<32)            
  442.                             {
  443.                                           light0=0;
  444.       light1=0;
  445.                                           light2=0;
  446.                                           light3=LED_P2[f6_flag%8];
  447.                                           light4=0;
  448.                             }            
  449.                             if(f6_flag>=32&&f6_flag<40)            
  450.                             {
  451.                                           light0=0;
  452.       light1=0;
  453.                                           light2=0;
  454.                                           light3=0;
  455.                                           light4=LED_P2[f6_flag%8];
  456.                             }                           
  457.                             if(f6_flag==39)
  458.                             {
  459.                                           light0=0;
  460.       light1=0;
  461.                                           light2=0;
  462.                                           light3=0;
  463.                                           light4=LED_P2[(f6_flag-32)%8];
  464.                                           bell=0;
  465.                                           for(i=0;i<100;i++)
  466.                                           {
  467.                                           bell=!bell;
  468.                                                         delay(2);
  469.                                           }
  470.      }
  471.                             if(f6_flag>39&&f6_flag<48)
  472.                             {
  473.                                          
  474.                                           light0=0;
  475.                                           light1=0;
  476.                                           light2=0;
  477.                                           light3=0;
  478.                                           light4=LED_P0[(f6_flag-32)%8];
  479.                             }
  480.                             if(f6_flag>=48&&f6_flag<56)
  481.                             {
  482.                                          
  483.                                           light4=0;
  484.                                           light3=LED_P0[(f6_flag-40)%8];
  485.                                           light2=0;
  486.                                           light1=0;
  487.                                           light0=0;
  488.                             }
  489.                             if(f6_flag>=56&&f6_flag<64)
  490.                             {
  491.                                          
  492.                                           light4=0;
  493.                                           light3=0;
  494.                                           light2=LED_P0[(f6_flag-48)%8];
  495.                                           light1=0;
  496.                                           light0=0;
  497.                             }
  498.                             if(f6_flag>=64&&f6_flag<72)
  499.                             {
  500.                                          
  501.                                           light4=0;
  502.                                           light3=0;
  503.                                           light2=0;
  504.                                           light1=LED_P0[(f6_flag-56)%8];
  505.                                           light0=0;
  506.                             }
  507.                             if(f6_flag>=72&&f6_flag<80)
  508.                             {
  509.                                          
  510.                                           light4=0;
  511.                                           light3=0;
  512.                                           light2=0;
  513.                                           light1=0;
  514.                                           light0=LED_P0[(f6_flag-64)%8];
  515.                             }
  516.                             if(f6_flag>=80)
  517.                             {
  518.                                           f6_flag=0;
  519.                                           light0=0x01;
  520.                                           light1=0x00;
  521.                                           light2=0x00;
  522.                                           light3=0x00;
  523.                                           light4=0x00;
  524.                             }
  525.               while(sw_zdy == 0);

  526.               }
  527. }

  528. void f_7(void)
  529.               {            
  530.                             if(sw_zdy==0)
  531.                             {
  532.                                           f7_flag++;
  533.                                           if(f7_flag>=0&&f7_flag<8)
  534.                                           {
  535.                                                         light0=LED_P2[f7_flag];
  536.                                             light1=0;
  537.                                             light2=0;
  538.                                             light3=0;
  539.                                             light4=LED_P0[f7_flag%8];
  540.                                           }
  541.                                           if(f7_flag>=8&&f7_flag<16)
  542.                                           {
  543.                                                         light0=0;
  544.                                             light1=LED_P2[f7_flag%8];
  545.                                             light2=0;
  546.                                             light3=LED_P0[f7_flag%8];
  547.                                             light4=0;
  548.                                           }
  549.                                           if(f7_flag>=16&&f7_flag<21)
  550.                                           {
  551.                                                         light0=0;
  552.                                             light1=0;
  553.                                             light2=LED_F7[f7_flag-16];
  554.                                             light3=0;
  555.                                             light4=0;
  556.                                           }
  557.                                           if(f7_flag>=21)
  558.                                           {
  559.                                                         f7_flag=0;
  560.                                                         light0=LED_P2[f7_flag%8];
  561.                                                         light1=0x00;
  562.                                                         light2=0x00;
  563.                                                         light3=0x00;
  564.                                                         light4=LED_P0[f7_flag%8];
  565.                                           }
  566.                             while(sw_zdy==0);
  567.                             }
  568.                             }
  569.             
  570. void f_8(void)
  571.               {            
  572.                             uchar i;
  573.                             if(sw_zdy==0)
  574.                             {
  575.                                           f7_flag++;
  576.                                           if(f7_flag>=0&&f7_flag<8)
  577.                                           {
  578.                                                         light0=LED_P2[f7_flag];
  579.                                             light1=0;
  580.                                             light2=0;
  581.                                             light3=0;
  582.                                             light4=LED_P0[f7_flag%8];
  583.                                           }
  584.                                           if(f7_flag>=8&&f7_flag<16)
  585.                                           {
  586.                                                         light0=0;
  587.                                             light1=LED_P2[f7_flag%8];
  588.                                             light2=0;
  589.                                             light3=LED_P0[f7_flag%8];
  590.                                             light4=0;
  591.                                           }
  592.                                           if(f7_flag>=16&&f7_flag<20)
  593.                                           {
  594.                                                         light0=0;
  595.                                             light1=0;
  596.                                             light2=LED_F7[f7_flag-16];
  597.                                             light3=0;
  598.                                             light4=0;
  599.                                           }
  600.                                           if(f7_flag==20)
  601.                                           {
  602.                                                         light0=0x00;
  603.                                                         light1=0x00;
  604.                                                         light2=0x18;
  605.                                                         light3=0x00;
  606.                                                         light4=0x00;
  607.                                                         bell=0;
  608.                                             for(i=0;i<100;i++)
  609.                                           {
  610.                                             bell=!bell;
  611.                                                         delay(2);
  612.                                           }
  613.                                           }
  614.                                          
  615.                                           if(f7_flag>20&&f7_flag<=24)
  616.                                           {
  617.                                                         light0=0;
  618.                                             light1=0;
  619.                                             light2=LED_F8[f7_flag-20];
  620.                                             light3=0;
  621.                                             light4=0;
  622.                                           }
  623.                                          
  624.                                           if(f7_flag>24&&f7_flag<32)
  625.                                           {
  626.                                                         light0=0;
  627.                                             light1=LED_P0[f7_flag%8];
  628.                                             light2=0;
  629.                                             light3=LED_P2[f7_flag-24];
  630.                                             light4=0;
  631.                                           }                           
  632.                                          
  633.                                           if(f7_flag>=32&&f7_flag<40)
  634.                                           {
  635.                                                         light0=LED_P0[f7_flag-32];
  636.                                             light1=0;
  637.                                             light2=0;
  638.                                             light3=0;
  639.                                             light4=LED_P2[f7_flag-32];
  640.                                           }
  641.                                           if(f7_flag>=40)
  642.                                           {
  643.                                                         f7_flag=0;
  644.                                           }
  645.                             while(sw_zdy==0);
  646.                             }
  647.                             }
  648.             
  649. void f_9(void)
  650. {
  651.                             uint i;
  652.               if(f9_slow == 0)
  653.               {            
  654.     f5_flag++;
  655.                             if(f5_flag>=0&&f5_flag<8)            
  656.                             {
  657.       light0=LED_P2[f5_flag];
  658.                                           light1=0;
  659.                                           light2=0;
  660.                                           light3=0;
  661.                                           light4=0;
  662.                             }                           
  663.                             if(f5_flag>=8&&f5_flag<16)            
  664.                             {
  665.                                           light0=0;
  666.       light1=LED_P2[f5_flag%8];
  667.                                           light2=0;
  668.                                           light3=0;
  669.                                           light4=0;
  670.                             }                           
  671.                             if(f5_flag>=16&&f5_flag<24)            
  672.                             {
  673.                                           light0=0;
  674.                                           light1=0;
  675.       light2=LED_P2[f5_flag%8];
  676.                                           light3=0;
  677.                                           light4=0;
  678.                             }
  679.                             if(f5_flag>=24&&f5_flag<32)            
  680.                             {
  681.                                           light0=0;
  682.       light1=0;
  683.                                           light2=0;
  684.                                           light3=LED_P2[f5_flag%8];
  685.                                           light4=0;
  686.                             }            
  687.                             if(f5_flag>=32&&f5_flag<40)            
  688.                             {
  689.                                           light0=0;
  690.       light1=0;
  691.                                           light2=0;
  692.                                           light3=0;
  693.                                           light4=LED_P2[f5_flag%8];
  694.                             }                           
  695.                             if(f5_flag==39)
  696.                             {
  697.                                           light0=0;
  698.       light1=0;
  699.                                           light2=0;
  700.                                           light3=0;
  701.                                           light4=0x80;
  702.                                           bell=0;
  703.                                           for(i=0;i<100;i++)
  704.                                           {
  705.                                           bell=!bell;
  706.                                                         delay(2);
  707.                                           }
  708.      }
  709.                             if(f5_flag>=40)
  710.                             {
  711.                                          
  712.                                           f5_flag=0;
  713.                                           light0=0x01;
  714.                             }

  715.               while(f9_slow == 0);

  716.               }

  717.                             }

  718. void f_10(void)
  719. {
  720.     uchar i;
  721.                             if(f10_slow==1)
  722.                             {
  723.                                           f7_flag++;
  724.                                           if(f7_flag>=0&&f7_flag<8)
  725.                                           {
  726.                                                         light0=LED_P2[f7_flag];
  727.                                             light1=0;
  728.                                             light2=0;
  729.                                             light3=0;
  730.                                             light4=LED_P0[f7_flag%8];
  731.                                           }
  732.                                           if(f7_flag>=8&&f7_flag<16)
  733.                                           {
  734.                                                         light0=0;
  735.                                             light1=LED_P2[f7_flag%8];
  736.                                             light2=0;
  737.                                             light3=LED_P0[f7_flag%8];
  738.                                             light4=0;
  739.                                           }
  740.                                           if(f7_flag>=16&&f7_flag<20)
  741.                                           {
  742.                                                         light0=0;
  743.                                             light1=0;
  744.                                             light2=LED_F7[f7_flag-16];
  745.                                             light3=0;
  746.                                             light4=0;
  747.                                           }
  748.                                           if(f7_flag==20)
  749.                                           {
  750.                                                         light0=0x00;
  751.                                                         light1=0x00;
  752.                                                         light2=0x18;
  753.                                                         light3=0x00;
  754.                                                         light4=0x00;
  755.                                                         bell=0;
  756.                                             for(i=0;i<100;i++)
  757.                                           {
  758.                                             bell=!bell;
  759.                                                         delay(2);
  760.                                           }
  761.                                           }
  762.                                           if(f7_flag>20&&f7_flag<=24)
  763.                                           {
  764.                                                         light0=0;
  765.                                             light1=0;
  766.                                             light2=LED_F8[f7_flag-20];
  767.                                             light3=0;
  768.                                             light4=0;
  769.                                           }
  770.                                          
  771.                                           if(f7_flag>24&&f7_flag<32)
  772.                                           {
  773.                                                         light0=0;
  774.                                             light1=LED_P0[f7_flag%8];
  775.                                             light2=0;
  776.                                             light3=LED_P2[f7_flag-24];
  777.                                             light4=0;
  778.                                           }                           
  779.                                          
  780.                                           if(f7_flag>=32&&f7_flag<40)
  781.                                           {
  782.                                                         light0=LED_P0[f7_flag-32];
  783.                                             light1=0;
  784.                                             light2=0;
  785.                                             light3=0;
  786.                                             light4=LED_P2[f7_flag-32];
  787.                                           }
  788.                                           if(f7_flag>=40)
  789.                                           {
  790.                                                         f7_flag=0;
  791.                                           }
  792.                             while(f10_slow==1);
  793.                             }

  794. }
  795. void f_11()
  796. {
  797.               uchar h;
  798.               if(sw_zdy==0)
  799.               {
  800.               switch(f11_flag)
  801.                 {
  802.                             case 0:{f11_flag++;light0=0x01;light1=0;light2=0;light3=0;light4=0;break;}
  803.                             case 1:{f11_flag++;light0=0x88;light1=0;light2=0;light3=0;light4=0;break;}
  804.                             case 2:{f11_flag++;light0=0x40;light1=0x40;light2=0;light3=0;light4=0;break;}
  805.                             case 3:{f11_flag++;light0=0;light1=0x02;light2=0x20;light3=0;light4=0;break;}
  806.                             case 4:{f11_flag++;light0=0;light1=0x10;light2=0;light3=0x10;light4=0;break;}
  807.                             case 5:{f11_flag++;light0=0;light1=0;light2=0x01;light3=0x10;light4=0;break;}
  808.                             case 6:{f11_flag++;light0=0;light1=0;light2=0x10;light3=0x10;light4=0;break;}
  809.                             case 7:{f11_flag++;light0=0;light1=0;light2=0;light3=0x11;light4=0;break;}
  810.                             case 8:{f11_flag++;light0=0;light1=0;light2=0;light3=0x10;light4=0;break;}
  811.                             case 9:{f11_flag++;light0=0;light1=0;light2=0;light3=0x10;light4=0x01;break;}
  812.                             case 10:{f11_flag++;light0=0;light1=0;light2=0;light3=0x10;light4=0x10;break;}
  813.                             case 11:{f11_flag=0;light0=0;light1=0;light2=0;light3=0x00;light4=0x88;break;}
  814.                            
  815.                 }
  816.                            
  817.                 if(f11_flag==0)
  818.               {
  819.                               for(h=0;h<50;h++)
  820.                 {bell=0;
  821.                                           delay(2);
  822.                               bell=!bell;
  823.                             }
  824.               }}
  825.                             while(sw_zdy == 0);
  826.             
  827. }

  828. void f_12()
  829. {
  830.               uchar h;
  831.               if(sw_zdy==0)
  832.               {
  833.               switch(f12_flag)
  834.                 {
  835.                             case 0:{f12_flag++;light0=0x01;light1=0;light2=0;light3=0;light4=0;break;}
  836.                             case 1:{f12_flag++;light0=0x88;light1=0;light2=0;light3=0;light4=0;break;}
  837.                             case 2:{f12_flag++;light0=0x40;light1=0x40;light2=0;light3=0;light4=0;break;}
  838.                             case 3:{f12_flag++;light0=0;light1=0x02;light2=0x20;light3=0;light4=0;break;}
  839.                             case 4:{f12_flag++;light0=0;light1=0x10;light2=0;light3=0x10;light4=0;break;}
  840.                             case 5:{f12_flag++;light0=0;light1=0;light2=0x01;light3=0x10;light4=0;break;}
  841.                             case 6:{f12_flag++;light0=0;light1=0;light2=0x10;light3=0x10;light4=0;break;}
  842.                             case 7:{f12_flag++;light0=0;light1=0;light2=0;light3=0x11;light4=0;break;}
  843.                             case 8:{f12_flag++;light0=0;light1=0;light2=0;light3=0x10;light4=0;break;}
  844.                             case 9:{f12_flag++;light0=0;light1=0;light2=0;light3=0x10;light4=0x00;break;}
  845.                             case 10:{f12_flag++;light0=0;light1=0;light2=0;light3=0x10;light4=0x02;break;}
  846.                             case 11:{f12_flag=0;light0=0;light1=0;light2=0;light3=0x10;light4=0x80;break;}
  847.                            
  848.                 }
  849.                            
  850.                 if(f12_flag==0)
  851.               {
  852.                               for(h=0;h<50;h++)
  853.                 {bell=0;
  854.                                           delay(2);
  855.                               bell=!bell;
  856.                             }
  857.               }}
  858.                             while(sw_zdy == 0);
  859.             
  860. }
  861. void f_13(void)
  862. {            
  863.             
  864.               if(sw_zdy == 0)
  865.               {            
  866.     f13_flag++;
  867.                             if(f13_flag>=0&&f13_flag<4)            
  868.                             {
  869.       light0=0;
  870.                                           light1=0;
  871.                                           light2=LED_P3[f13_flag];
  872.                                           light3=0;
  873.                                           light4=0;
  874.                             }                           
  875.                             if(f13_flag>=4&&f13_flag<12)            
  876.                             {
  877.                                           light0=0;
  878.       light1=LED_P33[f13_flag-4];
  879.                                           light2=0xff;
  880.                                           light3= LED_P7[f13_flag-4];
  881.                                           light4=0;
  882.                             }                           
  883.                             if(f13_flag>=12&&f13_flag<20)            
  884.                             {
  885.                                           light0=LED_P33[f13_flag-12];
  886.                                           light1=0xff;
  887.       light2=0xff;
  888.                                           light3=0xff;
  889.                                           light4=LED_P7[f13_flag-12];
  890.                             }
  891.                            
  892.                             if(f13_flag>=20)
  893.                             {
  894.                                          
  895.                                           f13_flag=0;
  896.                                           light2=0x18;
  897.                                           light0=0;
  898.                                           light1=0;
  899.                                           light3=0;
  900.                                           light4=0;
  901.                             }

  902.               while(sw_zdy == 0);

  903.               }

  904.               }
复制代码


分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表