According to the principle of the running light, the IO port outputs a low level sequentially from low to high or from high to low.1. Experimental Wiring Diagram
Code:Delay function:
void delay(void)//Delay for a period of time{ unsigned int n; for(n=0;n<30000;n++) ;}
main function:
void main(void){ unsigned char i; while(1) { P1=0xff;//Initialize P1 delay(); for(i=0;i<8;i++)//Set loop count to 8 { P1=P1>>1; //Right shift each bit of P1 by 1, high bits filled with 0 delay(); //Call delay function } }}
