- #include <reg52.h>
- #include "Delay.h"
- sbit K1=P3^0;
- #define uint unsigned int
- #define uchar unsigned char
- bit Timer_1s,Timer_500ms;
- // 数码管段选信号
- uchar code duan[] = {
- 0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,
- //0 1 2 3 4 5 6 7 8 9 A
- 0x7c,0x39,0x5e,0x79,0x71,
- //B C D E F
- 0x76,0x73,0x6e,0x38,0x3e, 0x31,0x50,0X37,0x01,0x40,0x08,0X00,
- //H16 P17 Y18 L19 V20 T21 R22 N23 上— 中- 下-
- };
- uchar T0_Cnt=0;
- // 数码管位选信号
- uchar code wei[] = {
- 0x1c,0x18,0x14,0x10,0x0c,0x08,0x04,0x00
- };
- uchar code SMGCONTENT[]={10,2,2,1,3,27,4,7,27, //A2213 47
- 16,10,17,17,18,24,25,26, 27, //HAPPY_--
- 18,14,23,11,6,6,6,27, //YENB666
- 18,14,23,11,6,6,6,27, //YENB666
- 18,14,23,11,6,6,6,27 }; //YENB666
- uchar LEDBUFF[8];
- uchar LEDFLASHBUFF[8];
- uchar j,leftnum,Mode,i,flash,KeyVal=0;
- uint t;
- void Timer0Init( void )
- {
- TMOD = 0x01;
- TH0 = (65536-5000)/256;
- TL0 = (65536-5000)%256;
- ET0 = 1;
- EA = 1;
- TR0 = 1;
- }
- void Timer1Init( void )
- {
- TMOD = 0x01;
- TH1 = (65536-5000)/256;
- TL1 = (65536-5000)%256;
- ET1 = 1;
- EA = 1;
- TR1 = 1;
- }
- void display();
- void main()
- {
- Timer0Init();
- Timer1Init();
- while (1)
- {
- display();
- }
-
- }
- void display()
- {
-
-
- if(Mode==0)
- {
- for(j=0;j<8;j++)
- {LEDBUFF[j]=SMGCONTENT[j];
- }
- }
- if(Mode==1)
- {
- for(j=0;j<8;j++)
- {LEDBUFF[j]=SMGCONTENT[j+9];}
- }
-
- if(Mode==2)
- {
- for(j=0;j<8;j++)
- {LEDBUFF[j]=SMGCONTENT[j+18];}
- }
-
- if(Mode==3) //左移
- {
- leftnum=0;
- do
- {
- for(j=0;j<8;j++)
- {
- LEDBUFF[j]=SMGCONTENT[j+leftnum];
- }
- Delay(1000);
-
- }
- while(leftnum++<36);
- leftnum=0;
- Mode=0;
- }
-
-
- }
- void Timer0_ISR(void) interrupt 1
- {
-
- TH0=(65536-5000)/256;
- TL0=(65536-5000)%256;
- if(T0_Cnt==200) {T0_Cnt=0;Timer_1s=1;Mode++; }
- T0_Cnt++;
- P0=0x00;
- P2=wei[i];
- if(KeyVal!=0&&flash)
- P0=duan[LEDFLASHBUFF[i]];
- else
- P0=duan[LEDBUFF[i]];
- i++;
- if(i==8) i=0;
-
- }
- void Timer1_ISR(void) interrupt 3
- {
- TH1=(65536-10000)/256;
- TL1=(65536-10000)%256;
- t++;
- if(t==50)
- { t=0;Timer_500ms=1;flash=~flash;}
- if(K1==0)
- {
- Delay(10);
- if(K1==0)
- {KeyVal++;
- while(K1==0);}
- }
- switch(KeyVal)
- {
- case 1 :LEDFLASHBUFF[0]=27;LEDFLASHBUFF[1]=27;
- LEDFLASHBUFF[2]=LEDBUFF[2];LEDFLASHBUFF[3]=LEDBUFF[3];
- LEDFLASHBUFF[4]=LEDBUFF[4];LEDFLASHBUFF[5]=LEDBUFF[5];
- LEDFLASHBUFF[6]=LEDBUFF[6];LEDFLASHBUFF[7]=LEDBUFF[7];
- break;
- case 2 :LEDFLASHBUFF[0]=LEDBUFF[0];LEDFLASHBUFF[1]=LEDBUFF[1];
- LEDFLASHBUFF[2]=27;LEDFLASHBUFF[2]=27;
- LEDFLASHBUFF[4]=LEDBUFF[4];LEDFLASHBUFF[5]=LEDBUFF[5];
- LEDFLASHBUFF[6]=LEDBUFF[6];LEDFLASHBUFF[7]=LEDBUFF[7];
- break;
- case 3 :LEDFLASHBUFF[0]=LEDBUFF[0];LEDFLASHBUFF[1]=LEDBUFF[1];
- LEDFLASHBUFF[2]=LEDBUFF[2];LEDFLASHBUFF[3]=LEDBUFF[3];
- LEDFLASHBUFF[4]=27;LEDFLASHBUFF[5]=27;
- LEDFLASHBUFF[6]=LEDBUFF[6];LEDFLASHBUFF[7]=LEDBUFF[7];
- break;
- case 4 :LEDFLASHBUFF[0]=LEDBUFF[0];LEDFLASHBUFF[1]=LEDBUFF[1];
- LEDFLASHBUFF[2]=LEDBUFF[2];LEDFLASHBUFF[3]=LEDBUFF[3];
- LEDFLASHBUFF[4]=LEDBUFF[4];LEDFLASHBUFF[5]=LEDBUFF[5];
- LEDFLASHBUFF[6]=27;LEDFLASHBUFF[7]=27;
- break;
- default : LEDFLASHBUFF[0]=LEDBUFF[0];LEDFLASHBUFF[1]=LEDBUFF[1];
- LEDFLASHBUFF[2]=LEDBUFF[2];LEDFLASHBUFF[3]=LEDBUFF[3];
- LEDFLASHBUFF[4]=LEDBUFF[4];LEDFLASHBUFF[5]=LEDBUFF[5];
- LEDFLASHBUFF[6]=LEDBUFF[6];LEDFLASHBUFF[7]=LEDBUFF[7];
- break;
- }
-
-
- }
复制代码
A2213_47_叶小宇_实验4.zip
(89.34 KB, 下载次数: 4)
|