搞了好几天了STM8L152K4驱动段式LCD ,9个seg, 1/4DUTY ,1/3BIAS没法显示,测4个COM口有波形,程序如下请大侠多多帮忙
void LCD_Config(void)
{CLK_PeripheralClockConfig(CLK_Peripheral_LCD, ENABLE);
CLK_RTCClockConfig(CLK_RTCCLKSource_LSE, CLK_RTCCLKDiv_1);
LCD_Init(LCD_Prescaler_2, LCD_Divider_18, LCD_Duty_1_4,
LCD_Bias_1_3, LCD_VoltageSource_External);//LCD_VoltageSource_Internal);
//选择seg8-seg15作为LCD段码输入端(stm8l152K6 32pin 无SEG0-SEG7)
//特别注意:STM8L152K6只有4个COM,且固定在PA4\5\6和PD1端口
LCD_PortMaskConfig(LCD_PortMaskRegister_0, 0x00);
LCD_PortMaskConfig(LCD_PortMaskRegister_1, 0xFF);
LCD_PortMaskConfig(LCD_PortMaskRegister_2, 0x00);
LCD_PortMaskConfig(LCD_PortMaskRegister_3, 0x00);
LCD_PortMaskConfig(LCD_PortMaskRegister_4, 0x00);
LCD_PortMaskConfig(LCD_PortMaskRegister_5, 0x00);
LCD_ContrastConfig(LCD_Contrast_Level_7);
LCD_DeadTimeConfig(LCD_DeadTime_0);
LCD_PulseOnDurationConfig(LCD_PulseOnDuration_1);
LCD_Cmd(ENABLE);
}
/******************************************************************************
功能说明: 16进制转成ASCII
输入参数: i代转数值 str转成后的数值
输出参数:
调用说明:
******************************************************************************/
void Byte2ASCII(u8 i,u8 *str)
{str[0] = i / 100;//'0' + i / 100;
if(str[0] == '0')
{str[0] = 32;//' ';
}
str[1] = (i / 10) % 10;//'0' + (i / 10) % 10;
if(str[0] == ' ' && str[1] == '0')
{str[1] = 32;//' ';
}
str[2] = i % 10;//'0' + i % 10;
str[3] = 32;//' ';
}
void LCD_SetSegValue(void)
{u16 T,SEG[4];
u8 i,j,Code[6];
for(i=0;i<6;i++)
{Code[5-i]=Disp_Bit[Disp_Buf[i]&0x7F];
if(Disp_Buf[i]&0x80)Code[5-i]|=0x02;
}
for(i=0;i<4;i++)
{for(T=0,j=0;j<6;j++)
{T<<=2;
T|=(Code[j]&0x03);
Code[j]>>=2;
}
SEG[i]=T;
}
LCD_RAM0=(u8)(SEG[0]); //COM0->B[7:0]
LCD_RAM1=(u8)(SEG[0]>>8); //COM0->B[11:8]
LCD_RAM3=(u8)(SEG[1]<<4); //COM1->B[3:0]->H
LCD_RAM4=(u8)(SEG[1]>>4); //COM1->B[11:4]
LCD_RAM7=(u8)(SEG[2]); //COM2->B[7:0]
LCD_RAM8=(u8)(SEG[2]>>8); //COM2->B[11:8]
LCD_RAM10=(u8)(SEG[3]<<4); //COM3->B[3:0]->H
LCD_RAM11=(u8)(SEG[3]>>4); //CoM3->B[11:4]
}
//清显示
void LCD_Clear(u8 Index)
{u8 i;
if(Index==0xFF)
for(i=0;i<6;i++)
Disp_Buf[i]='U'-'A';
else
Disp_Buf[Index]='U'-'A';
LCD_SetSegValue();
}
//写显示缓冲区点
void LCD_ShowSpecial(u8 Saddr,u8 Char)
{if(Char>0)
Disp_Buf[Saddr]|=0x80;
else
Disp_Buf[Saddr]&=0x7F;
}
//显示字符
void LCD_ShowChar(u8 Saddr,u8 Char)
{Disp_Buf[Saddr]&=0x80;
Disp_Buf[Saddr]|=Char;
LCD_SetSegValue();
}
//显示字符串
void LCD_ShowString(u8 Saddr,u8 *Text)
{u8 T,P,*Str;
Str=(u8 *)Text;
while(*Str>0)
{T=*Str++;
P=Disp_Buf[Saddr];
Disp_Buf[Saddr++]=(P&0x80)|(T-'A');
}
LCD_SetSegValue();
}
//显示数字
void LCD_ShowNumber(u8 Saddr,u16 Number,u8 Length)
{u8 P;
Saddr+=Length-1;
while(Length--)
{P=Disp_Buf[Saddr];
Disp_Buf[Saddr]=(P&0x80)|(Number%10);
Saddr--;Number/=10;
}
LCD_SetSegValue();
}
void main(void)
{u16 i;
LCD_Config();
while(1)
{LCD_ShowNumber(1,123456,4);
for(i=0;i<0xFFFE;i++)
{};
}
}转载
|