|
5黑幣
- #include<REG52.h>
- #define uchar unsigned char
- unsigned char PWM_COUNT;
- unsigned int HUXI_COUNT;
- unsigned char PWM_VLAUE;
- bit direc_flag;
- sbit led1=P0^0;
- sbit led2=P0^1;
- sbit led3=P0^2;
- sbit led4=P0^3;
- sbit led5=P0^4;
- sbit led6=P0^5;
- sbit led7=P0^6;
- sbit led8=P0^7;
- sbit w1=P2^4;
- sbit key1 = P2^0;
- sbit key2 = P2^1;
- unsigned char smg_date[]=
- {0xc0,0xf9,0xa4,0xb0,0x99,0x92,
- 0x82,0xf8,0x80,0x98,0x88,0x83,
- 0xa7,0xa1,0x86,0x8e};
- uchar an = 0;
- void keyscan();
- void delayms (uchar time)//???
- {
- for(time; time>0; time--)
- {
- TMOD = 0x01;
- TH0 = 0xfc;
- TL0 = 0x18;
- TR0 = 1; //?????????0
- while(TF0!=1);//???????
- EA=1;
- ET0 = 1;
- TR0 = 0;
- }
- }
- void scan_key (void)
- {
- if (!key1)
- {
- delayms (10);
- if (!key1)
- {
- delayms (5);
- while (!key1);
- an++;
- if (an==9)
- {
- an = 0;
- }
- }
- }
- }
- void main (void)
- {
- w1=0;
- while (1)
- {
- scan_key ();
- if (an==0)
- {
-
- led1 = 1;
- led2 = 1;
- led3 = 1;
- led4 = 1;
- led5 = 1;
- led6 = 1;
- led7 = 1;
- led8 = 1;
- P1=smg_date[0];
- an=0;
- }
- if (an==1)
- {
-
- led1 = 0;
- led2 = 1;
- led3 = 1;
- led4 = 1;
- led5 = 1;
- led6 = 1;
- led7 = 1;
- led8 = 1;
- P1=smg_date[1];
- an=1;
- }
- if (an==2)
- {
-
- led1 = 1;
- led2 = 0;
- led3 = 1;
- led4 = 1;
- led5 = 1;
- led6 = 1;
- led7 = 1;
- led8 = 1;
- P1=smg_date[2];
- an=2;
- }
- if (an==3)
- {
- led1 = 1;
- led2 = 1;
- led3 = 0;
- led4 = 1;
- led5 = 1;
- led6 = 1;
- led7 = 1;
- led8 = 1;
- P1=smg_date[3];
- an=3;
- }
- if (an==4)
- {
-
- led1 = 1;
- led2 = 1;
- led3 = 1;
- led4 = 0;
- led5 = 1;
- led6 = 1;
- led7 = 1;
- led8 = 1;
- P1=smg_date[4];
- an=4;
- }
- if (an==5)
- {
- led1 = 1;
- led2 = 1;
- led3 = 1;
- led4 = 1;
- led5 = 0;
- led6 = 1;
- led7 = 1;
- led8 = 1;
- P1=smg_date[5];
- an=5;
- }
- if (an==6)
- {
- led1 = 1;
- led2 = 1;
- led3 = 1;
- led4 = 1;
- led5 = 1;
- led6 = 0;
- led7 = 1;
- led8 = 1;
- P1=smg_date[6];
- an=6;
- }
- if (an==7)
- {
-
- led1 = 1;
- led2 = 1;
- led3 = 1;
- led4 = 1;
- led5 = 1;
- led6 = 1;
- led7 = 0;
- led8 = 1;
- P1=smg_date[7];
- an=7;
- }
- if (an==8)
- {
-
- led1 = 1;
- led2 = 1;
- led3 = 1;
- led4 = 1;
- led5 = 1;
- led6 = 1;
- led7 = 1;
- led8 = 0;
- P1=smg_date[8];
- }
- if (an==9)
- {
-
- led1 = 1;
- led2 = 1;
- led3 = 1;
- led4 = 1;
- led5 = 1;
- led6 = 1;
- led7 = 1;
- led8 = 1;
- P1=smg_date[9];
- }
- if(key2==0)
- {
- delayms(5);
- if(key2==0)
- {
- while(!key2);
- TR0=1;
- }
- }
- }
-
- switch(an)
- {
- case 1: if (PWM_COUNT==PWM_VLAUE)
- {
- led1=1;
- }
- if(PWM_COUNT==10)
- {
- led1=0;
- PWM_COUNT=0;
- }
- break;
- case 2: if (PWM_COUNT==PWM_VLAUE)
- {
- led2=1;
- }
- if(PWM_COUNT==10)
- {
- led2=0;
- PWM_COUNT=0;
- }
- break;
- case 3: if (PWM_COUNT==PWM_VLAUE)
- {
- led3=1;
- }
- if(PWM_COUNT==10)
- {
- led3=0;
- PWM_COUNT=0;
- }
- break;
- case 4: if (PWM_COUNT==PWM_VLAUE)
- {
- led4=1;
- }
- if(PWM_COUNT==10)
- {
- led4=0;
- PWM_COUNT=0;
- }
- break;
- case 5: if (PWM_COUNT==PWM_VLAUE)
- {
- led5=1;
- }
- if(PWM_COUNT==10)
- {
- led5=0;
- PWM_COUNT=0;
- }
- break;
- case 6: if (PWM_COUNT==PWM_VLAUE)
- {
- led6=1;
- }
- if(PWM_COUNT==10)
- {
- led6=0;
- PWM_COUNT=0;
- }
- break;
- case 7: if (PWM_COUNT==PWM_VLAUE)
- {
- led7=1;
- }
- if(PWM_COUNT==10)
- {
- led7=0;
- PWM_COUNT=0;
- }
- break;
- case 8: if (PWM_COUNT==PWM_VLAUE)
- {
- led8=1;
- }
- if(PWM_COUNT==10)
- {
- led8=0;
- PWM_COUNT=0;
- }
- break;
- }
- }
- void T0_timer() interrupt 1
- {
- PWM_COUNT++;
- HUXI_COUNT++;
- if((HUXI_COUNT==600)&&(direc_flag==1))
- {
- HUXI_COUNT=0;
- PWM_VLAUE--;
- if(PWM_VLAUE==1)
- direc_flag=0;
- }
- if((HUXI_COUNT==600)&&(direc_flag==0))
- {
- HUXI_COUNT=0;
- PWM_VLAUE++;
- if(PWM_VLAUE==9)
- direc_flag=1;
- }
-
- }
復(fù)制代碼
|
|