基于stc15f2k60s2芯片单片机编程(流动字幕)

程序思路

一共两种方法,方法一用的是for循环实现的。逻辑比较复杂。第二种方法逻辑比较简单,但是程序很长。其实复制粘贴的话,也不是太麻烦。具体程序如下:

流动字幕①

#include
#include
int a,n=0,i=0;
unsigned int shuzu1[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0xff,0x80,0x90};
unsigned int shuzu2[]={0xc0,0xf8,0x82,0x92,0x99,0xb0,0xa4,0xf9,0x80,0XFF,0x90};
void delay1ms();


void main()
{
	
 P2=0XA0;P0=0X00;P2=0X80;P0=0XFF;
	while(1)
	{
		 a++;
	 if(a==100)
	 {
	  a=0;
		 i++;
	 }
	 if(i<=7)
	 {
   for(n=0;n<=i;n++)
	 {		 
	 P2=(P2&0X1F)|0Xc0;
	P0=0X80>>n;
	P2&=0X01;
	P2=(P2&0X1F)|0Xe0;
	P0=0XFF;
	P0=shuzu1[i-n];
	P2&=0X1F;
	 delay1ms();
	 }
   }
	 if(i>8)
	 {
    for(n=0;n<(16-i);n++)
	 {		 
	 P2=(P2&0X1F)|0Xc0;
	P0=0X01<<n;
	P2&=0X01;
	P2=(P2&0X1F)|0Xe0;
	P0=0XFF;
	P0=shuzu2[16-i-n];
	P2&=0X1F;
	 delay1ms();
	 }
  }
	 if(i==16)
		 i=0;
}
}
void delay1ms()		//@11.0592MHz
{
	unsigned char i, j;

	_nop_();
	_nop_();
	_nop_();
	i = 11;
	j = 190;
	do
	{
		while (--j);
	} while (--i);
}

流动字幕②

#include 
#include 
void Timer0Init()	;
void zhduan();
void Delay500ms()	;
unsigned char i;
unsigned char shuzu[]={0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
unsigned char huancun[]={0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff};
void main()
{
    Timer0Init();
  P2=0X80;P0=0XFF;P2=0X1F;
	P2=0XA0;P0=0X00;P2=0X1F;
	while(1)
	{
		switch(i)
		{
		case(1):
			huancun[0]=0xff;
			huancun[1]=0xff;
			huancun[2]=0xff;
			huancun[3]=0xff;
			huancun[4]=0xff;
			huancun[5]=0xff;
			huancun[6]=0xff;
			huancun[7]=shuzu[0]; 
		break;
		case(2):
			huancun[0]=0xff;
			huancun[1]=0xff;
			huancun[2]=0xff;
			huancun[3]=0xff;
			huancun[4]=0xff;
			huancun[5]=0xff;
			huancun[6]=shuzu[0];
			huancun[7]=shuzu[1]; 
		break;
		case(3):
			huancun[0]=0xff;
			huancun[1]=0xff;
			huancun[2]=0xff;
			huancun[3]=0xff;
			huancun[4]=0xff;
			huancun[5]=shuzu[0];
			huancun[6]=shuzu[1];
			huancun[7]=shuzu[2]; 
		break;
		case(4):
			huancun[0]=0xff;
			huancun[1]=0xff;
			huancun[2]=0xff;
			huancun[3]=0xff;
			huancun[4]=shuzu[0];
			huancun[5]=shuzu[1];
			huancun[6]=shuzu[2];
			huancun[7]=shuzu[3]; 
		break;
		case(5):
			huancun[0]=0xff;
			huancun[1]=0xff;
			huancun[2]=0xff;
			huancun[3]=shuzu[0];
			huancun[4]=shuzu[1];
			huancun[5]=shuzu[2];
			huancun[6]=shuzu[3];
			huancun[7]=shuzu[4]; 
		break;
		case(6):
		huancun[0]=0xff;
			huancun[1]=0xff;
			huancun[2]=shuzu[0];
			huancun[3]=shuzu[1];
			huancun[4]=shuzu[2];
			huancun[5]=shuzu[3];
			huancun[6]=shuzu[4];
			huancun[7]=shuzu[5]; 
		break;
		case(7):
			huancun[0]=0xff;
			huancun[1]=shuzu[0];
			huancun[2]=shuzu[1];
			huancun[3]=shuzu[2];
			huancun[4]=shuzu[3];
			huancun[5]=shuzu[4];
			huancun[6]=shuzu[5];
			huancun[7]=shuzu[6]; 
		break;
		case(8):
			huancun[0]=shuzu[0];
			huancun[1]=shuzu[1];
			huancun[2]=shuzu[2];
			huancun[3]=shuzu[3];
			huancun[4]=shuzu[4];
			huancun[5]=shuzu[5];
			huancun[6]=shuzu[6];
			huancun[7]=shuzu[7]; 
		break;
case(9):
			huancun[0]=shuzu[1];
			huancun[1]=shuzu[2];
			huancun[2]=shuzu[3];
			huancun[3]=shuzu[4];
			huancun[4]=shuzu[5];
			huancun[5]=shuzu[6];
			huancun[6]=shuzu[7];
			huancun[7]=0xff; 
		break;
case(10):
			huancun[0]=shuzu[2];
			huancun[1]=shuzu[3];
			huancun[2]=shuzu[4];
			huancun[3]=shuzu[5];
			huancun[4]=shuzu[6];
			huancun[5]=shuzu[7];
			huancun[6]=0xff;
			huancun[7]=0xff;
		break;
case(11):
			huancun[0]=shuzu[3];
			huancun[1]=shuzu[4];
			huancun[2]=shuzu[5];
			huancun[3]=shuzu[6];
			huancun[4]=shuzu[7];
			huancun[5]=0xff;
			huancun[6]=0xff;
			huancun[7]=0xff;
		break;
case(12):
			huancun[0]=shuzu[4];
			huancun[1]=shuzu[5];
			huancun[2]=shuzu[6];
			huancun[3]=shuzu[7];
			huancun[4]=0xff;
			huancun[5]=0xff;
			huancun[6]=0xff;
			huancun[7]=0xff;
		break;
case(13):
			huancun[0]=shuzu[5];
			huancun[1]=shuzu[6];
			huancun[2]=shuzu[7];
			huancun[3]=0xff;
			huancun[4]=0xff;
			huancun[5]=0xff;
			huancun[6]=0xff;
			huancun[7]=0xff;
		break;
case(14):
			huancun[0]=shuzu[6];
			huancun[1]=shuzu[7];
			huancun[2]=0xff;
			huancun[3]=0xff;
			huancun[4]=0xff;
			huancun[5]=0xff;
			huancun[6]=0xff;
			huancun[7]=0xff; 
		break;
case(15):
			huancun[0]=shuzu[7];
			huancun[1]=0xff;
			huancun[2]=0xff;
			huancun[3]=0xff;
			huancun[4]=0xff;
			huancun[5]=0xff;
			huancun[6]=0xff;
			huancun[7]=0xff; 
		break;
case(16):
			huancun[0]=0xff;
			huancun[1]=0xff;
			huancun[2]=0xff;
			huancun[3]=0xff;
			huancun[4]=0xff;
			huancun[5]=0xff;
			huancun[6]=0xff;
			huancun[7]=0xff;
		break;

	}
 zhduan();
	}
}



void weixuan() interrupt 1
{
	unsigned char j;
	P2=0XC0;
	P0=1<<j;
	P2=0X1F;
	P2=0XE0;
	P0=huancun[j];
	P2=0x1f;
	j++;
	if(j==8) j=0;
		
	}

	
void zhduan() 
{
Delay500ms();
i++;
	if(i==17) i=0;
}	


void Delay500ms()		//@11.0592MHz
{
	unsigned char i, j, k;

	_nop_();
	_nop_();
	i = 22;
	j = 3;
	k = 227;
	do
	{
		do
		{
			while (--k);
		} while (--j);
	} while (--i);
}



void Timer0Init()		//[email protected]
{
	AUXR |= 0x80;		//?????1T??
	TMOD &= 0xF0;		//???????
	TL0 = 0xCD;		//??????
	TH0 = 0xD4;		//??????
	TF0 = 0;		//??TF0??
	TR0 = 1;		//???0????
	EA=1;
	ET0=1;
}

你可能感兴趣的:(基于stc15f2k60s2芯片单片机编程(流动字幕))