新年即将来临,为了烘托热烈的气氛,使用点阵板是个不错的选择,这里所用的是一款P4.75型的红色点阵板,其显示分辨率为16*64像素点,见图1所示。
图1 点阵板外观
该点阵板与开发板间是通过接口J1和J2来连接,如图2所示,具体的连接关系为:
CLK---P0_25
LR1---P0_26
LEN---P0_24
LSTB---P0_27
LA---P0_10
LB---P0_28
LC---P0_31
LD---P1_2
图2 所用接口
为输出高低电平所定义的语句为:
#define CLK_high GPIO_PortSet(GPIO0, 1U << 25U) //CLK
#define CLK_low GPIO_PortClear(GPIO0, 1U << 25U)
#define LR1_high GPIO_PortSet(GPIO0, 1U << 26U) //DIN
#define LR1_low GPIO_PortClear(GPIO0, 1U << 26U)
#define LEN_high GPIO_PortSet(GPIO0, 1U << 24U) //RES
#define LEN_low GPIO_PortClear(GPIO0, 1U << 24U)
#define LSTB_high GPIO_PortSet(GPIO0, 1U << 27U) //DC
#define LSTB_low GPIO_PortClear(GPIO0, 1U << 27U)
#define LA_high GPIO_PortSet(GPIO0, 1U << 10U) //LA
#define LA_low GPIO_PortClear(GPIO0, 1U << 10U)
#define LB_high GPIO_PortSet(GPIO0, 1U << 28U) //LB
#define LB_low GPIO_PortClear(GPIO0, 1U << 28U)
#define LC_high GPIO_PortSet(GPIO0, 1U << 31U) //LC
#define LC_low GPIO_PortClear(GPIO0, 1U << 31U)
#define LD_high GPIO_PortSet(GPIO1, 1U << 2U) //LD
#define LD_low GPIO_PortClear(GPIO1, 1U << 2U)
使用字模提取软件所构建的数组为:
uint8_t tab[]={
//蛇(0) 年(1) 祥(2) 瑞(3)
0x20,0x10,0x10,0x10,0x10,0x10,0xFE,0x7D,0x02,0x55,0x04,0x56,0x80,0x54,0x88,0x54,
0x90,0x7C,0xA0,0x50,0xC0,0x10,0x82,0x14,0x82,0x1E,0x82,0xE2,0x7E,0x40,0x00,0x00,/*"蛇",0*/
0x00,0x10,0x00,0x10,0xFC,0x1F,0x80,0x20,0x80,0x20,0x80,0x40,0xF8,0x1F,0x80,0x10,
0x80,0x10,0x80,0x10,0xFE,0xFF,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,/*"年",1*/
0x04,0x21,0x84,0x10,0x88,0x10,0x00,0xF8,0xFE,0x0B,0x20,0x10,0x20,0x10,0xFC,0x39,
0x20,0x54,0x20,0x90,0xFE,0x13,0x20,0x10,0x20,0x10,0x20,0x10,0x20,0x10,0x20,0x10,/*"祥",2*/
0x20,0x00,0x22,0x02,0x22,0xFA,0x22,0x22,0xFE,0x23,0x00,0x20,0xFE,0x27,0x20,0xF8,
0x40,0x20,0xFE,0x23,0x52,0x22,0x52,0x3A,0x52,0xE2,0x52,0x42,0x52,0x02,0x06,0x02,/*"瑞",3*/
};
向点阵板发送字节数据的函数为:
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(int16_t lenght)
{
int16_t dat,n;
int8_t m=0;
while(lenght--)
{
dat=( tab[m*32+ScanRow*2+1]<<8)+ tab [m*32+ScanRow*2];
OutByte(dat);
m=m+1;
}
}
显示输出的函数为:
void Display(void)
{
DisCol(4);
LEN_high;
LSTB_high;
LSTB_low;
SeleRow(ScanRow);
LEN_low;
ScanRow++;
if(ScanRow>15) ScanRow=0;
}
实现显示效果的主程序为:
int main(void)
{
uint8_t i,n,f,m,j;
uint16_t k;
gpio_pin_config_t led_config = {
kGPIO_DigitalOutput,
0,
};
gpio_pin_config_t key_config = {
kGPIO_DigitalInput,
0,
};
CLOCK_SetClkDiv(kCLOCK_DivFlexcom4Clk, 1u);
CLOCK_AttachClk(BOARD_DEBUG_UART_CLK_ATTACH);
CLOCK_EnableClock(kCLOCK_Gpio0);
CLOCK_EnableClock(kCLOCK_Gpio1);
BOARD_InitPins();
BOARD_InitBootClocks();
BOARD_InitDebugConsole();
GPIO_PinInit(GPIO0, 25U, &led_config);
GPIO_PinInit(GPIO0, 26U, &led_config);
GPIO_PinInit(GPIO0, 24U, &led_config);
GPIO_PinInit(GPIO0, 27U, &led_config);
GPIO_PinInit(GPIO0, 10U, &led_config);
GPIO_PinInit(GPIO0, 28U, &led_config);
GPIO_PinInit(GPIO0, 31U, &led_config);
GPIO_PinInit(GPIO1, 2U, &led_config);
GPIO_PinInit(GPIO0, 6U, &key_config);
ScanRow=0;
while (1)
{
Display()
delay(2);
}
}
经程序的编译与下载,其显示效果如图3所示。
图3 汉字显示效果