51单片机学习10_8*8点阵(显示“♥”)

原创文章,转载请注明: 转载自勤奋的小青蛙
本文链接地址: 51单片机学习10_8*8点阵(显示“♥”)

昨天晚上弄懂了8×8点阵的原理,今天晚上我自己拿点阵模子,设计了个“♥”形的显示效果,于是开始写代码调试,最后终于弄出来了,效果图如下:

点阵显示

点阵显示

8×8点阵显示原理,类似于点阵矩形键盘的原理,只要由DIOLA锁存端控制了高电平,然后DULA锁存端控制了低电平,那么电流由高到低就形成了回路,于是发光二极管就会点亮。
我的开发板的原理图如下:

88点阵原理图1

88点阵原理图1

锁存器原理图

锁存器原理图

51IO控制口

51IO控制口

源代码如下:

#include <reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit dula = P2 ^ 6;
sbit diola = P2 ^ 5;
sbit wela = P2 ^ 7;

void delay(uint time)
{
	uint x, y;
	for (x = time; x > 0; x--)
		for (y = 110; y > 0; y--);
}

void close_shuma()
{
	wela = 1;
	delay(10);
	P0 = 0xff;
	delay(10);
	wela = 0;
	delay(10);
}

void init_led()
{
	dula = 1;
	diola = 1;
	P0 = 0x00;
	dula = 0;
	diola = 0;
	delay(1);
}

void display()
{
	//1
	init_led();

	dula = 1;
	P0 = 0xff;
	dula = 0;

	diola = 1;
	P0 = 0x01;
	diola = 0;
	delay(3);

	//2
	init_led();

	dula = 1;
	P0 = 0x99;
	dula = 0;

	diola = 1;
	P0 = 0x02;
	diola = 0;
	delay(3);

	//3
	init_led();

	dula = 1;
	P0 = 0x00;
	dula = 0;

	diola = 1;
	P0 = 0x04;
	diola = 0;
	delay(3);

	//4
	init_led();

	dula = 1;
	P0 = 0x00;
	dula = 0;

	diola = 1;
	P0 = 0x08;
	diola = 0;
	delay(3);

	//5
	init_led();

	dula = 1;
	P0 = 0x81;
	dula = 0;

	diola = 1;
	P0 = 0x10;
	diola = 0;
	delay(3);

	//6
	init_led();

	dula = 1;
	P0 = 0x81;
	dula = 0;

	diola = 1;
	P0 = 0x20;
	diola = 0;
	delay(3);

	//7
	init_led();

	dula = 1;
	P0 = 0xc3;
	dula = 0;

	diola = 1;
	P0 = 0x40;
	diola = 0;
	delay(3);

	//8
	init_led();

	dula = 1;
	P0 = 0xe7;
	dula = 0;

	diola = 1;
	P0 = 0x80;
	diola = 0;
	delay(3);

}

void main()
{
	close_shuma();
	while (1) {
		display();
	}
}
原创文章,转载请注明: 转载自勤奋的小青蛙
本文链接地址: 51单片机学习10_8*8点阵(显示“♥”)

文章的脚注信息由WordPress的wp-posturl插件自动生成



|2|left
打赏

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: