LED花样流水灯和数码管变换

/************************************************************************
工程名称:LEDflash AND Digitron
工程功能:花样流水灯和动态数码管变换
时    间: 2012-04-28
作    者:syd989
*************************************************************************/
#include<at89x52.h>
#define num 6                                   //流水灯样式
unsigned char code tab[]={                      //数码管选值
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71
};
unsigned char code tab1[]={0xe4,0xe3,0xe2,0xe1};   //74hc138译码器选址
code unsigned char tab3[num][8]=
{
	{0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80},   //逐个亮
	{0x01,0x03,0x07,0x0f,0x1f,0x3f,0x7f,0xff},   //逐一亮
	{0xff,0x7f,0x3f,0x1f,0x0f,0x07,0x03,0x01},   //逐个灭
	{0x81,0xc3,0xe7,0xff,0xe7,0xc3,0x81,0x00},   //两端亮中间灭
	{0x01,0x03,0x07,0x0f,0x1f,0x3f,0x7f,0xff},   //左端逐一亮
	{0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff},   //右端逐一亮
};
void delay(unsigned int z);                     //不精确延时函数声明
void LED();                                     //花样LED流水灯函数声明
void shuma();												//动态扫描数码管变换

void main()                                     //主函数  调用LED()和shuma()函数
{
	while(1)
	{
		LED();
		shuma();
	}
}
void delay(unsigned int z)     //不精确延时
{
	unsigned int x,y;
	for(x=z;x>0;x--)
	for(y=120;y>0;y--); 
}

void LED()
{
	unsigned int i,j;                     
   P2=0xe0;                                  //74hc138使能
   P1=0x00;                                  
	for(j=0;j<num;j++)                        //花样LED流水灯
	{
		for(i=0;i<8;i++)
		{
			P1=tab3[j][i];	
			delay(40);		
		}
	}
}

void shuma()
{
	unsigned int m,n; 	
	for(m=0;m<16;m++)                         //动态扫描数码管变换
	{
		for(n=0;n<4;n++)
		{ 
			P2=tab1[n]; 
			P1=tab[m];
			delay(30);
		}
	}
}
/************************************************************************
								End  of  file
*************************************************************************/


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值