⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 跑马灯.c

📁 基于mcs51的单片机32个LED的跑马灯程序
💻 C
字号:
///////////////////////////////////////////////////////////
//
//   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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -