- void DZP_gpio(void)
- {
- __HAL_RCC_GPIOA_CLK_ENABLE();
- __HAL_RCC_GPIOB_CLK_ENABLE();
- __HAL_RCC_GPIOC_CLK_ENABLE();
- __HAL_RCC_GPIOD_CLK_ENABLE();
- __HAL_RCC_GPIOF_CLK_ENABLE();
- __HAL_RCC_GPIOG_CLK_ENABLE();
- GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
- GPIO_InitStruct.Pin = GPIO_PIN_5| GPIO_PIN_15;
- HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
- GPIO_InitStruct.Pin = GPIO_PIN_3 | GPIO_PIN_5 |GPIO_PIN_12| GPIO_PIN_13;
- HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
- GPIO_InitStruct.Pin = GPIO_PIN_7;
- HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
- GPIO_InitStruct.Pin = GPIO_PIN_14| GPIO_PIN_15;
- HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
- GPIO_InitStruct.Pin = GPIO_PIN_3;
- HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);
- GPIO_InitStruct.Pin = GPIO_PIN_9| GPIO_PIN_10;
- HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);
- }
串行输出字节数据的函数为:
- void OutByte(u8 dat, u8 datp)
- {
- u8 i=0 ;
- for(i=0;i<8;i++)
- {
- LSCL_Low();
- if(dat&0x80)
- {
- LR1_High();
- LB1_High();
- LG1_High();
- }
- else
- {
- LR1_Low();
- LB1_Low();
- LG1_Low();
- }
- if(datp&0x80)
- {
- LR2_High();
- LB2_High();
- LG2_High();
- }
- else
- {
- LR2_Low();
- LB2_Low();
- LG2_Low();
- }
- dat=dat<<1;
- datp=datp<<1;
- LSCL_High();
- }
- }
实现地址输出的函数为:
- void SeleRow(u8 Nd)
- {
- u8 N=Nd;
- if(Nd==0) N=7;
- if(Nd==1) N=0;
- if(Nd==2) N=1;
- if(Nd==3) N=2;
- if(Nd==4) N=3;
- if(Nd==5) N=4;
- if(Nd==6) N=5;
- if(Nd==7) N=6;
- N=N%8;
- if((N&0x01)>0)
- {
- LA_High();
- }
- else
- {
- LA_Low();
- }
- if((N&0x02)>0)
- {
- LB_High();
- }
- else
- {
- LB_Low();
- }
- if((N&0x04)>0)
- {
- LC_High();
- }
- else
- {
- LC_Low();
- }
- }
用于显示的字模被放置在数组中,其结构如下:
- u8 t[]={
- 0x20,0x00,0x23,0xF8,0x22,0x08,0x22,0x08,0xFB,0x28,0x22,0xA8,0x22,0xA8,0x72,0x48,
- 0x6A,0x48,0xA2,0xA8,0xA2,0xA8,0x23,0x2A,0x24,0x0A,0x24,0x0A,0x28,0x06,0x30,0x02,
- 0x00,0x20,0x00,0x20,0x78,0x20,0x48,0x20,0x48,0x20,0x48,0x20,0x4B,0xFE,0x48,0x20,
- 0x48,0x20,0x48,0x20,0x78,0x20,0x48,0x20,0x00,0x20,0x00,0x20,0x00,0x20,0x00,0x20,
- ...
- };
读取字模实现显示的函数为:
- void Display(void)
- {
- u16 d;
- LEN_High();
- LSTB_High();
- LSTB_Low();
- d=ScanRow*2;
- OutByte(t[d],t[d+16]);
- OutByte(t[d+1],t[d+17]);
- OutByte(t[32+d],t[d+48]);
- OutByte(t[32+d+1],t[d+49]);
- SeleRow(ScanRow);
- LEN_Low();
- ScanRow++;
- if(ScanRow>7) ScanRow=0;
- }
实现显示效果的主程序为:
- int main(void)
- {
- HAL_Init();
- SystemClock_Config();
- MX_GPIO_Init();
- MX_ICACHE_Init();
- LED1_GPIO_CLK_ENABLE();
- LED2_GPIO_CLK_ENABLE();
- GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
- GPIO_InitStruct.Pin = LED1_PIN;
- HAL_GPIO_Init(LED1_GPIO_PORT, &GPIO_InitStruct);
- GPIO_InitStruct.Pin = LED2_PIN;
- HAL_GPIO_Init(LED2_GPIO_PORT, &GPIO_InitStruct);
- DZP_gpio();
- DZP_gpio();
- ScanRow=0;
- while (1)
- {
- Display();
- }
- }
稍感不足的是,使用NUCLEO- H563ZI开发板的驱动效果似乎不如其它开发板的效果好,亮度偏弱,且有一些杂点的出现,见图5和图6所示。
图5 显示效果
图6 对比效果