看着sdk里的驱动 挺难受的:
比如:
LCD_WriteRam0_7Int32(0,0x0b060600);
LCD_WriteRam0_7Int32(1,0x0d030f02);
以上两行代码要显示什么呢?入口参数第二个参数是啥?看不懂,可读性极差!
折腾一下,随手写了几个函数,分分钟,贴上来和大家共享。
/*
***显示译码 “0,1,2,3,4,5,6,7,8,9,关闭”************
**************************************************
*/
uint16_t code[11]={0xf05,0x600,0xb06,0xf02,0x603,0xd03,0xd07,0x700,0xf07,0xf03,0x000}; // 0,1,2,3,4,5,6,7,8,9,关闭
static void Lcd_SetPortAnalog(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
}
void LCD_config(void)
{
stc_lcd_config_t stcLcdCfg;
DDL_ZERO_STRUCT(stcLcdCfg);
Sysctrl_SetPeripheralGate(SysctrlPeripheralLcd,TRUE);
Sysctrl_SetPeripheralGate(SysctrlPeripheralGpio,TRUE);
Lcd_SetPortAnalog();//和LCD相关端口都要配置为模拟端口
LCD_SetSegCom(0,0xffffff00);//设置seg0-7
LCD_SetSegCom(1,0x10ff);//设置com0-3
stcLcdCfg.enDispMode = LcdMode0;
stcLcdCfg.enBias = LcdBias3;
stcLcdCfg.enBiasSrc = LcdInRes_Low;//内部电阻方式
stcLcdCfg.enClk = LcdRCL;
stcLcdCfg.enDuty = LcdDuty4;
stcLcdCfg.enCpClk = LcdClk2k;
stcLcdCfg.enScanClk = LcdClk128hz;
LCD_Init(&stcLcdCfg);
LCD_EnFunc(LcdEn,TRUE);
LCD_ClearDisp();
return;
}
/*显示数字,成两组,左边和右边
index : 0 左对齐,1 右对齐
mun : 数字范围在 0 ~99
*/
void LCD_disp_num(uint8_t index, uint8_t mun)
{
int a = 0;
int b = 0;
a=mun/10;
b=mun%10;
LCD_WriteRam0_7Int32(index,(code[b]<<16) + code[a]);
}
/*显示小数点,冒号*/
void LCD_disp_dot(uint8_t index)
{
if(index == 1)
{
LCD_WriteRam(0,3,1); /*first dot */
}
else if(index == 2)
{
LCD_WriteRam(1,3,1); /*second dot */
}
else if(index == 3)
{
LCD_WriteRam(1,19,1); /*third dot */
}
else
{
LCD_WriteRam(0,19,1); /*maohao*/
}
return;
}
下载运行,结果OK。
|
|
您好,这两天在看LCD部分,想问一下,显示点那一部分是怎么处理的,就是传参的几个数字怎么来的