怎样用51单片机和led8*8矩阵进行字符汉字显示?
8*8也就能显示字符,显示汉字比较吃力。
#include<reg51.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
uchar code Table_of_Digits[]=
{
0x00,0x3e,0x41,0x41,0x41,0x3e,0x00,0x00, //0
0x00,0x00,0x00,0x21,0x7f,0x01,0x00,0x00, //1
0x00,0x27,0x45,0x45,0x45,0x39,0x00,0x00, //2
0x00,0x22,0x49,0x49,0x49,0x36,0x00,0x00, //3
0x00,0x0c,0x14,0x24,0x7f,0x04,0x00,0x00, //4
0x00,0x72,0x51,0x51,0x51,0x4e,0x00,0x00, //5
0x00,0x3e,0x49,0x49,0x49,0x26,0x00,0x00, //6
0x00,0x40,0x40,0x40,0x4f,0x70,0x00,0x00, //7
0x00,0x36,0x49,0x49,0x49,0x36,0x00,0x00, //8
0x00,0x32,0x49,0x49,0x49,0x3e,0x00,0x00, //9
0xff,0x81,0x81,0x81,0x81,0x81,0x81,0xff
};
uchar code xdat[8]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};
uchar code ydat[8]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
uchar i=0,j=0,t=0,Num_Index,key,xi,yi;
sbit we1=P1^1;
sbit we2=P1^3;
//主程序
void main()
{
//P1=0x80;
Num_Index=0; //从0 开始显示
TMOD=0x01; //T0 方式0
TH0=(65536-2000)/256; //2ms 定时
TL0=(65536-2000)%256;
IE=0x82;
key=0;
xi=0;
yi=0;
EX0=1;
IT0=1;
TR0=1; //启动T0
while(1);
}
//T0 中断函数
void ext_int0() interrupt 0
{
key++;
key&=0x03;
}
void LED_Screen_Display() interrupt 1
{
TH0=(65536-2000)/256; //2ms 定时
TL0=(65536-2000)%256;
switch(key)
{
case 0:
P0=0xff;
we1=1;
P0=~Table_of_Digits[Num_Index*8+i];
we1=0;
P0=0xff; //输出位码和段码
we2=1;
P0=xdat[i];
we2=0;
if(++i==8) i=0; //每屏一个数字由8 个字节构成
if(++t==250) //每个数字刷新显示一段时间
{
t=0;
if(++Num_Index==10) Num_Index=0; //显示下一个数字
}
break;
case 1:
we1=1;
P0=~xdat[xi];
we1=0;
we2=1;
P0=ydat[yi];
we2=0;
if(++t==250) //每个数字刷新显示一段时间
{
t=0;
yi++;
if(yi>7){yi=0;xi++;}
if(xi>7)xi=0;
}
break;
case 2:
we1=1;
P0=0x00;
we1=0;
P0=0xff; //输出位码和段码
we2=1;
P0=xdat[i];
we2=0;
if(++t==250) //每个数字刷新显示一段时间
{
if(++i==8) i=0; //每屏一个数字由8 个字节构成
t=0;
}
break;
default:
key=0;
i=0;
j=0;
t=0;
xi=0;
yi=0;
Num_Index=0;
we1=1;
P0=0xff;
we1=0;
we2=1;
P1=0x80;
we2=0;
break;
}
}
其次,你没提用什么驱动电路,按理总得用595之类的驱动一下吧,直接用IO去扫每个BIT是不是太累了。
谢谢
谢谢哦,真感谢!