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

📄 3_20.c

📁 基于EM78P153的下雪灯
💻 C
字号:
//# include "EM78x153xx.h"


//unsigned int   单个延时
#define short_delay 120
//unsigned char  每4个延时 
#define long_delay  3
//unsigned int   全部完成后延时 
#define all_delay_1   20
#define all_delay_2   20


io unsigned char P6CR  @0x06;
unsigned char PORT6  @0x06  :rpage 0;


//void goDwon(void);
//void delay(unsigned int);
//void delayLong(void);
//void setLed(unsigned char);

const static  char dts [6]={5,1,4,5,6,2};        

const char dext[21][2]={{20,1},
					  {1,2},{1,3},{1,4},{1,5},
					  {2,1},{2,3},{2,4},{2,5},
					  {3,1},{3,2},{3,4},{3,5},
					  {4,1},{4,2},{4,3},{4,5},
					  {5,1},{5,2},{5,3},{5,4},};

/////////////////////////////////////////////////////////
void delay(unsigned int d1)
{   unsigned int e1;
	for(;d1>1;d1--)
	{
		for(e1=5;e1>1;e1--)
		{;}
		
	}
}

//-----------------------------------------------

void setLed(unsigned char x)
{
		unsigned char s1;
		P6CR=0xff;
  		PORT6=0x00;
  		
	  	s1=0x01;
  		s1<<=dts[dext[x][0]];
  		P6CR&=~s1;                 //设置正端为输出态
  		
  		s1=0x01;
  		s1<<=dts[dext[x][1]];
  		P6CR&=~s1;                 //设置负端为输出态
  			
  		s1=0x01;
	  	s1<<=dts[dext[x][0]];
  		PORT6=s1;                //设置正端为高电平
  		
}


//---------------------------------------------------------
void goDwon(void)
{
	char i;
	unsigned char g1;
  	for(i=1;i<25;i++)
  	{			
		for(g1=long_delay;g1>1;g1--)
		{
			P6CR=0xff;
  			PORT6=0x00;
			if(i>4&&i<25) setLed(i-4);
			delay(short_delay);
			
			P6CR=0xff;
  			PORT6=0x00;
			if(i>3&&i<24) setLed(i-3);
			delay(short_delay);
			
			P6CR=0xff;
  			PORT6=0x00;
			if(i>2&&i<23) setLed(i-2);
			delay(short_delay);
			
			P6CR=0xff;
  			PORT6=0x00;
			if(i>1&&i<22) setLed(i-1);
			delay(short_delay);
			
			P6CR=0xff;
  			PORT6=0x00;
			if(i>0&&i<21) setLed(i);
			delay(short_delay);
			
		}
  		
  	}
}

//---------------------------------------------------------



void delayLong()
{
	unsigned char l1,l2,x;
	for(l1=all_delay_1;l1>=1;l1--)
	{
		for(l2=all_delay_2;l2>=1;l2--)
		{
			delay(150);
		}
	}
	
	_asm
	{
		MOV A,0x01
		MOV %x,A         //取R1值
	}
	
	//x%=100;
	for(l1=250;l1>1;l1--)
	{
		while(x>1)
		{
			delay(150);
			delay(150);
			x--;
		}
	}
}


//---------------------------------------------------------

void main()
{
	//CONT=0x9f;    //P65所在管脚设为I/O
	//R1=0x16;      //定时器初始值 
	//CONT&=0xd7;   //启动定时器

_asm
{
  MOV a,@0x9f
  CONTW            //P65所在管脚设为I/O
  MOV  A,@0x12
  MOV  0x01,A    //定时器初始值
  CONTR
  AND A,@0xd7
  CONTW           //启动定时器
  
}

  while(1)
  {
  	P6CR=0xff;
  	PORT6=0x00;
  	delayLong();
  	goDwon();
  	
  }
}

//---------------------------------------------------------

⌨️ 快捷键说明

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