8*8点阵显示数字

完整仿真图:

完整代码:

#include "reg51.h"			 
#include<intrins.h>

typedef unsigned int u16;	  
typedef unsigned char u8;

sbit SHCP=P3^1;
sbit STCP=P3^3;
sbit DS=P3^0;

u8 ledduan[]={0x00,0x00,0x3e,0x41,0x41,0x41,0x3e,0x00};
u8 ledwei[]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};
/*******************************************************************************

*******************************************************************************/
void delay(u16 i)
{
	while(i--);	
}

/*******************************************************************************

*******************************************************************************/
void Hc595SendByte(u8 dat)
{
	u8 a;
	SHCP=0;
	STCP=0;
	for(a=0;a<8;a++)
	{
		DS=dat>>7;
		dat<<=1;

		SHCP=1;
		_nop_();
		_nop_();
		SHCP=0;	
	}

	STCP=1;
	_nop_();
	_nop_();
	STCP=0;
}

/*******************************************************************************

*******************************************************************************/
void main()
{			
	u8 i;
	while(1)
	{
		P2=0x7f;
		for(i=0;i<8;i++)
		{
			P2=ledwei[i];		 
			Hc595SendByte(ledduan[i]);	
			delay(100);		  
			Hc595SendByte(0x00); 
		}	
	}		
}

 效果展示:

猜你喜欢

转载自blog.csdn.net/fw1035/article/details/113755420