功能描述

1、51+Proteus8.10;

2、驱动MAX7219实现三个引脚控制八位数码管显示;

仿真设计

5016-单片机数码管滚动显示(仿真+程序)_嵌入式硬件

程序设计

/**********************************************************************/
#include <reg52.h>
#include <stdio.h>
#define uchar unsigned char

void delayms(unsigned int ms);
/************************************************************************
                              I/O定义
*************************************************************************/
sbit DIN=P0^0;//数据输入端	   
sbit LOAD=P0^1;//地址锁存端
sbit CLK=P0^2; //时钟输入端
sbit P2_0=P2^0;
sbit P2_1=P2^1;
sbit P2_2=P2^2;
sbit P2_5=P2^5;
sbit P2_6=P2^6;
sbit P2_7=P2^7;
/************************************************************************
                              数据输入
*************************************************************************/
void send(uchar add,uchar dat)
{
	uchar ADS,i,j;
	CLK=0;
	LOAD=0;
	DIN=0;
	i=4;
	while(i<16)
	{
		if(i<8)
		{
			ADS=add;
		}
		else
		{
			ADS=dat;
		}
		for(j=8;j>=1;j--)
		{
			if((ADS&0x80)==0)
			{     
				DIN=0 ;
			}
			else 
			{     
				DIN=1;
			}
			ADS=ADS<<1;
			CLK=1;	 
			CLK=0; 
		}
		i=i+8;
	}
	LOAD=1;
}

/************************************************************************
                               主函数
*************************************************************************/

void main(void)
{
	uchar d=0;
	
	send(0x0c,0x01);//正常状态

	send(0x0b,0x07);//设置扫描范围DIG0-7

	send(0x0a,0x05);//设置亮度11/32

	send(0x09,0xff);//采用译码方式

	while(1)
	{ 	
		for(d=0;d<10;d++)
		{
			switch(d)
			{
				case 0:send(0x01,0x00);send(0x02,0x01);send(0x03,0x02);send(0x04,0x03);send(0x05,0x04);send(0x06,0x05);send(0x07,0x06);send(0x08,0x07);break;
				case 1:send(0x01,0x01);send(0x02,0x02);send(0x03,0x03);send(0x04,0x04);send(0x05,0x05);send(0x06,0x06);send(0x07,0x07);send(0x08,0x08);break;
				case 2:send(0x01,0x02);send(0x02,0x03);send(0x03,0x04);send(0x04,0x05);send(0x05,0x06);send(0x06,0x07);send(0x07,0x08);send(0x08,0x09);break;
				case 3:send(0x01,0x03);send(0x02,0x04);send(0x03,0x05);send(0x04,0x06);send(0x05,0x07);send(0x06,0x08);send(0x07,0x09);send(0x08,0x00);break;
				case 4:send(0x01,0x04);send(0x02,0x05);send(0x03,0x06);send(0x04,0x07);send(0x05,0x08);send(0x06,0x09);send(0x07,0x00);send(0x08,0x01);break;
				case 5:send(0x01,0x05);send(0x02,0x06);send(0x03,0x07);send(0x04,0x08);send(0x05,0x09);send(0x06,0x00);send(0x07,0x01);send(0x08,0x02);break;
				case 6:send(0x01,0x06);send(0x02,0x07);send(0x03,0x08);send(0x04,0x09);send(0x05,0x00);send(0x06,0x01);send(0x07,0x02);send(0x08,0x03);break;
				case 7:send(0x01,0x07);send(0x02,0x08);send(0x03,0x09);send(0x04,0x00);send(0x05,0x01);send(0x06,0x02);send(0x07,0x03);send(0x08,0x04);break;
				case 8:send(0x01,0x08);send(0x02,0x09);send(0x03,0x00);send(0x04,0x01);send(0x05,0x02);send(0x06,0x03);send(0x07,0x04);send(0x08,0x05);break;
				case 9:send(0x01,0x09);send(0x02,0x00);send(0x03,0x01);send(0x04,0x02);send(0x05,0x03);send(0x06,0x04);send(0x07,0x05);send(0x08,0x06);break;
				default:send(0x01,0x00);send(0x02,0x00);send(0x03,0x00);send(0x04,0x00);send(0x05,0x00);send(0x06,0x00);send(0x07,0x00);send(0x08,0x00);break;
			}
			delayms(1000);
//			send(0x01,0x00);send(0x02,0x02);
//			send(0x01,0x04);send(0x02,0x07);
//			send(0x01,0x08);send(0x02,0x05);
		}
	}
}

void delayms(unsigned int ms)
{
	unsigned int i,j;
	for(j=0;j<ms;j++)
		for(i=0;i<115;i++);
}