/*-----------------------------------------------Name: Running Lights Date: 2009.5 modified: No content: The cycle of light P1 port corresponding to the 8 LED lights, Results in a circular water-lit effect------------------------------------------------*/#include<reg52.h>//contains the header file, the general situation does not need to change, the header file contains the special function registers the definition/*------------------------------------------------Delay subroutine--------------------------------------------- ---*/voidDelay (unsignedintCNT) { while(--cnt);}/*------------------------------------------------main function----------------------------------------------- -*/Main () {bit flag=0;//set a bit variableP1=0x7f;//the conversion of the initialization value to binary is 0111 1111 while(1)//When 1, the infinite loop is not executed once when it is 0 { if(Flag = =0)//determine if it is 0{delay (30000);//Delay ProgramP1 = P1 >>1;//move left one the statement is equivalent to p1=p1<<1P1 |=0x80;//0000 if(p1==0xFE)//does detection move to the leftmost end? "= =" Indicates whether the value of the 2 end of the detection symbol is equal{flag=1; } } Else{delay (30000);//Delay ProgramP1 = P1 <<1;//move left one the statement is equivalent to p1=p1<<1P1 |=0x01;//0000 0001 if(p1==0x7f)//does detection move to the leftmost end? "= =" Indicates whether the value of the 2 end of the detection symbol is equal{flag=0; } } }}
51 single-chip computer racing lights