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

📄 max7219all.c

📁 Max7219完全控制
💻 C
字号:
/*max7219完全控制包括闪烁字符*/
#include "REG52.H"
#include "STDIO.H"
#include "INTRINS.H"
#include "ABSACC.H"
#include "MATH.H"
#define circle 65535 //rund of circle form quesz

sbit din=P1^0;
sbit load=P1^1;
sbit clk=P1^2;



unsigned char position=0;//flash position
unsigned char first=0;
unsigned char second=0;
unsigned char third=0;
unsigned char forth=0;//4 number show
unsigned int flashcount;//if flashcount<1000 let it display 0x0f,>1000 show the number

void write7219(unsigned char address,unsigned char dat);

void LockInitial(void);
//this is shows that you can send a BCD code to show in led.
void FreeInitial(void);
//this is shows that you can choose all you want to show in led.
void startdisplay(void);
//show star display
void Display(void);
//display all the time expect seting
void SetDisplay(void);
//only work at seting time
void ShowDisplay(void);//only show the code "S T E I N G"

void delay10ms(void);

/************************************************************************
/*   main mode
/************************************************************************/
void main (void)
{
	unsigned char i;
	IP=0x0a;
	TH0=0xff;
	TL0=0xfe;
	TH1=0;
	TL1=0;
	TMOD=0x15;
	TCON=0x50;
	IT0=1;
	IT1=1;
	EA=1;
	ET1=1;
	ET0=1;

	startdisplay();
	while(1)
	{





		Display();
	}

}
//7219 send I&D,first send address,and then send dat
//
void write7219(unsigned char address,unsigned char dat)
{
	unsigned char i;
	load=0;
	for(i=0;i<8;i++)
	{
		clk=0;
		din=(bit)(address  &0x80);
		address<<=1;
		clk=1;
	}
	;
	for(i=0;i<8;i++)
	{
		clk=0;
		din=(bit)(dat&0x80);
		dat<<=1;
		clk=1;
	}
	;
	load=1;
}
void LockInitial(void)
{
	write7219(0x0c,0x01);//this is the power mode,it shows working now
	write7219(0x0f,0x00);
	write7219(0x09,0xff);//all instrans
	write7219(0x0b,0x07);//scan limit ,use all
	write7219(0x0a,0x08);//lighting step =4
}
void FreeInitial(void)
{
	write7219(0x0c,0x01);//this is the power mode,it shows working now
	write7219(0x0f,0x00);
	write7219(0x09,0x00);//do not instrans
	write7219(0x0b,0x07);//scan limit ,use all
	write7219(0x0a,0x04);//lighting step =4
}

//this is the code for delay
void delay20ms(void)
{
	int i,a,b,c;
	for (i=0;i<6000;i++)
	{
		a=10;
		b=10;
		c=a*b;
	}
}

void setdisplay(void)
{
	flashcount++;
	if (flashcount>200)
	{
		flashcount=0;
	}


	LockInitial();//prepar to display

	switch (position)
	{
		case 0:
		{
			if (flashcount<100)
			{
				write7219(0x05,first);
				write7219(0x06,second);
				write7219(0x07,third);
				write7219(0x08,forth);
			}
			else
			{
				write7219(0x05,0x0f);
				write7219(0x06,second);
				write7219(0x07,third);
				write7219(0x08,forth);
			}
			break;
		}
		case 1:
		{
			if (flashcount<100)
			{
				write7219(0x05,first);
				write7219(0x06,second);
				write7219(0x07,third);
				write7219(0x08,forth);
			}
			else
			{
				write7219(0x05,first);
				write7219(0x06,0x0f);
				write7219(0x07,third);
				write7219(0x08,forth);
			}
			break;
		}
		case 2:
		{
			if (flashcount<100)
			{
				write7219(0x05,first);
				write7219(0x06,second);
				write7219(0x07,third);
				write7219(0x08,forth);
			}
			else
			{
				write7219(0x05,first);
				write7219(0x06,second);
				write7219(0x07,0x0f);
				write7219(0x08,forth);
			}
			break;
		}
		case 3:
		{
			if (flashcount<100)
			{
				write7219(0x05,first);
				write7219(0x06,second);
				write7219(0x07,third);
				write7219(0x08,forth);
			}
			else
			{
				write7219(0x05,first);
				write7219(0x06,second);
				write7219(0x07,third);
				write7219(0x08,0x0f);
			}
			break;
		}
		default: break;
	}
	;
}

void Display(void)
{
	unsigned char a,b,c,d;
	write7219(0x04,a);
	write7219(0x03,b);
	write7219(0x02,c);
	write7219(0x01,d);
}



void startdisplay(void)
{
	//show star display
	unsigned char i,s;
	for(s=0;s<5;s++)
	{
		FreeInitial();    //this is shows that you can choose all you want to show in led.
		for(i=0;i<9;i++)
		{
			write7219(i,0x42);
		}
		delay10ms();
		for(i=0;i<9;i++)
		{
			write7219(i,0x60);
		}
		delay10ms();
		for(i=0;i<9;i++)
		{
			write7219(i,0x18);
		}
		delay10ms();
		for(i=0;i<9;i++)
		{
			write7219(i,0x0c);
		}
		delay10ms();
	}
}
void delay10ms(void)
{
	int i,a,b,c;
	for (i=0;i<3000;i++)
	{
		a=10;
		b=10;
		c=a*b;
	}
}
void showdisplay(void)
{
	LockInitial();
	write7219(0x04,0x8e);
	write7219(0x03,0x0f);
	write7219(0x02,0x0f);
	write7219(0x01,0x0f);

}

⌨️ 快捷键说明

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