- #include<reg51.h>
- #define uchar unsigned char
- sbit P3_7=P3^7;
- sbit P3_2=P3^2;
- sbit P3_3=P3^3;
- int v=3000;
- char LED1[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
- char LED2[]={0x01,0x03,0x07,0x0f,0x1f,0x3f,0x7f,0xff};
- char LED3[]={0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff};
- void jiasu() interrupt 0 { v=v-900;}
- void jiansu() interrupt 2 {v=v+900;}
- uchar delay(int time){
- uchar j;
- for(;time>0;time--)
- for(j=125;j>0;j--){if(P3_7==0){while(P3_7==0);return 1;}}
- /*延迟并判断启停开关是否按下*/
- }
- main(){
- uchar i;
- IT0=1;
- IT1=1;
- EX0=1;
- EX1=1;
- EA=1;
- kaiguan: P0=P2=0;
- if(P3_7==0){while(P3_7==0);
- while(1){
- goto pattern1;
- pattern1: for(i=0;i<8;i++){P0=LED1[i];if(delay(v)) goto kaiguan;if(i==7)P0=0;}
- for(i=0;i<8;i++){P2=LED1[i];if(delay(v)) goto kaiguan;if(i==7)P2=0;}
- goto pattern2;
- pattern2: for(i=7;i>0;i--){P2=LED1[i];if(delay(v)) goto kaiguan;if(i==1)P2=0;}
- P2=0x01;delay(v);
- P2=0;
- for(i=7;i>0;i--){P0=LED1[i];;if(delay(v)) goto kaiguan;if(i==1)P0=0;}
- P0=0x01;delay(v);
- P0=0;
- goto pattern3;
- pattern3: for(i=0;i<8;i++){P0=LED2[i];;if(delay(v)) goto kaiguan ;}
- for(i=0;i<8;i++){P2=LED2[i];;if(delay(v)) goto kaiguan ;}
- P0=P2=0;delay(v);
- goto pattern4;
- pattern4: for(i=0;i<8;i++){P2=LED3[i];;if(delay(v)) goto kaiguan ;}
- for(i=0;i<8;i++){P0=LED3[i];;if(delay(v)) goto kaiguan ;}
- P0=P2=0;delay(v);
- goto pattern5;
- pattern5: for(i=0;i<8;i++){P0=LED2[i];P2=LED3[i];;if(delay(v)) goto kaiguan;}
- P0=P2=0;
- goto pattern6;
- pattern6: for(i=0;i<8;i++){P0=LED3[i];P2=LED2[i];;if(delay(v)) goto kaiguan;}
- P0=P2=0;
- }}}
复制代码 |