这里我们讲一讲什么是点阵LED,所谓点的点阵LED就是我们平时在大街上看到的电子滚动屏幕,用以显示店家需要展示的消息。
而深入来看,它是一个LED组成的点阵,如图所示
![点阵LED原理](https://img-blog.csdn.net/20170813102704299?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvaGhjaGVuY2hvbmc=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
和我们中学学习的坐标类似,如果要想形成文字,便将点阵LED中的某些点电亮,展现各种各样的图形。
我们所看见的电子屏幕的滚动,实际上是图片的动态刷新。一次只移动一个LED,形成我们所看到的滚动屏幕。
下面是宋雪松老师提供的代码,详情访问www.kingst.org
#include<reg52.h>
sbit ADDR0 = P1^0;
sbit ADDR1 = P1^1;
sbit ADDR2 = P1^2;
sbit ADDR3 = P1^3;
sbit ENLED = P1^4;
unsigned char code image[] = {
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x7D,0x01,0x01,0x7D,0xFF,0xFF,0xE3,0xC1,
0x81,0x03,0x03,0x81,0xC1,0xE3,0xFF,0xFF,0x81,0x01,0x3F,0x3F,0x3F,0x01,0x81,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
};
void main()
{
EA = 1;
ENLED = 0;
ADDR3 = 0;
TMOD = 0x01;
TH0 = 0xFC;
TL0 = 0x67;
ET0 = 1;
TR0 = 1;
while(1);
}
void InterruptTimer0() interrupt 1
{
static unsigned char i = 0;
static unsigned char index = 0;
static unsigned char tmr = 0;
TH0 = 0xFC;
TL0 = 0x67;
P0 = 0xFF;
switch(i)
{
case 0: ADDR2=0; ADDR1=0; ADDR0=0; i++; P0=image[index + 0];break;
case 1: ADDR2=0; ADDR1=0; ADDR0=1; i++; P0=image[index + 1];break;
case 2: ADDR2=0; ADDR1=1; ADDR0=0; i++; P0=image[index + 2];break;
case 3: ADDR2=0; ADDR1=1; ADDR0=1; i++; P0=image[index + 3];break;
case 4: ADDR2=1; ADDR1=0; ADDR0=0; i++; P0=image[index + 4];break;
case 5: ADDR2=1; ADDR1=0; ADDR0=1; i++; P0=image[index + 5];break;
case 6: ADDR2=1; ADDR1=1; ADDR0=0; i++; P0=image[index + 6];break;
case 7: ADDR2=1; ADDR1=1; ADDR0=1; i=0; P0=image[index + 7];break;
default: break;
}
tmr++;
if(tmr >= 250)
{
tmr = 0;
index++;
if(index >= 32)
{
index = 0;
}
}
}
#include<reg52.h>
sbit ADDR0 = P1^0;
sbit ADDR1 = P1^1;
sbit ADDR2 = P1^2;
sbit ADDR3 = P1^3;
sbit ENLED = P1^4;
unsigned char code image[30][8] = {
{0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},
{0xFF,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F},
{0xFF,0x3F,0x7F,0x7F,0x7F,0x7F,0x7F,0x3F},
{0xFF,0x1F,0x3F,0x3F,0x3F,0x3F,0x3F,0x1F},
{0xFF,0x0F,0x9F,0x9F,0x9F,0x9F,0x9F,0x0F},
{0xFF,0x87,0xCF,0xCF,0xCF,0xCF,0xCF,0x87},
{0xFF,0xC3,0xE7,0xE7,0xE7,0xE7,0xE7,0xC3},
{0xFF,0xE1,0x73,0x73,0x73,0xF3,0xF3,0xE1},
{0xFF,0x70,0x39,0x39,0x39,0x79,0xF9,0xF0},
{0xFF,0x38,0x1C,0x1C,0x1C,0x3C,0x7C,0xF8},
{0xFF,0x9C,0x0E,0x0E,0x0E,0x1E,0x3E,0x7C},
{0xFF,0xCE,0x07,0x07,0x07,0x0F,0x1F,0x3E},
{0xFF,0x67,0x03,0x03,0x03,0x07,0x0F,0x9F},
{0xFF,0x33,0x01,0x01,0x01,0x03,0x87,0xCF},
{0xFF,0x99,0x00,0x00,0x00,0x81,0xC3,0xE7},
{0xFF,0xCC,0x80,0x80,0x80,0xC0,0xE1,0xF3},
{0xFF,0xE6,0xC0,0xC0,0xC0,0xE0,0xF0,0xF9},
{0xFF,0x73,0x60,0x60,0x60,0x70,0x78,0xFC},
{0xFF,0x39,0x30,0x30,0x30,0x38,0x3C,0x7E},
{0xFF,0x9C,0x98,0x98,0x98,0x9C,0x1E,0x3F},
{0xFF,0xCE,0xCC,0xCC,0xCC,0xCE,0x0F,0x1F},
{0xFF,0x67,0x66,0x66,0x66,0x67,0x07,0x0F},
{0xFF,0x33,0x33,0x33,0x33,0x33,0x03,0x87},
{0xFF,0x99,0x99,0x99,0x99,0x99,0x81,0xC3},
{0xFF,0xCC,0xCC,0xCC,0xCC,0xCC,0xC0,0xE1},
{0xFF,0xE6,0xE6,0xE6,0xE6,0xE6,0xE0,0xF0},
{0xFF,0xF3,0xF3,0xF3,0xF3,0xF3,0xF0,0xF8},
{0xFF,0xF9,0xF9,0xF9,0xF9,0xF9,0xF8,0xFC},
{0xFF,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFE},
{0xFF,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFF}
};
void main()
{
EA = 1;
ENLED = 0;
ADDR3 = 0;
TMOD = 0x01;
TH0 = 0xFC;
TL0 = 0x67;
ET0 = 1;
TR0 = 1;
while(1);
}
void InterruptTimer0() interrupt 1
{
static unsigned char i = 0;
static unsigned char tmr = 0;
static unsigned char index = 0;
TH0 = 0xFC;
TL0 = 0x67;
P0 = 0xFF;
switch(i)
{
case 0: ADDR2=0; ADDR1=0; ADDR0=0; i++; P0=image[index][0]; break;
case 1: ADDR2=0; ADDR1=0; ADDR0=1; i++; P0=image[index][1]; break;
case 2: ADDR2=0; ADDR1=1; ADDR0=0; i++; P0=image[index][2]; break;
case 3: ADDR2=0; ADDR1=1; ADDR0=1; i++; P0=image[index][3]; break;
case 4: ADDR2=1; ADDR1=0; ADDR0=0; i++; P0=image[index][4]; break;
case 5: ADDR2=1; ADDR1=0; ADDR0=1; i++; P0=image[index][5]; break;
case 6: ADDR2=1; ADDR1=1; ADDR0=0; i++; P0=image[index][6]; break;
case 7: ADDR2=1; ADDR1=1; ADDR0=1; i=0; P0=image[index][7]; break;
default: break;
}
tmr++;
if(tmr >= 250)
{
tmr = 0;
index++;
if(index >= 30)
{
index = 0;
}
}
}