通过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:程序 - include<reg51.h>
- #define uint unsigned int
- #define uchar unsigned char
- uchar LED_P2[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};//方案5
- uchar LED_P0[]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};//方案6
- uchar LED_F7[]={0x81,0x42,0x24,0x18};//方案7
- uchar LED_F8[]={0x18,0x24,0x42,0x81};//方案8
- uchar LED_P6[]={0x0f,0xf0};
- uchar LED_P3[]={0x18,0x3c,0x7e,0xff};//方案13.light2
- uchar LED_P33[]={0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff};//方案13,lingt1,light0
- uchar LED_P7[]={0x01,0x03,0x07,0x0f,0x1f,0x3f,0x7f,0xff};//方案13,light3,light4
- uchar LED_P1[5]={0xfe,0xfd,0xfb,0xf7,0xef};
- uchar LED_P4[5]={0xfe,0xfc,0xf8,0xf0,0xe0};
- uchar LED_P8[2]={0xfc,0xe7};
- uchar code tab[11]={ 0x6f,0x06,0xcb,0xc7,0xa6,0xe5,0xec,0x07,0xef,0xa7,0x00};//共阴数码管显示
- sbit key1=P0^0;//控制
- sbit key2=P0^1;//调速+
- sbit key3=P0^2;//调速-
- sbit wei0=P1^0;//第0条led位控
- sbit wei1=P1^1;//第1条led位控
- sbit wei2=P1^2;//第2条led位控
- sbit wei3=P1^3;//第3条led位控
- sbit wei4=P1^4;//第4条led位控
- sbit weil=P1^5;//数码管com1,左边数码管位选
- sbit weir=P1^6;//数码管com2,右边数码管位选
- sbit bell=P1^7;
- uint ABC=0;//中断标志位
- uint temp;//中断标志位,数码管上的速度
- uchar sw_value,flag0=0,c=0,av=0;
- bit sw_05s=5;//周期为0.5的中断标志位
- uchar shum;//数码管控制位,我假设的,硬件里不存在,0的时候是设置状态,1的时候是正常发光状态
- uchar shuml=0,shumr=5;//数码管右边的,数码管左边的
- uchar sw_zdy=0;//自定义周期的中断标志位
- uchar sw_f9,sw_f10;//方案9,10的中断标志位
- uchar keydeal;//按键中断标志位
- uchar count=0;//按键中断标志位
- uchar set_control=0;//key1设置键中断标志位,1设置,0跳出
- uchar light0=0,light1=0,light2=0,light3=0,light4=0;
- bit f4_flag=0;///
- uchar f5_flag=0,f6_flag=0,f7_flag=0,f9_slow,f10_slow=0,f11_flag=0,f12_flag=0,f13_flag=0;
- void f_1();//方案1
- void f_2();//方案2
- void f_3();
- void f_4();
- void f_5();
- void f_6();
- void f_7();
- void f_8();
- void f_9();
- void f_10();
- void f_11();//龟兔赛跑
- void f_12();//新龟兔赛跑,兔子先掉进陷阱,乌龟在掉进去,乌龟让兔子踩着自己上来,完成了比赛,然后叫来了动物,救起了乌龟
- void f_13();//两个由中间向两边
- void f_14();
- void f_15();
- void f_16();
-
- void key_deal(void)
- {
- keydeal=P0&0x07;
- if (keydeal!=0x07)//有键按下
- {
- count ++;
- if (count >= 6)
- {
- count=0;
-
-
- if (key1 == 0)//按下key1设置键
- {
-
- set_control=!set_control;//进入设置时间状态,或者跳出设置状态
- }
- if (set_control == 1&&key2 == 0&&((shuml*10+shumr)<=14))//在15限速内,按下设置后按下+键
- {
- while(key2==0);
- shumr++;
- if (shumr == 10)
- {
- shuml++;
- shumr=0;
- }
- }
- if (set_control == 1&&key3 == 0&&((shuml*10+shumr)>01))//在01限速内,按下设置后按下-键
- {
- while (key3 == 0);
- shumr--;
- if(shumr == 255)
- {
- shumr=9;
- shuml--;
- }
- }
- }
-
- }
- }
-
- void delay(unsigned char x)
- { unsigned char i,j;
- for(i=125;i>0;i--)
- for(j=x;j>0;j--);
- }
-
- void sw_deal()//按键扫描程序
- { sw_value=P0;
- sw_value=(sw_value>>4);
- switch(sw_value)
- { case 0x0f:f_1();break;
- case 0x0e:f_2();break;
- case 0x0d:f_3();break;
- case 0x0c:f_4();break;
- case 0x0b:f_5();break;
- case 0x0a:f_6();break;
- case 0x09:f_7();break;
- case 0x08:f_8();break;
- case 0x05:f_9();break;
- case 0x04:f_10();break;
- case 0x03:f_11();break;
- case 0x02:f_12();break;
- case 0x01:f_13();break;
- }
- }
-
-
-
- void time_0(void)interrupt 1 using 1
- {
- TH0=(65536-2000)/256;
- TL0=(65536-2000)%256;
- if (ABC > 60000)
- {ABC=1;}
- else
- {ABC++;}
- if(ABC%250==0)
- {sw_05s=!sw_05s;}//周期为0.5s
- if(ABC%((shuml*10+shumr)*50) == 0)//按照数码管上的时间切换周期
- sw_zdy=!sw_zdy;
- if(ABC%((shuml*10+shumr)*50+5*f5_flag)==0)
- f9_slow=!f9_slow;
- if(ABC%((shuml*10+shumr)*50-5*f7_flag+20*5)==0)
- f10_slow=!f10_slow;
-
- switch(flag0)
- {case 0:{
- flag0++;
- P1=0xff;
- P2=0x00;//消影
- weil=0;//开左边数码管的位控
- if(set_control == 1&&sw_05s==0 || set_control == 0)//处于非设置状态,或者设置状态下的正常发光
- {
- P2=tab[shuml]+0x10;
- }
- else
- P2=tab[10];//熄灭
- break;
- }
- case 1:{
- flag0++;
- P1=0xff;
- P2=0x00;
- weir=0;//开右边数码管的位控
- if(set_control == 1&&sw_05s==0 || set_control == 0)
- {
- P2=tab[shumr];
- }
- else
- P2=tab[10];//熄灭
- break;
- }
-
- case 2:{
- flag0 ++;
- weir=1;
-
- P2=0x00;
- wei0=0;
- if(set_control==0)//非设置状态led常亮
- {
- P2=light0;
- }
-
- if(set_control==1)//设置状态led常灭
- {
-
- P2=0x00;
- }
- break;
-
- }
-
- case 3:
- {
- flag0 ++;
- wei0=1;
-
- P2=0x00;
- wei1=0;
- if(set_control==0)//非设置状态led常亮
- {
- P2=light1;
- }
- if(set_control==1)//设置状态led常灭
- {
-
- P2=0x00;
- }
- break;
- }
-
- case 4:
- {
- flag0 ++;
- wei1=1;
-
- P2=0x00;
- wei2=0;
- if(set_control==0)//非设置状态led常亮
- {
- P2=light2;
- }
- if(set_control==1)//设置状态led常灭
- {
-
- P2=0x00;
- }
- break;
- }
-
- case 5:
- {
- flag0 ++;
- wei2=1;
-
- P2=0x00;
- wei3=0;
- if(set_control==0)//非设置状态led常亮
- {
- P2=light3;
- }
- if(set_control==1)//设置状态led常灭
- {
-
- P2=0x00;
- }
- break;
- }
-
- case 6:
- {
- flag0=0;
- wei3=1;
- P2=0x00;
- wei4=0;
- if(set_control==0)//非设置状态led常亮
- {
- P2=light4;
- }
- if(set_control==1)//设置状态led常灭
- {
-
- P2=0x00;
- }
- break;
- }
- }
- if (sw_zdy%10==0)
- {
- P0=0xff;
- sw_value=P0&0xf0;
- keydeal=P0&0x07;
- key_deal();
- }
- }
- void main(void)
- {
- TMOD=0x01;
- TH0=(65536-2000)/256;
- TL0=(65536-2000)%256;
- IE=0x82;
- TR0=1;
- P1=0xff;
- P2=0x00;
- while(1)
- {
- sw_deal();
- }
- }
-
- void f_1 (void)
- {
- light0=0x01;
- light1=0x00;
- light2=0x00;
- light3=0x00;
- light4=0x00;
-
- }
- void f_2(void)//合上s1,亮三盏
- {
- light0=0x07;
- light1=0x00;
- light2=0x00;
- light3=0x00;
- light4=0x00;
- }
-
- void f_3(void)//合上s2,0.5s交替亮灭
- {
- if(sw_05s==0)
- {
- light0=0x01;
- light1=0x00;
- light2=0x00;
- light3=0x00;
- light4=0x00;
- }
- if(sw_05s==1)
- {
- light0=0x00;
- light1=0x00;
- light2=0x00;
- light3=0x00;
- light4=0x00;
- }
- }
-
- void f_4(void)//交替点亮
- {
- if(sw_zdy==0)
- {
- light0=0x01;
- light1=0x00;
- light2=0x00;
- light3=0x00;
- light4=0x00;
- }
- if(sw_zdy==1)
- {
- light0=0x02;
- light1=0x00;
- light2=0x00;
- light3=0x00;
- light4=0x00;
- }
- }
-
- void f_5(void)//循环点亮
- {
- uint i;
- if(sw_zdy == 0)
- {
- f5_flag++;
- if(f5_flag>=0&&f5_flag<8)
- {
- light0=LED_P2[f5_flag];
- light1=0;
- light2=0;
- light3=0;
- light4=0;
- }
- if(f5_flag>=8&&f5_flag<16)
- {
- light0=0;
- light1=LED_P2[f5_flag%8];
- light2=0;
- light3=0;
- light4=0;
- }
- if(f5_flag>=16&&f5_flag<24)
- {
- light0=0;
- light1=0;
- light2=LED_P2[f5_flag%8];
- light3=0;
- light4=0;
- }
- if(f5_flag>=24&&f5_flag<32)
- {
- light0=0;
- light1=0;
- light2=0;
- light3=LED_P2[f5_flag%8];
- light4=0;
- }
- if(f5_flag>=32&&f5_flag<40)
- {
- light0=0;
- light1=0;
- light2=0;
- light3=0;
- light4=LED_P2[f5_flag%8];
- }
- if(f5_flag==39)
- {
- light0=0;
- light1=0;
- light2=0;
- light3=0;
- light4=LED_P2[f5_flag%8];
- bell=0;
- for(i=0;i<100;i++)
- {
-
- bell=!bell;
- delay(2);
- }
- }
- if(f5_flag>=40)
- {
-
- f5_flag=0;
- light0=0x01;
- }
-
- while(sw_zdy == 0);
-
- }
-
- }
-
-
- void f_6(void)
- {
- uint i;
- if(sw_zdy == 0)
- {
- f6_flag++;
- if(f6_flag>=0&&f6_flag<8)
- {
- light0=LED_P2[f6_flag];
- light1=0;
- light2=0;
- light3=0;
- light4=0;
- }
- if(f6_flag>=8&&f6_flag<16)
- {
- light0=0;
- light1=LED_P2[f6_flag%8];
- light2=0;
- light3=0;
- light4=0;
- }
- if(f6_flag>=16&&f6_flag<24)
- {
- light0=0;
- light1=0;
- light2=LED_P2[f6_flag%8];
- light3=0;
- light4=0;
- }
- if(f6_flag>=24&&f6_flag<32)
- {
- light0=0;
- light1=0;
- light2=0;
- light3=LED_P2[f6_flag%8];
- light4=0;
- }
- if(f6_flag>=32&&f6_flag<40)
- {
- light0=0;
- light1=0;
- light2=0;
- light3=0;
- light4=LED_P2[f6_flag%8];
- }
- if(f6_flag==39)
- {
- light0=0;
- light1=0;
- light2=0;
- light3=0;
- light4=LED_P2[(f6_flag-32)%8];
- bell=0;
- for(i=0;i<100;i++)
- {
- bell=!bell;
- delay(2);
- }
- }
- if(f6_flag>39&&f6_flag<48)
- {
-
- light0=0;
- light1=0;
- light2=0;
- light3=0;
- light4=LED_P0[(f6_flag-32)%8];
- }
- if(f6_flag>=48&&f6_flag<56)
- {
-
- light4=0;
- light3=LED_P0[(f6_flag-40)%8];
- light2=0;
- light1=0;
- light0=0;
- }
- if(f6_flag>=56&&f6_flag<64)
- {
-
- light4=0;
- light3=0;
- light2=LED_P0[(f6_flag-48)%8];
- light1=0;
- light0=0;
- }
- if(f6_flag>=64&&f6_flag<72)
- {
-
- light4=0;
- light3=0;
- light2=0;
- light1=LED_P0[(f6_flag-56)%8];
- light0=0;
- }
- if(f6_flag>=72&&f6_flag<80)
- {
-
- light4=0;
- light3=0;
- light2=0;
- light1=0;
- light0=LED_P0[(f6_flag-64)%8];
- }
- if(f6_flag>=80)
- {
- f6_flag=0;
- light0=0x01;
- light1=0x00;
- light2=0x00;
- light3=0x00;
- light4=0x00;
- }
- while(sw_zdy == 0);
-
- }
- }
-
- void f_7(void)
- {
- if(sw_zdy==0)
- {
- f7_flag++;
- if(f7_flag>=0&&f7_flag<8)
- {
- light0=LED_P2[f7_flag];
- light1=0;
- light2=0;
- light3=0;
- light4=LED_P0[f7_flag%8];
- }
- if(f7_flag>=8&&f7_flag<16)
- {
- light0=0;
- light1=LED_P2[f7_flag%8];
- light2=0;
- light3=LED_P0[f7_flag%8];
- light4=0;
- }
- if(f7_flag>=16&&f7_flag<21)
- {
- light0=0;
- light1=0;
- light2=LED_F7[f7_flag-16];
- light3=0;
- light4=0;
- }
- if(f7_flag>=21)
- {
- f7_flag=0;
- light0=LED_P2[f7_flag%8];
- light1=0x00;
- light2=0x00;
- light3=0x00;
- light4=LED_P0[f7_flag%8];
- }
- while(sw_zdy==0);
- }
- }
-
- void f_8(void)
- {
- uchar i;
- if(sw_zdy==0)
- {
- f7_flag++;
- if(f7_flag>=0&&f7_flag<8)
- {
- light0=LED_P2[f7_flag];
- light1=0;
- light2=0;
- light3=0;
- light4=LED_P0[f7_flag%8];
- }
- if(f7_flag>=8&&f7_flag<16)
- {
- light0=0;
- light1=LED_P2[f7_flag%8];
- light2=0;
- light3=LED_P0[f7_flag%8];
- light4=0;
- }
- if(f7_flag>=16&&f7_flag<20)
- {
- light0=0;
- light1=0;
- light2=LED_F7[f7_flag-16];
- light3=0;
- light4=0;
- }
- if(f7_flag==20)
- {
- light0=0x00;
- light1=0x00;
- light2=0x18;
- light3=0x00;
- light4=0x00;
- bell=0;
- for(i=0;i<100;i++)
- {
- bell=!bell;
- delay(2);
- }
- }
-
- if(f7_flag>20&&f7_flag<=24)
- {
- light0=0;
- light1=0;
- light2=LED_F8[f7_flag-20];
- light3=0;
- light4=0;
- }
-
- if(f7_flag>24&&f7_flag<32)
- {
- light0=0;
- light1=LED_P0[f7_flag%8];
- light2=0;
- light3=LED_P2[f7_flag-24];
- light4=0;
- }
-
- if(f7_flag>=32&&f7_flag<40)
- {
- light0=LED_P0[f7_flag-32];
- light1=0;
- light2=0;
- light3=0;
- light4=LED_P2[f7_flag-32];
- }
- if(f7_flag>=40)
- {
- f7_flag=0;
- }
- while(sw_zdy==0);
- }
- }
-
- void f_9(void)
- {
- uint i;
- if(f9_slow == 0)
- {
- f5_flag++;
- if(f5_flag>=0&&f5_flag<8)
- {
- light0=LED_P2[f5_flag];
- light1=0;
- light2=0;
- light3=0;
- light4=0;
- }
- if(f5_flag>=8&&f5_flag<16)
- {
- light0=0;
- light1=LED_P2[f5_flag%8];
- light2=0;
- light3=0;
- light4=0;
- }
- if(f5_flag>=16&&f5_flag<24)
- {
- light0=0;
- light1=0;
- light2=LED_P2[f5_flag%8];
- light3=0;
- light4=0;
- }
- if(f5_flag>=24&&f5_flag<32)
- {
- light0=0;
- light1=0;
- light2=0;
- light3=LED_P2[f5_flag%8];
- light4=0;
- }
- if(f5_flag>=32&&f5_flag<40)
- {
- light0=0;
- light1=0;
- light2=0;
- light3=0;
- light4=LED_P2[f5_flag%8];
- }
- if(f5_flag==39)
- {
- light0=0;
- light1=0;
- light2=0;
- light3=0;
- light4=0x80;
- bell=0;
- for(i=0;i<100;i++)
- {
- bell=!bell;
- delay(2);
- }
- }
- if(f5_flag>=40)
- {
-
- f5_flag=0;
- light0=0x01;
- }
-
- while(f9_slow == 0);
-
- }
-
- }
-
- void f_10(void)
- {
- uchar i;
- if(f10_slow==1)
- {
- f7_flag++;
- if(f7_flag>=0&&f7_flag<8)
- {
- light0=LED_P2[f7_flag];
- light1=0;
- light2=0;
- light3=0;
- light4=LED_P0[f7_flag%8];
- }
- if(f7_flag>=8&&f7_flag<16)
- {
- light0=0;
- light1=LED_P2[f7_flag%8];
- light2=0;
- light3=LED_P0[f7_flag%8];
- light4=0;
- }
- if(f7_flag>=16&&f7_flag<20)
- {
- light0=0;
- light1=0;
- light2=LED_F7[f7_flag-16];
- light3=0;
- light4=0;
- }
- if(f7_flag==20)
- {
- light0=0x00;
- light1=0x00;
- light2=0x18;
- light3=0x00;
- light4=0x00;
- bell=0;
- for(i=0;i<100;i++)
- {
- bell=!bell;
- delay(2);
- }
- }
- if(f7_flag>20&&f7_flag<=24)
- {
- light0=0;
- light1=0;
- light2=LED_F8[f7_flag-20];
- light3=0;
- light4=0;
- }
-
- if(f7_flag>24&&f7_flag<32)
- {
- light0=0;
- light1=LED_P0[f7_flag%8];
- light2=0;
- light3=LED_P2[f7_flag-24];
- light4=0;
- }
-
- if(f7_flag>=32&&f7_flag<40)
- {
- light0=LED_P0[f7_flag-32];
- light1=0;
- light2=0;
- light3=0;
- light4=LED_P2[f7_flag-32];
- }
- if(f7_flag>=40)
- {
- f7_flag=0;
- }
- while(f10_slow==1);
- }
-
- }
- void f_11()
- {
- uchar h;
- if(sw_zdy==0)
- {
- switch(f11_flag)
- {
- case 0:{f11_flag++;light0=0x01;light1=0;light2=0;light3=0;light4=0;break;}
- case 1:{f11_flag++;light0=0x88;light1=0;light2=0;light3=0;light4=0;break;}
- case 2:{f11_flag++;light0=0x40;light1=0x40;light2=0;light3=0;light4=0;break;}
- case 3:{f11_flag++;light0=0;light1=0x02;light2=0x20;light3=0;light4=0;break;}
- case 4:{f11_flag++;light0=0;light1=0x10;light2=0;light3=0x10;light4=0;break;}
- case 5:{f11_flag++;light0=0;light1=0;light2=0x01;light3=0x10;light4=0;break;}
- case 6:{f11_flag++;light0=0;light1=0;light2=0x10;light3=0x10;light4=0;break;}
- case 7:{f11_flag++;light0=0;light1=0;light2=0;light3=0x11;light4=0;break;}
- case 8:{f11_flag++;light0=0;light1=0;light2=0;light3=0x10;light4=0;break;}
- case 9:{f11_flag++;light0=0;light1=0;light2=0;light3=0x10;light4=0x01;break;}
- case 10:{f11_flag++;light0=0;light1=0;light2=0;light3=0x10;light4=0x10;break;}
- case 11:{f11_flag=0;light0=0;light1=0;light2=0;light3=0x00;light4=0x88;break;}
-
- }
-
- if(f11_flag==0)
- {
- for(h=0;h<50;h++)
- {bell=0;
- delay(2);
- bell=!bell;
- }
- }}
- while(sw_zdy == 0);
-
- }
-
- void f_12()
- {
- uchar h;
- if(sw_zdy==0)
- {
- switch(f12_flag)
- {
- case 0:{f12_flag++;light0=0x01;light1=0;light2=0;light3=0;light4=0;break;}
- case 1:{f12_flag++;light0=0x88;light1=0;light2=0;light3=0;light4=0;break;}
- case 2:{f12_flag++;light0=0x40;light1=0x40;light2=0;light3=0;light4=0;break;}
- case 3:{f12_flag++;light0=0;light1=0x02;light2=0x20;light3=0;light4=0;break;}
- case 4:{f12_flag++;light0=0;light1=0x10;light2=0;light3=0x10;light4=0;break;}
- case 5:{f12_flag++;light0=0;light1=0;light2=0x01;light3=0x10;light4=0;break;}
- case 6:{f12_flag++;light0=0;light1=0;light2=0x10;light3=0x10;light4=0;break;}
- case 7:{f12_flag++;light0=0;light1=0;light2=0;light3=0x11;light4=0;break;}
- case 8:{f12_flag++;light0=0;light1=0;light2=0;light3=0x10;light4=0;break;}
- case 9:{f12_flag++;light0=0;light1=0;light2=0;light3=0x10;light4=0x00;break;}
- case 10:{f12_flag++;light0=0;light1=0;light2=0;light3=0x10;light4=0x02;break;}
- case 11:{f12_flag=0;light0=0;light1=0;light2=0;light3=0x10;light4=0x80;break;}
-
- }
-
- if(f12_flag==0)
- {
- for(h=0;h<50;h++)
- {bell=0;
- delay(2);
- bell=!bell;
- }
- }}
- while(sw_zdy == 0);
-
- }
- void f_13(void)
- {
-
- if(sw_zdy == 0)
- {
- f13_flag++;
- if(f13_flag>=0&&f13_flag<4)
- {
- light0=0;
- light1=0;
- light2=LED_P3[f13_flag];
- light3=0;
- light4=0;
- }
- if(f13_flag>=4&&f13_flag<12)
- {
- light0=0;
- light1=LED_P33[f13_flag-4];
- light2=0xff;
- light3= LED_P7[f13_flag-4];
- light4=0;
- }
- if(f13_flag>=12&&f13_flag<20)
- {
- light0=LED_P33[f13_flag-12];
- light1=0xff;
- light2=0xff;
- light3=0xff;
- light4=LED_P7[f13_flag-12];
- }
-
- if(f13_flag>=20)
- {
-
- f13_flag=0;
- light2=0x18;
- light0=0;
- light1=0;
- light3=0;
- light4=0;
- }
-
- while(sw_zdy == 0);
-
- }
-
- }
复制代码
|