通過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);
-
- }
-
- }
復制代碼
|