现在在做12864液晶画图,拿的是论坛前辈的代码,在51上通过了,但在F149上画横线正确,画竖线不准确,画竖线的时候线条特别粗,每条竖线占屏幕的九分之一,求助!!主要代码如下
void LCD_write_com(unsigned char com)
{
RS_CLR;
RW_CLR;
EN_SET;
DataPort = com;
delay_ms(5);
EN_CLR;
delay_ms(5);
}
void LCD_write_data(unsigned char data)
{
RS_SET;
RW_CLR;
EN_SET;
DataPort = data;
delay_ms(5);
EN_CLR;
delay_ms(5);
}
unsigned char ReadByte(void)
{
unsigned char byReturnValue ;
DataPort=0xff ;
RS_SET;
RW_SET;
EN_CLR;
EN_SET;
byReturnValue=DataPort;
EN_CLR;
return byReturnValue ;
}
//增加画点子程序
void DrawPoint(unsigned char X,unsigned char Y,unsigned char Color)
{
unsigned char Row,Tier,Tier_bit ;
unsigned char ReadOldH,ReadOldL ;
LCD_write_com(0x34);
LCD_write_com(0x36);
Tier=X>>4 ;
Tier_bit=X&0x0f ;
if(Y<32)
{
Row=Y ;
}
else
{
Row=Y-32 ;
Tier+=8 ;
}
LCD_write_com(Row+0x80);
LCD_write_com(Tier+0x80);
ReadByte();
ReadOldH=ReadByte();
ReadOldL=ReadByte();
delay_us(250);
LCD_write_com(Row+0x80);
LCD_write_com(Tier+0x80);
delay_us(250);
if(Tier_bit<8)
{
switch(Color)
{
case 0 :
ReadOldH&=(~(0x01<<(7-Tier_bit)));
break ;
case 1 :
ReadOldH|=(0x01<<(7-Tier_bit));
break ;
case 2 :
ReadOldH^=(0x01<<(7-Tier_bit));
break ;
default :
break ;
}
LCD_write_data(ReadOldH);
LCD_write_data(ReadOldL);
}
else
{
switch(Color)
{
case 0 :
ReadOldL&=(~(0x01<<(15-Tier_bit)));
break ;
case 1 :
ReadOldL|=(0x01<<(15-Tier_bit));
break ;
case 2 :
ReadOldL^=(0x01<<(15-Tier_bit));
break ;
default :
break ;
}
LCD_write_data(ReadOldH);
LCD_write_data(ReadOldL);
}
LCD_write_com(0x30);
}
//画横线
void DrawLineX(unsigned char x0,unsigned char x1,unsigned char y,unsigned color)
{
unsigned char temp;
if(x0>x1)
{
temp=x1;
x1=x0;
x0=temp;
}
for(;x0<=x1;x0++)
DrawPoint(x0,y,color);
}
//画竖线
void DrawLineY(unsigned char x,unsigned char y0,unsigned char y1,unsigned color)
{
unsigned char temp;
if(y0>y1)
{
temp=y1;
y1=y0;
y0=temp;
}
for(;y0<=y1;y0++)
DrawPoint(x,y0,color);
}
此帖出自
小平头技术问答
一周热门 更多>