// Arduino 328 用16行*32列 LED矩阵显示屏基础测试程序,主频是32MHz,在主菜单Project->工程设置中修改
// 项目格式 Proteus V8.9 SP2版本,测试如图所示。
// 源代码如下。
int A = 8;
int B = 9;
int C = 10;
int D = 11;
int DE = 12;
int LATCH = 2; //锁存信号 Latch
int SCLK = 3; //时钟信号 Shift Clock
int R0 = 4; //数据输入 ,Data Shift in
char datain=0x0F;
int refreshtime=500;
int i=0,LineNum=0; // 临时循环变量
#define NumOf74HC595 3// 从0开始查数,实际上是4个,0也算一个。
unsigned char zimo[][32]={
{0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x3F,0xF8,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x3F,0xF8,0x21,0x08,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00},/*"中",0*/
/* (16 X 16 , 宋体 )*/
{0x00,0x00,0x7F,0xFC,0x40,0x04,0x40,0x04,0x5F,0xF4,0x41,0x04,0x41,0x04,0x4F,0xE4,0x41,0x04,0x41,0x44,0x41,0x24,0x5F,0xF4,0x40,0x04,0x40,0x04,0x7F,0xFC,0x40,0x04},/*"国",1*/
/* (16 X 16 , 宋体 )*/
{0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x7C,0xFE,0x44,0x12,0x44,0x12,0x44,0x12,0x44,0x12,0x44,0x12,0x44,0x12,0x44,0x12,0x44,0x22,0x44,0x22,0x7C,0x4A,0x44,0x84,0x00},/*"加",2*/
/* (16 X 16 , 宋体 )*/
{0x00,0x40,0x20,0x40,0x10,0x40,0x10,0x40,0x87,0xFC,0x44,0x44,0x44,0x44,0x14,0x44,0x14,0x44,0x27,0xFC,0xE4,0x44,0x24,0x44,0x24,0x44,0x24,0x44,0x27,0xFC,0x04,0x04},/*"油",3*/
/* (16 X 16 , 宋体 )*/
};
unsigned char DisplayBuffer[16][4]={}; // 16行*32(4*8bit)列的显示缓冲区,与LED点阵屏一一对应,要显示什么内容,先把内容复制到这个缓冲区中即可。
void setup() {
pinMode(LATCH, OUTPUT);
pinMode(SCLK, OUTPUT);
pinMode(R0, OUTPUT);
pinMode(A, OUTPUT);
pinMode(B, OUTPUT);
pinMode(C, OUTPUT);
pinMode(D, OUTPUT);
pinMode(DE, OUTPUT);
DDRB=0xFF; // 8 pin output
digitalWrite(DE, HIGH); // 关闭138的输出,显示屏不会亮
// 填充显示缓冲区
for(LineNum=0;LineNum<16;LineNum++)
{
DisplayBuffer[LineNum][NumOf74HC595]=zimo[2][LineNum*2];
DisplayBuffer[LineNum][NumOf74HC595-1]=zimo[2][LineNum*2+1];
DisplayBuffer[LineNum][NumOf74HC595-2]=zimo[3][LineNum*2];
DisplayBuffer[LineNum][NumOf74HC595-3]=zimo[3][LineNum*2+1];
}
}
void loop() {
for(LineNum=0;LineNum<16;LineNum++)
{
digitalWrite(DE, HIGH); // 关闭138的输出,防止显示串行
PORTB=0xF0 | LineNum; // 选择第LineNum行
for (i = 0; i <= NumOf74HC595; i++)
{ // 本电路图中有4个595芯片,所以这里是4
// 串行输出数据
digitalWrite(LATCH, LOW);
shiftOut(R0, SCLK, MSBFIRST, DisplayBuffer[LineNum][NumOf74HC595-i]);
digitalWrite(LATCH, HIGH);
}
digitalWrite(DE, LOW); // 打开138的输出,点亮相应的行
delayMicroseconds(refreshtime); // 每行数据的显示停留时间
}
}
|