上传者: an519777215hui
|
上传时间: 2022-05-19 18:19:47
|
文件大小: 30KB
|
文件类型: DOC
16×16点阵LED显示汉字
Proteus中点阵LED最大为8×8点阵,不能用来显示汉字,而四片接在一起又因为引脚太近,无法接线。然而,是不是这样就意味着不能仿真“点阵汉字”了呢?笔者经过研究,将库里的8×8点阵LED修改后,将四片8×8点阵LED合并成一体,就成了16×16的点阵LED了。
该LED的特点是:共阴、逐行扫描、低在前高位在后,上面的引脚为数据口,下面的引脚为行选引脚,低电平有效。
电路由AT89C52、4片74HC138、4片8×8点阵组成。74HC138用于选择行,4片74HC138的有效顺序为:左上,右上,左下,右下。P0口作为数据口,4片74HC138列引脚都接到P0口。显示汉字的示意图如下图所示:
---------------------> ---------------------->
----------------------------------------------------------------
LSB 0 1 2 3 4 5 6 7 MSB | LSB 0 1 2 3 4 5 6 7 MSB
LSB 0 1 2 3 4 5 6 7 MSB | LSB 0 1 2 3 4 5 6 7 MSB
LSB 0 1 2 3 4 5 6 7 MSB | LSB 0 1 2 3 4 5 6 7 MSB
LSB 0 1 2 3 4 5 6 7 MSB | LSB 0 1 2 3 4 5 6 7 MSB
LSB 0 1 2 3 4 5 6 7 MSB | LSB 0 1 2 3 4 5 6 7 MSB
LSB 0 1 2 3 4 5 6 7 MSB | LSB 0 1 2 3 4 5 6 7 MSB
LSB 0 1 2 3 4 5 6 7 MSB | LSB 0 1 2 3 4 5 6 7 MSB
LSB 0 1 2 3 4 5 6 7 MSB | LSB 0 1 2 3 4 5 6 7 MSB
----------------------------------------------------------------
LSB 0 1 2 3 4 5 6 7 MSB | LSB 0 1 2 3 4 5 6 7 MSB
LSB 0 1 2 3 4 5 6 7 MSB | LSB 0 1 2 3 4 5 6 7 MSB
LSB 0 1 2 3 4 5 6 7 MSB | LSB 0 1 2 3 4 5 6 7 MSB
LSB 0 1 2 3 4 5 6 7 MSB | LSB 0 1 2 3 4 5 6 7 MSB
LSB 0 1 2 3 4 5 6 7 MSB | LSB 0 1 2 3 4 5 6 7 MSB
LSB 0 1 2 3 4 5 6 7 MSB | LSB 0 1 2 3 4 5 6 7 MSB
LSB 0 1 2 3 4 5 6 7 MSB | LSB 0 1 2 3 4 5 6 7 MSB
LSB 0 1 2 3 4 5 6 7 MSB | LSB 0 1 2 3 4 5 6 7 MSB
----------------------------------------------------------------
以下程序在16×16点阵LED上依次显示“梅川酷子”四个字,分别用正向显示和反向显示,间隔两秒钟变换一次,电路图和效果图下图所示。 AT89c52晶振频率为24MHz,用T0定时,改变变量flag值,从而让程序确定显示哪个汉字和显示方式(正向or反向)。
#i nclude
#define int8 unsigned char
#define int16 unsigned int
#define int32 unsigned long
int8 flag;
/*
flag变量
MSB 7 6 5 4 3 2 1 0 LSB
× × ×
Bit5=1,Bit4=0 时,负向显示
Bit5=0,Bit4=1 时,负向显示
Bit[2..0]74HC138的片选信号
*/
int8 n;
int8 code table[][32]={
{0x88,0x00,0x88,0x00,0x88,0x7F,0x48,0x00,0xDF,0x1F,0xA8,0x10,0x9C,0x12,0xAC,0x14,0xEA,0x7F,0x8A,0x12,0x89,0x14,0x88,0x10,0x88,0x7F,0x08,0x10,0x08,0x14,0x08,0x08},/*"梅",0*/
{0x08,0x20,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x04,0x21,0x04,0x20,0x02,0x00},/*"川",1*/
{0x00,0x08,0xFE,0x08,0x28,0x0A,0x28,0x7E,0xFE,0x0A,0xAA,0x09,0xAA,0xFF,0xEA,0x00,0x86,0x00,0x82,0x7E,0xFE,0x42,0x82,0x42,0x82,0x42,0xFE,0x7E,0x82,0x42,0x00,0x00},/*"酷",2*/
{0x00,0x00,0xF8,0x1F,0x00,0x08,0x00,0x04,0x00,0x02,0x00,0x01,0x00,0x01,0x00,0x41,0xFE,0xFF,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x40,0x01,0x80,0x00}/*"子",3*/
};
void delay(void);
void main(void){
int8 i;
int8 j;
int8 index;
flag=0x10;
n=0;
//定时器T0初始化
TMOD=0x01;
TH0=0xb1;
TL0=0xe0;
ET0=1;
EA=1;
TR0=1;
while(1)
{
index=flag&0x03;
if((flag&0x30)==0x10)
{ //正向显示
for(i=0;i<8;i++)
{ //显示上半屏
P0=table[index][2*i];
//左上
P2=i|0x08;
delay();
P0=table[index][2*i+1];
//右上
P2=i|0x10;
delay();
}
for(i=8;i<16;i++)
{ //显示下半屏
P0=table[index][2*i];
//左下
P2=(i-8)|0x20;
delay();
P0=table[index][2*i+1];
//右下
P2=(i-8)|0x40;
delay();
}
}
if((flag&0x30)==0x20)
{ //反向显示
for(i=0;i<8;i++)
{
P0=~(table[index][2*i]);
//左上
P2=i|0x08;
delay();
P0=~(table[index][2*i+1]);
//右上
P2=i|0x10;
delay();
}
for(i=8;i<16;i++)
{
P0=~(table[index][2*i]);
//左下
P2=(i-8)|0x20;
delay();
P0=~(table[index][2*i+1]);
//右下
P2=(i-8)|0x40;
delay();
}
}
}
}
void delay(void){
int16 i;
for(i=0;i<50;i++);
}
void timer0() interrupt 1 using 3
{
TF0=0;
TH0=0xb1;
TL0=0xe0;
//10ms中断一次
if(n<200)
{
n++;
}
else
{ //2秒改变一次
switch(flag)
{
case 0x10:
{
flag=0x11;//下次显示正向“川”
break;
}
case 0x11:
{
flag=0x12;//下次显示正向“酷”
break;
}
case 0x12:
{
flag=0x13;//下次显示正向“子”
break;
}
case 0x13:
{
flag=0x20;//下次显示负向“川”
break;
}
case 0x20:
{
flag=0x21;//下次显示负向“梅”
break;
}
case 0x21:
{
flag=0x22;//下次显示负向“酷”
break;
}
case 0x22:
{
flag=0x23;//下次显示负向“子”
break;
}
case 0x23:
{
flag=0x10;//下次显示正向“梅”
break;
}
}
n=0;
}
}