Microcontroller experiment 1: running water lamp

flow_LED light experiment code

The single-chip crystal oscillator needs to be adjusted to 11.0592, only in this state can X*110 cycles be approximately equal to X milliseconds

#include <reg52.h>
#include <intrins.h>
#define uint unsigned int
#define uchar unsigned char

void delay()
{
    
    
	uint i,j;
	for(i=1000;i>0;i--)
	{
    
    
	 	for(j=110;j>0;j--);
	}
		
}

void main()
{
    
    
	uchar a = 0Xf8;
	while(1)
	{
    
    
		P2 = a;
		delay();     //延时1s
		a = _crol_(a,1);
	} 
}

Experimental results
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here

Guess you like

Origin blog.csdn.net/The_RedMaple/article/details/111312540