2021-07-03 51单片机1.高低4位交替8次,2.从0到255,3.1+2+3+4...

缘由求老哥帮做一下单片机题。_嵌入式-CSDN问答

#include "REG52.h"
bit k=1;
void main()
{
	unsigned char Xd=0,ss=15,cs=0;
	unsigned int ys=64000;
	while(1)
	{
		P1=ss;
		if(++ys==0&&cs<8)
        {
            k=~k;
            ++cs;
            ss=(k?15:240);
            ys=64000;
        }
	}
}
#include "REG52.h"
bit k=1;
void main()
{
	unsigned char Xd=0,ss=0,cs=0;
	unsigned int ys=64000;
	while(1)
	{
		P1=ss;
		if(++ys==0)
        {
            ++ss;
            ys=64000;
        }
	}
}
#include "REG52.h"
bit k=1;
void main()
{
	unsigned char Xd=0,ss=1,cs=0;
	unsigned int ys=64000;
	while(1)
	{
		P1=ss;
		if(++ys==0)
        {
            ss+=cs++;
            ys=64000;
        }
	}
}

你可能感兴趣的:(51单片机,算法,嵌入式硬件)