前面介绍过一种8x8点阵屏的显示驱动,但要显示一些信息就需要将多个模块级联起来。然而采用这种级联方案,在价格方面是不划算的。为此就选用一款红色的P4.75点阵屏来替代它,该点阵屏的规格为16*64点阵,其外观如图1所示。
图1 点阵屏外观
该点阵屏采用的接口方式为HUB08,各引脚的名称如图2所示。
图2 HUB08接口
该点阵屏与开发板的连接关系为:
A---PB9
B---PB8
C---PA6
D---PA5
R1 ---PA0
OE ---PA1
LAT ---PA2
CLK---PA3
使用相关引脚输出高低电平的语句定义为:
#define LR1_high GPIO_SetBits(GPIOA, GPIO_PIN_0)
#define LR1_low GPIO_ResetBits(GPIOA, GPIO_PIN_0)
#define CLK_high GPIO_SetBits(GPIOA, GPIO_PIN_3)
#define CLK_low GPIO_ResetBits(GPIOA, GPIO_PIN_3)
#define LA_high GPIO_SetBits(GPIOB, GPIO_PIN_9)
#define LA_low GPIO_ResetBits(GPIOB, GPIO_PIN_9)
#define LB_high GPIO_SetBits(GPIOB, GPIO_PIN_8)
#define LB_low GPIO_ResetBits(GPIOB, GPIO_PIN_8)
#define LC_high GPIO_SetBits(GPIOA, GPIO_PIN_6)
#define LC_low GPIO_ResetBits(GPIOA, GPIO_PIN_6)
#define LD_high GPIO_SetBits(GPIOA, GPIO_PIN_5)
#define LD_low GPIO_ResetBits(GPIOA, GPIO_PIN_5)
#define LEN_high GPIO_SetBits(GPIOA, GPIO_PIN_1)
#define LEN_low GPIO_ResetBits(GPIOA, GPIO_PIN_1)
#define LSTB_high GPIO_SetBits(GPIOA, GPIO_PIN_2)
#define LSTB_low GPIO_ResetBits(GPIOA, GPIO_PIN_2)
对相关引脚进行工作模式配置的函数为:
void gpio_Init(void)
{
GPIO_InitType GPIO_InitStructure;
RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB, ENABLE);
GPIO_InitStruct(&GPIO_InitStructure);
GPIO_InitStructure.Pin = GPIO_PIN_8|GPIO_PIN_9;
GPIO_InitStructure.GPIO_Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitPeripheral(GPIOB, &GPIO_InitStructure);
RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA, ENABLE);
GPIO_InitStructure.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3|GPIO_PIN_5|GPIO_PIN_6;
GPIO_InitPeripheral(GPIOA, &GPIO_InitStructure);
}
点阵屏发送数据的函数为:
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;
}
}
发送多列数据的函数为:
void DisCol(uint16_t dat,uint16_t len)
{
while(len--)
{
OutByte(dat);
}
}
输出行地址的函数为:
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 Display(void)
{
DisCol(0x5555,4);
LEN_high;
LSTB_high;
LSTB_low;
SeleRow(ScanRow);
LEN_low;
ScanRow++;
if(ScanRow>15) ScanRow=0;
}
实现图3所示效果的主程序为:
int main(void)
{
gpio__Init();
ScanRow=0;
while(1)
{
Display();
}
}
图3测试效果
为实现数字符号的显示,需使用字模提取软件来获得相应的字模,其存储结构为:
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 DisCol(uint16_t lenght) // 显示数字
{
uint16_t dat;
uint8_t m=8;
while(lenght--)
{
dat=(V[m*32+16+ScanRow]<<8)+V[m*32+ScanRow];
OutByte(dat);
m=m+1;
}
}
如果将它与RTC计时功能结合起来,就可实现一个具有电子时钟功能的点阵信息牌,其显示效果如图4所示。
图4 显示效果
演示视频:
电子计时牌