单片机点阵显示数据

我们老师要求我们写一段话,这一段话挺长在 8*8 的点阵上显示“武汉是一座英雄的城市,武汉人民是英雄的人民”对应的拼音 字母,纵向移动,每 200ms 改变一张图片,然后不停地动态刷新(每 1ms 刷新一次)。
如果每次都要用字模的话要好多字模。

我开始时的思路是将点阵视为一个二维数组,通过改变索引来改变点阵的显示。这样只需要录入26个字母的点阵信息就能显示有字母组成的数据。主要是如何改变索引才能正常显示,首先在行是0,1,2,3,4,5,6,7->1,2,3,4,5,6,7,0->2,3,4,5,6,7,0,1……->7,0,1,2,3,4,5,6这是一个有规律的循环,循环左移,向左移出的元素又放回右端。因此可以建立一个函数来完成这一过程。还有字母索引相对更加复杂,每一轮显示不能单纯的改变index字母索引,因为存在两个字母同时存在于点阵的情况,因此需要渐渐改变index,为此有建立了一个数组f[7],专门来改变index的下标。开始时图片完全不对,因为索引值不对,经过修改后图片才正常。之后还出现了一个问题就是下一轮循环显示不正确,修改了索引需要减去的值才对。还有一个完善的问题,两次显示之间没有空格间隔,后来加上了空格,这一字符。

#include <reg52.h>

sbit ADDR0 = P1^0;
sbit ADDR1 = P1^1;
sbit ADDR2 = P1^2;
sbit ADDR3 = P1^3;
sbit ENLED = P1^4;

static unsigned char m=0;

unsigned char code image[27][8]=
{{0xff,0xe7,0xe7,0xdb,0x81,0xbd,0x7e,0xff},
{0xff,0xc1,0xbd,0xc1,0xbd,0x7d,0x81,0xff},
{0xff,0xc3,0xbd,0xfd,0xfd,0x79,0x83,0xff},
{0xff,0xc1,0x9d,0xbd,0xbd,0x9d,0xc1,0xff}, 
{0xff,0x81,0xfd,0x81,0xfd,0xfd,0x81,0xff},
{0xff,0x81,0xfd,0x81,0xfd,0xfd,0xfd,0xff},
{0xff,0xc3,0xb9,0xfd,0x8d,0xb9,0x83,0xff},
{0xff,0xbd,0xbd,0x81,0xbd,0xbd,0xbd,0xff},
{0xff,0xf7,0xf7,0xf7,0xf7,0xf7,0xf7,0xff},
{0xff,0xbf,0xbf,0xbf,0xbf,0xbd,0xc3,0xff},
{0xff,0x9d,0xed,0xf5,0xe9,0xdd,0xbd,0xff},
{0xff,0xfd,0xfd,0xfd,0xfd,0xfd,0x81,0xff},
{0xff,0x99,0x99,0x99,0xa5,0xa5,0xa5,0xff},
{0xff,0xb9,0xb9,0xb5,0xad,0x9d,0x9d,0xff},
{0xff,0xc3,0x99,0xbd,0xbd,0x99,0xc3,0xff},
{0xff,0xc1,0xbd,0xbd,0xc1,0xfd,0xfd,0xff},
{0xff,0xc3,0x99,0xbd,0xbd,0xa9,0xc3,0xbf},
{0xff,0xc1,0xbd,0x81,0xbd,0xbd,0xbd,0xff},
{0xff,0xc3,0xbd,0xc3,0x3f,0x7d,0x83,0xff},
{0xff,0x80,0xf7,0xf7,0xf7,0xf7,0xf7,0xff},
{0xff,0xbd,0xbd,0xbd,0xbd,0xbd,0xc3,0xff},
{0xff,0x7e,0xbd,0xdd,0xdb,0xe3,0xf7,0xff},
{0xff,0xff,0xff,0x66,0xa6,0x99,0x99,0xff},
{0xff,0xdd,0xeb,0xf7,0xe3,0xd9,0xbc,0xff},
{0xff,0xbc,0xd9,0xe3,0xf7,0xf7,0xf7,0xff},
{0xff,0x80,0xdf,0xe7,0xfb,0xfd,0x80,0xff}};

unsigned char code index[64]={22,20,7,0,13,18,7,8,24,8,25,20,14,24,8,13,6,23,8,14,13,6,3,4,2,7,4,13,6,18,7,8,22,20,7,0,13,17,4,13,12,8,13,18,7,8,24,8,13,6,23,8,14,13,6,3,4,17,4,13,12,8,13};
unsigned char flag[8]={0,1,2,3,4,5,6,7};
unsigned char f[8]={0,0,0,0,0,0,0,0};

void main()
{
	EA = 1;
	ENLED = 0;
	ADDR3 = 0;
	TMOD = 0x01;
	TH0 = 0xFC;
	TL0 = 0x67;
	ET0 =1;
	TR0 = 1;
	while(1);
}

void swap(unsigned char *a)
{
	unsigned char x=a[0];
	for (m=0;m<7;m++)
		a[m]=a[m+1];
	a[7]=x;
}

unsigned char con(int count,unsigned char *f)
{
	if (count>7)
	{
		count=count-8;
	}
	if(f[count]>=62)
		f[count]=f[count]-62;
	else
		f[count]=f[count]+1;
	count++;
	return count;
}

void InterruptTimer0() interrupt 1
{
	static unsigned char i = 0;
	static unsigned char tmr = 0;
	static unsigned char count = 0;

	TH0 = 0xFC;
	TL0 = 0x67;
	P0 = 0xFF;

	switch(i)
	{
		case 0:ADDR2=0;ADDR1=0;ADDR0=0;i++;P0=image[index[f[7]]][flag[0]];break;
		case 1:ADDR2=0;ADDR1=0;ADDR0=1;i++;P0=image[index[f[6]]][flag[1]];break;
		case 2:ADDR2=0;ADDR1=1;ADDR0=0;i++;P0=image[index[f[5]]][flag[2]];break;
		case 3:ADDR2=0;ADDR1=1;ADDR0=1;i++;P0=image[index[f[4]]][flag[3]];break;
		case 4:ADDR2=1;ADDR1=0;ADDR0=0;i++;P0=image[index[f[3]]][flag[4]];break;
		case 5:ADDR2=1;ADDR1=0;ADDR0=1;i++;P0=image[index[f[2]]][flag[5]];break;
		case 6:ADDR2=1;ADDR1=1;ADDR0=0;i++;P0=image[index[f[1]]][flag[6]];break;
		case 7:ADDR2=1;ADDR1=1;ADDR0=1;i=0;P0=image[index[f[0]]][flag[7]];break;
		default:break;								
	}
	tmr++;
	if(tmr >= 200)
	{
		tmr = 0;
		count=con(count,f);
		swap(flag);	
	}
}

这个效果挺好玩的,这个就具有实用性了,可以任意改变文字,只需要改变索引即可。当然这只是针对字母而言,我用的是8*8点阵只能显示字母。如果是汉字的话要将26个字母替换为对应汉字的字模。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值