74HC595实现8x8点阵从(0-9)一秒计时显示

简介

利用51单片机,实现数字0-9每隔一秒显示一个数字。

电路原理图

74HC595实现8x8点阵从(0-9)一秒计时显示_第1张图片
74HC595实现8x8点阵从(0-9)一秒计时显示_第2张图片
74HC595实现8x8点阵从(0-9)一秒计时显示_第3张图片

  • 这里LED点阵的封装图和原理图有点问题,大概意思就是行表示Hc595ByteSend,每一列接到的是P0口。

C语言程序

#include 
#include 

typedef unsigned char u8;
typedef unsigned int u16;

unsigned char code LedWei[] = {0x7F,0xBF,0xDF,0xEF,0xF7,0xFB,0xFD,0xFE};
unsigned char code LedDuan[10][8] = {
					{0x00,0x00,0x3e,0x41,0x41,0x41,0x3e,0x00},
					{0x00,0x00,0x02,0x42,0xFE,0x02,0x02,0x00},
					{0x00,0x00,0x63,0x85,0x89,0x91,0x61,0x00},
					{0x00,0x00,0x22,0x49,0x49,0x36,0x00,0x00},
					{0x00,0x00,0x0c,0x14,0x24,0x7f,0x04,0x00},
					{0x00,0x00,0x72,0x51,0x51,0x51,0x4e,0x00},
					{0x00,0x00,0x3e,0x49,0x49,0x49,0x26,0x00},
					{0x00,0x00,0x40,0x40,0x40,0x4f,0x70,0x00},
					{0x00,0x00,0x36,0x49,0x49,0x49,0x36,0x00},
					{0x00,0x00,0x32,0x49,0x49,0x49,0x3e,0x00},
					};

sbit SER = P3^4;
sbit RCLK = P3^5;
sbit SRCLK = P3^6;

void delay(u8 time)
{
	u8 i,j;
	for(i = 0;i < time;i++);
	for(j = 0;j < 121;j++);
}

void Hc595ByteSend(u8 dat)
{
	u8 a;
	RCLK = 0;
	SRCLK = 0;
	for(a = 0;a < 8;a++)
	{
		SER = dat >> 7;
		dat <<= 1;
		SRCLK = 1;
		_nop_();
		_nop_();
		SRCLK = 0;
	}
	RCLK = 1;
	_nop_();
	_nop_();
	RCLK = 0;
}

void main()
{	
	TMOD = 0x01;
	TH0 = 0xFC; 
	TL0 = 0x18;
	TR0 = 1;
	while(1)
	{
		while(TF0 == 0);
		TF0 = 0xFC;
		TL0 = 0x18;
		cnt++;
		if(cnt >= 1000)
		{
			cnt = 0;
			for(i = 0;i < 50;i++)
			{
				for(tab = 0;tab < 8;tab++)
				{
					Hc595ByteSend(0x00);
					P0 = LedWei[tab];
					Hc595ByteSend(LedDuan[j][tab]);
					delay(10);
				}
			}
			j++;
			if(j == 10)
			{
				j = 0;
			}
		}
	}	
}
  • 其实前面的delay的延时我用着是有一点懵的,不是很理解,而且这个定时我也不知道用对了没,但是我在开发板上,确实是可以成功运行的。
  • 还有很多不足的地方,还望加以补充和修改。
  • 新手上道,还望多多指教,谢谢啦。

手动笔芯

74HC595实现8x8点阵从(0-9)一秒计时显示_第4张图片

你可能感兴趣的:(单片机学习笔记)