跑马灯.c

来自「基于mcs51的单片机32个LED的跑马灯程序」· C语言 代码 · 共 112 行

C
112
字号
///////////////////////////////////////////////////////////
//
//   ProjectName : 跑马灯.spj
//   Source File : 跑马灯.c
//   Additional  : ****.c
//   Head Files  : ****.h
//   Additional  : ****.h
//   Version     : *.**
//   Writen By   : ###
//   Created     : 03-3-31 16:23:42
//
///////////////////////////////////////////////////////////
#include<stdio.h>
#include<reg51.h>
#include<intrins.h>
   unsigned int tc;
   
void main()
{
  void delay(int t);
  void light();
  while(1)
  {
  	tc=2000;
  	while(tc>1000)
    {
		light();
		tc=tc-1000;
	}
	while(tc>500)
    {
		light();
		tc=tc-200;
	}
	while(tc>=100)
	{	light();
		tc=tc-50;
	}
	while(tc>=10)
	{	light();
		tc=tc-5;
	}
	while(tc>=2)
	{	light();
		tc=tc-1;
	}
  }
}

void light()
{
	unsigned char i,c;
	c=0x01;
	for (i=1;i<9;i++)
	{	
		P0=c;
		delay(tc);
		//c=c<<1|1;
		c=c=_crol_(c,1);
		if (i==8)
 	    {c=0;
		P0=0;
		}
	}
	c=0x01;
	for(i=1;i<9;i++)
	{	
		P1=c;
		delay(tc);
		//c=c>>1|0x80;
		c=c=_crol_(c,1);
		if (i==8) 
		{P1=0;
		c=0;
		}
	}
	c=0x80;
	for(i=1;i<9;i++)
	{	
		P2=c;
		delay(tc);
		//c=c>>1|0x80;
		c=c=_cror_(c,1);
		if (i==8)
 	    {c=0;
		P2=0;
		}
	}
	c=0x01;
	for(i=1;i<9;i++)
	{	
	P3=c;
	delay(tc);
	//c=c>>1|0x80;
	c=c=_crol_(c,1);
	if (i==8)
    {c=0;
	P3=0;
	}
	}
}
void Delay(unsigned int i)
{
	for (;i>0;i--)
	{
		unsigned int j;
		for (j=0;j<40;j++)
		{;}
	}
}	

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?