点阵板在信息广告牌中使用的很多,通过点阵板的串接可以灵活地改变显示屏幕的大小。
这里使用的点阵板是一款16*64点阵的显示板,它与开发板的连接如下:
R1----P512
CLK----P511
A----P412
B----P410
C----P411
D----P413
EN----P415
STB----P611
各引脚输出高低电平的语句定义为:
#define LR1_high rt_pin_write(BSP_IO_PORT_05_PIN_12,PIN_HIGH)
#define LR1_low rt_pin_write(BSP_IO_PORT_05_PIN_12,PIN_LOW)
#define CLK_high rt_pin_write(BSP_IO_PORT_05_PIN_11,PIN_HIGH)
#define CLK_low rt_pin_write(BSP_IO_PORT_05_PIN_11,PIN_LOW)
#define LA_high rt_pin_write(BSP_IO_PORT_04_PIN_12,PIN_HIGH)
#define LA_low rt_pin_write(BSP_IO_PORT_04_PIN_12, PIN_LOW)
#define LB_high rt_pin_write(BSP_IO_PORT_04_PIN_10,PIN_HIGH)
#define LB_low rt_pin_write(BSP_IO_PORT_04_PIN_10,PIN_LOW)
#define LC_high rt_pin_write(BSP_IO_PORT_04_PIN_11,PIN_HIGH)
#define LC_low rt_pin_write(BSP_IO_PORT_04_PIN_11,PIN_LOW)
#define LD_high rt_pin_write(BSP_IO_PORT_04_PIN_13,PIN_HIGH)
#define LD_low rt_pin_write(BSP_IO_PORT_04_PIN_13,PIN_LOW)
#define EN_high rt_pin_write(BSP_IO_PORT_04_PIN_15,PIN_HIGH)
#define EN_low rt_pin_write(BSP_IO_PORT_04_PIN_15,PIN_LOW)
#define STB_high rt_pin_write(BSP_IO_PORT_06_PIN_11,PIN_HIGH)
#define STB_low rt_pin_write(BSP_IO_PORT_06_PIN_11,PIN_LOW)
用于串行发送16位数据的函数为:
void OutByte(uint16_t dat){ uint8_t i=0 ; for(i=0;i<16;i++) { CLK_low; if(dat&0x8000) { LR1_high; } else { LR1_low; } dat=dat<<1; CLK_high; } }
复制代码实现16行地址输出的函数为:
void SeleRow(uint8_t Nd){ uint8_t N; N=Nd; N=N%16; if(N&0x01) LA_high; else LA_low; if (N&0x02) LB_high; else LB_low; if (N&0x04) LC_high; else LC_low; if (N&0x08) LD_high; else LD_low; }
复制代码实现多列数据发送的函数为:
void DisCol(uint16_t dat,uint16_t len){ while(len--) { OutByte(dat); } }
复制代码绘制竖线的测试函数为:
void Display(void){ DisCol(0x5555,4); EN_high; STB_high; STB_low; SeleRow(ScanRow); EN_low; ScanRow++; if(ScanRow>15) ScanRow=0; }
复制代码实现测试效果的程序为:
void hal_entry(void){ rt_kprintf("\nHello RT-Thread!\n"); ScanRow=0; while (1) { Display(); } }
复制代码
图1 绘制竖线
在使用字模提取软件的情况下,可构建相应的显示字库,其结构如下:
rt_uint8_t V[]={
//远上寒山石径斜白云生处有人家
0x00,0x00,0xF8,0x23,0x00,0x10,0x00,0x10,0x00,0x00,0xFC,0x07,0x20,0xF1,0x20,0x11,
0x20,0x11,0x20,0x11,0x24,0x11,0x24,0x12,0x24,0x12,0x1C,0x14,0x00,0x28,0xFE,0x47,/* 0*/
0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,0xF8,0x03,0x00,0x02,
0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,0xFE,0xFF,0x00,0x00,/* 1*/
0x00,0x02,0x00,0x01,0xFE,0x7F,0x42,0x44,0xF4,0x9F,0x40,0x04,0xF8,0x3F,0x40,0x04,
0xFE,0xFF,0x20,0x08,0x10,0x13,0x88,0x20,0x46,0xC0,0x00,0x06,0x80,0x01,0x40,0x00,/* 2*/
0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,
0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0xF8,0x3F,0x08,0x00,0x00,0x00,/* 3*/
... ...
};
通过修改列数据发送函数,可实现中文的显示,其函数内容为:
void DisCol(uint16_t lenght){ uint16_t dat; uint8_t m=0; // 远上寒山石径斜白云深处有人家 while(lenght--) { dat=(V[m*32+ScanRow*2+1]<<8)+V[m*32+ScanRow*2]; OutByte(dat); m=m+1; } } 对应的显示函数为: voidDisplay(void) { DisCol(4); EN_high; STB_high; STB_low; SeleRow(ScanRow); EN_low; ScanRow++; if(ScanRow>15) ScanRow=0; }
复制代码经程序的下载测试,其显示效果如图2所示。

图2 显示中文效果
为显示数据值,需配置如下的字符库:
uint8_t S[]={
0x00,0x00,0x00,0x18,0x24,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x24,0x18,0x00,0x00,/*"0",0*/
0x00,0x00,0x00,0x08,0x0E,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x3E,0x00,0x00,/*"1",1*/
0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x20,0x20,0x10,0x08,0x04,0x42,0x7E,0x00,0x00,/*"2",2*/
0x00,0x00,0x00,0x3C,0x42,0x42,0x20,0x18,0x20,0x40,0x40,0x42,0x22,0x1C,0x00,0x00,/*"3",3*/
0x00,0x00,0x00,0x20,0x30,0x28,0x24,0x24,0x22,0x22,0x7E,0x20,0x20,0x78,0x00,0x00,/*"4",4*/
0x00,0x00,0x00,0x7E,0x02,0x02,0x02,0x1A,0x26,0x40,0x40,0x42,0x22,0x1C,0x00,0x00,/*"5",5*/
0x00,0x00,0x00,0x38,0x24,0x02,0x02,0x1A,0x26,0x42,0x42,0x42,0x24,0x18,0x00,0x00,/*"6",6*/
0x00,0x00,0x00,0x7E,0x22,0x22,0x10,0x10,0x08,0x08,0x08,0x08,0x08,0x08,0x00,0x00,/*"7",7*/
0x00,0x00,0x00,0x3C,0x42,0x42,0x42,0x24,0x18,0x24,0x42,0x42,0x42,0x3C,0x00,0x00,/*"8",8*/
0x00,0x00,0x00,0x18,0x24,0x42,0x42,0x42,0x64,0x58,0x40,0x40,0x24,0x1C,0x00,0x00,/*"9",9*/
0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00,/*":",10*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*"-",11*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
与该字符库相匹配的串行数据发送函数为:
void OutByte(uint16_t dat){ uint8_t i=0 ; for(i=0;i<16;i++) { CLK_low; if(dat&0x0001) { LR1_high; } else { LR1_low; } dat=dat>>1; CLK_high; } }
复制代码所对应的多列数据发送函数为:
void DisCol(uint16_t lenght){ uint16_t dat; uint8_t m=0; uint8_t sj[]={0x01,0x02,0x0A,0x03,0x00,0x0A,0x03,0x00}; while(lenght--) { dat=(S[sj[m+1]*16+ScanRow]<<8)+S[sj[m]*16+ScanRow]; OutByte(dat); m=m+2; } }
复制代码经程序的下载,其显示效果如图3所示。

图3 显示计时效果