51 single-chip computer racing lights

Source: Internet
Author: User

/*-----------------------------------------------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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.