HC32L196PCTA开发板配有笔段式的液晶屏,并有相应的显示例程,其显示效果如图1所示。 图1 显示效果
该液晶屏的驱动方式:1/4 Duty、1/3 Bias、工作电压:3V3,其几何尺寸及引脚功能如图2所示。 图2 几何尺寸及引脚功能
由于该例程只是一个测试例程,因此在实际使用过程中,该相应对它进一步完善,以实现数据显示的函数化。
为此,相应对例程加以分析和修改。其主程序为: int32_t main(void)
{
Sysctrl_ClkSourceEnable(SysctrlClkRCL,TRUE); ///< 使能RCL时钟
Sysctrl_SetRCLTrim(SysctrlRclFreq32768); ///< 配置内部低速时钟频率为32.768kHz
Sysctrl_SetPeripheralGate(SysctrlPeripheralLcd,TRUE); ///< 开启LCD时钟
Sysctrl_SetPeripheralGate(SysctrlPeripheralGpio,TRUE); ///< 开启GPIO时钟
App_PortCfg(); ///< LCD端口配置
App_LcdCfg(); ///< LCD模块配置
Lcd_ClearDisp(); ///< 清屏
Lcd_WriteRam(0,0x0f0f0f0f); ///< 赋值寄存器LCDRAM0
Lcd_WriteRam(1,0x0f0f0f0f); ///< 赋值寄存器LCDRAM1
while(1)
{
;
}
}
其引脚工作模式配置函数为: void App_PortCfg(void)
{
Gpio_SetAnalogMode(GpioPortA, GpioPin9); //COM0
Gpio_SetAnalogMode(GpioPortA, GpioPin10); //COM1
Gpio_SetAnalogMode(GpioPortA, GpioPin11); //COM2
Gpio_SetAnalogMode(GpioPortA, GpioPin12); //COM3
Gpio_SetAnalogMode(GpioPortA, GpioPin8); //SEG0
Gpio_SetAnalogMode(GpioPortC, GpioPin9); //SEG1
Gpio_SetAnalogMode(GpioPortC, GpioPin8); //SEG2
Gpio_SetAnalogMode(GpioPortC, GpioPin7); //SEG3
Gpio_SetAnalogMode(GpioPortC, GpioPin6); //SEG4
Gpio_SetAnalogMode(GpioPortB, GpioPin15); //SEG5
Gpio_SetAnalogMode(GpioPortB, GpioPin14); //SEG6
Gpio_SetAnalogMode(GpioPortB, GpioPin13); //SEG7
Gpio_SetAnalogMode(GpioPortB, GpioPin3); //VLCDH
Gpio_SetAnalogMode(GpioPortB, GpioPin4); //VLCD3
Gpio_SetAnalogMode(GpioPortB, GpioPin5); //VLCD2
Gpio_SetAnalogMode(GpioPortB, GpioPin6); //VLCD1
}
LCD 屏相指定寄存器写入数据的函数为: en_result_t Lcd_WriteRam(uint8_t u8Row,uint32_t u32Data)
{
en_result_t enRet = Error;
volatile uint32_t *ram = NULL;
ram = (volatile uint32_t*)&M0P_LCD->RAM0;
if (u8Row > 15)
{
enRet = ErrorInvalidParameter;
return enRet;
}
ram += u8Row;
*ram = u32Data;
enRet = Ok;
return enRet;
}
为实现数字的显示,所定义显示码为: int16_td[10]={0x0f05,0x0600,0x0b06,0x0f02,0x0603,0x0d03,0x0d07,0x0700,0x0f07,0x0f03};
实现数字显示的测试主程序为: int32_t main(void)
{
int8_t i=0;
Sysctrl_ClkSourceEnable(SysctrlClkRCL,TRUE); ///< 使能RCL时钟
Sysctrl_SetRCLTrim(SysctrlRclFreq32768); ///< 配置内部低速时钟频率为32.768kHz
Sysctrl_SetPeripheralGate(SysctrlPeripheralLcd,TRUE); ///< 开启LCD时钟
Sysctrl_SetPeripheralGate(SysctrlPeripheralGpio,TRUE); ///< 开启GPIO时钟
App_PortCfg(); ///< LCD端口配置
App_LcdCfg(); ///< LCD模块配置
Lcd_ClearDisp(); ///< 清屏
Lcd_WriteRam(0,0x00000000);
Lcd_WriteRam(1,0x00000000);
while(1)
{
Lcd_WriteRam(0,(d[i]<<16)+d[i]);
Lcd_WriteRam(1,(d[i]<<16)+d[i]);
i=(i+1)%10;
delay1ms(1000);
}
}
经程序的编译与下载,其显示效果如图3所示。 图3 测试效果
|