现在手里的液晶基本都没了,12864、12232什么的都不见影了,还有一块诺基亚手机3510上拆下来的液晶,以前点过,现在用Mega8再点点。由于Mega8的资源有限,不能一次做多个测试,只能一个个的做了。要3510资料的可以上BAIDU搜搜,有很多。
测试效果:
//3510.c
#include <iom8v.h>
#include "mytype.h"
#include "math.h"
#include "lcd3510.h"
//#include "ascii.h"
void DelayXms(uint16 x)
{
uint8 i;
while(x--)
{
i="1275";
while(i--);
}
}
/**************************************************************
************
液晶硬件复位
*****************************************************************************
*/
void LcdReset(void)
{
ClrLcdRst();
DelayXms(5);
SetLcdRst();
DelayXms(5);
}
/****************************************************************************
**********************
发送命令
*****************************************************************************
*************************/
void LcdSendCommand(uint8 cmd)
{
uint8 i;
SetSdataOut();
ClrLcdCs();
ClrLcdSclk();
ClrLcdSdata();
SetLcdSclk();
for(i=0;i<8;i++)
{
ClrLcdSclk();
if(cmd & 0x80)
{
SetLcdSdata();
}
else
{
ClrLcdSdata();
}
SetLcdSclk();
cmd<<=1;
}
}
/****************************************************************************
*
发送数据
*****************************************************************************
***********/
void LcdSendData(uint32 Data)
{
uint32 i;
SetSdataOut();
ClrLcdCs();
ClrLcdSclk();
SetLcdSdata();
SetLcdSclk();
for(i=0;i<8;i++)
{
ClrLcdSclk();
if(Data & 0x80)
{
SetLcdSdata();
}
else
{
ClrLcdSdata();
}
SetLcdSclk();
Data<<=1;
}
}
/***************************************************************************
液晶端口初始化
************************************************************************/
void LcdPortInit(void)
{
DDR4|=((1<<LCD_RST)|(1<<LCD_CS));
DDR2|=((1<<LCD_SDATA)|(1<<LCD_SCLK));
SetLcdRst();
SetLcdCs();
SetLcdSclk();
}
/**********************************************************************
液晶初始化
*************************************************************************/
void LcdInit(void)
{
uint8 i;
LcdPortInit();
LcdReset();
LcdSendCommand(0x01); //soft reset
SetLcdCs();
DelayXms(5);
LcdSendCommand(0xc6); //initial escape
SetLcdCs();
LcdSendCommand(0xb9); //refresh set
LcdSendData(0x00);
SetLcdCs();
LcdSendCommand(0xb6); //display control
LcdSendData(0x80);
LcdSendData(0x80);
LcdSendData(0x81);
LcdSendData(84);
LcdSendData(69);
LcdSendData(82);
LcdSendData(67);
SetLcdCs();
LcdSendCommand(0xb3); //gray scale position set
LcdSendData(1);
LcdSendData(2);
LcdSendData(4);
LcdSendData(8);
LcdSendData(16);
LcdSendData(30);
LcdSendData(40);
LcdSendData(50);
LcdSendData(60);
LcdSendData(70);
LcdSendData(80);
LcdSendData(90);
LcdSendData(100);
LcdSendData(110);
LcdSendData(127);
SetLcdCs();
LcdSendCommand(0xb5); //gamma curve set
LcdSendData(0x01);
SetLcdCs();
LcdSendCommand(0xbd); //common driver output select
LcdSendData(0x00);
SetLcdCs();
LcdSendCommand(0xbe); //power control
LcdSendData(0x04);
SetLcdCs();
LcdSendCommand(0x11); //sleep out
SetLcdCs();
LcdSendCommand(0xba); //voltage control
LcdSendData(127);
LcdSendData(3);
SetLcdCs();
LcdSendCommand(0xb7); //temperature gradient set
for(i=0; i<14; i++)
{
LcdSendData(0x00);
}
SetLcdCs();
LcdSendCommand(0x29); //display ON
SetLcdCs();
LcdSendCommand(0x03); //booster voltage ON
SetLcdCs();
DelayXms(5);
LcdSendCommand(0x20); //display inversion OFF
SetLcdCs();
LcdSendCommand(0x25); //write contrast
LcdSendData(63);
SetLcdCs();
}
/* ************************************************************************
液晶清屏
*****************************************************************************
/
void LcdClr(void)
{
uint8 x, y;
LcdSendCommand(0x2a); //column address set
LcdSendData(0);
LcdSendData(97);
SetLcdCs();
LcdSendCommand(0x2b); //page address set
LcdSendData(0);
LcdSendData(66);
SetLcdCs();
LcdSendCommand(0x2c); //memory write
for(y=0;y<67;y++)
{
for(x=0;x<98;x+=2)
{
LcdSendData(0);
LcdSendData(0);
LcdSendData(0);
}
}
SetLcdCs();
}
/****************************************************************************
***************
画点
*****************************************************************************
**************/
void LcdPointWrite(uint8 x, uint8 y,uint8 rr,uint8 gg,uint8 bb)
{
uint8 b1,b2;
b1=~(((rr<<4)&0xf0)|(gg&0x0f));
b2=~(((bb<<4)&0xf0)|(rr&0x0f));
LcdSendCommand(0x2a); //column address set
LcdSendData(x);
LcdSendData(x);
SetLcdCs();
LcdSendCommand(0x2b); //page address set
LcdSendData(y);
LcdSendData(y);
SetLcdCs();
LcdSendCommand(0x2c); //memory write
LcdSendData(b1);
LcdSendData(b2);
SetLcdCs();
}
/***************************************************************************
画线
*****************************************************************************
/
void LCD_DrawLine(uint8 x1, uint8 y1, uint8 x2, uint8 y2,uint8 rr,uint8
gg,uint8 bb)
{
uint8 x,y;
if(x1<x2)
for(x=x1;x<=x2;x++)
{
if(y1<=y2)
{ y="y1"+(uint16)((x-x1)*(y2-y1))/(x2-x1);
LcdPointWrite(x,y,rr,gg,bb);}
else
{y=y1-(uint16)((x-x1)*(y1-y2))/(x2-x1);
LcdPointWrite(x, y,rr,gg,bb);}
}
else if(x1==x2)
{ x="x1";
if(y1<=y2)
{for(y=y1;y<=y2;y++)
LcdPointWrite(x, y,rr,gg,bb);}
else {
for(y=y2;y<=y1;y++)
LcdPointWrite(x, y,rr,gg,bb);}
}
else for(x=x2;x<=x1;x++)
{
if(y1>=y2)
{ y="y1-"(uint16)((x1-x)*(y1-y2))/(x1-x2);
LcdPointWrite(x, y,rr,gg,bb);}
else
{y=y1+(uint16)((x1-x)*(y2-y1))/(x1-x2);
LcdPointWrite(x, y,rr,gg,bb);}
}
if(y1<y2)
for (y=y1;y<=y2;y++)
{
if(x1<=x2)
{x=x1+(uint16)((y-y1)*(x2-x1))/(y2-y1);
LcdPointWrite(x, y,rr,gg,bb);}
else
{x=x1-(uint16)((y-y1)*(x1-x2))/(y2-y1);
LcdPointWrite(x, y,rr,gg,bb);}
}
else if(y1==y2)
{y=y1;
if(x1<=x2)
{for(x=x1;x<=x2;x++)
LcdPointWrite(x, y,rr,gg,bb);}
else
{for(x=x2;x<=x1;x++)
LcdPointWrite(x, y,rr,gg,bb);}
}
else
for(y=y2;y<=y1;y++)
{
if(x1<=x2)
{x=x1+(uint16)((y1-y)*(x2-x1))/(y1-y2);
LcdPointWrite(x, y,rr,gg,bb);}
else
{x=x1-(uint16)((y1-y)*(x1-x2))/(y1-y2);
LcdPointWrite(x, y,rr,gg,bb);}
}
}
/****************************************************************************
*********
画线形实块,
*****************************************************************************
**********/
void LCD_Drawfilled(uint8 m1,uint8 n1,uint8 m2, uint8 n2,uint8 m3, uint8
n3,uint8 rr, uint8 gg,uint8 bb)
{
uint8 left,left0,mid,mid0,mid1,right,right0;
uint8 a,a0,b,b0,c,c0,k,k0,l,l0;
uint8 x,y1,y2;
uint8 z;
z=2;
if(m1==m2)
{{mid=m1;mid0=n1;mid1=n2;}
if(m1<m3)
{right=m3;right0=n3;z=0;}
else
{left=m3;left0=n3;z=1;}
}
if(m1==m3)
{{mid=m1;mid0=n1;mid1=n3;}
if(m1<m2)
{right=m2;right0=n2;z=0;}
else
{left=m2;left0=n2;z=1;}
}
if(m2==m3)
{{mid=m2;mid0=n2;mid1=n3;}
if(m2<m1)
{right=m1;right0=n1;z=0;}
else
{left=m1;left0=n1;z=1;}
}
if(z==1)
for(x=left;x<=mid;x++)
{if(mid0<=left0)
y1=mid0+(uint16)((left0-mid0)*(mid-x))/(mid-left);
else
y1=mid0-(uint16)((mid0-left0)*(mid-x))/(mid-left);
if(mid1<=left0)
y2=mid1+(uint16)((left0-mid1)*(mid-x))/(mid-left);
else
y2=mid1-(uint16)((mid1-left0)*(mid-x))/(mid-left);
LCD_DrawLine(x,y1,x,y2,rr,gg,bb);}
else if(z==0)
for(x=mid;x<=right;x++)
{if(mid0<=right0)
y1=mid0+(uint16)((right0-mid0)*(x-mid))/(right-mid);
else
y1=mid0-(uint16)((mid0-right0)*(x-mid))/(right-mid);
if(mid1<=right0)
y2=mid1+(uint16)((right0-mid1)*(x-mid))/(right-mid);
else
y2=mid1-(uint16)((mid1-right0)*(x-mid))/(right-mid);
LCD_DrawLine(x,y1,x,y2,rr,gg,bb);}
else
{
if(m1>m2)
{k=m1;k0=n1;l=m2;l0=n2;}
else
{k=m2;k0=n2;l=m1,l0=n1;}
if(m3>k)
{a=m3;a0=n3;b=k;b0=k0;c=l;c0=l0;}
else
{if( m3>l)
{a=k;a0=k0;b=m3;b0=n3;c=l;c0=l0;}
else
{a=k;a0=k0;b=l;b0=l0;c=m3;c0=n3;}
}
for(x=c;x<=b;x++)
{if(c0>=a0)
y1=c0-(uint16)((x-c)*(c0-a0))/(a-c);
else
y1=c0+(uint16)((x-c)*(a0-c0))/(a-c);
if(c0>=b0)
y2=c0-(uint16)((x-c)*(c0-b0))/(b-c);
else
y2=c0+(uint16)((x-c)*(b0-c0))/(b-c);
LCD_DrawLine(x,y1,x,y2,rr,gg,bb);}
for(x=b;x<=a;x++)
{if(b0>=a0)
y1=b0-(uint16)((x-b)*(b0-a0))/(a-b);
else
y1=b0+(uint16)((x-b)*(a0-b0))/(a-b);
if(c0>=a0)
y2=c0-(uint16)((x-c)*(c0-a0))/(a-c);
else
y2=c0+(uint16)((x-c)*(a0-c0))/(a-c);
LCD_DrawLine(x,y1,x,y2,rr,gg,bb);}
}
}
/****************************************************************************
**************
方块块写
*****************************************************************************
*******************/
void LcdBlockWrite(uint8 x1, uint8 y1, uint8 x2, uint8 y2, uint8 rr,uint8
gg,uint8 bb)
{
uint8 x, y;
uint8 b1,b2,b3;
b1=~(((rr<<4)&0xf0)|(gg&0x0f));
b2=~(((bb<<4)&0xf0)|(rr&0x0f));
b3=~(((gg<<4)&0xf0)|(bb&0x0f));
LcdSendCommand(0x2a); //column address set
LcdSendData(x1);
LcdSendData(x2);
SetLcdCs();
LcdSendCommand(0x2b); //page address set
LcdSendData(y1);
LcdSendData(y2);
SetLcdCs();
LcdSendCommand(0x2c); //memory write
for(y=y1;y<=y2;y++)
{
for(x=x1;x<=x2;x+=2)
{
LcdSendData(b1);
LcdSendData(b2);
LcdSendData(b3);
}
}
SetLcdCs();
}
文章评论(0条评论)
登录后参与讨论