微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > 自制单片机之七……LCD12864的驱动之源代码

自制单片机之七……LCD12864的驱动之源代码

时间:11-13 来源:互联网 点击:

void LcmPutBMP( uchar *puts )
{
uint X=0;
Page = 0;
Col = 0;
for(Page=0;Page<8;Page++)
{
for(Col=0;Col<128;Col++)
{
WriteData( puts[X] );
X++;
}
}
}
void LcmReverseBMP( void )
{
uchar temp;
Page = 0;
Col = 0;
for(Page=0;Page<8;Page++)
{
for(Col=0;Col<128;Col++)
{
temp = ReadData(); //空读一次
temp = ReadData();
temp = ~temp;
WriteData(temp);
}
}
}
void LcmPutHZ_12( uchar x,uchar y,uchar HZcode )
{
uchar offset,Rd,Wt,m,tmp,i;
uint n;
if(x<117&y<53) //x为横向起始点数0-117,超过117就显示不全一个汉字了。y同理。
{
Page=(y & 0x38)>>3; //将竖向的点阵数y转换成页数
Col=x; //横向的X就是LCD的列数。
n = 0x18*HZcode; //一个汉字24字节(18H),HZcode为字库序号。n就是要显示汉字的起始地址
offset=y&0x07;    //将显示该页的竖向偏移量。
if(offset<5) //如果偏移量小于5,那么在竖向用两个页的范围就可显示出汉字了。
{

for(i=12;i>0;i--)
{
Rd=ReadData();
Rd=ReadData(); //读出LCD该Page、Col位置的上半个数据。
m=HZK_12[n]; //读出汉字模第n的数据。
Wt=Rd&(0xff>>(8-offset))|(m WriteData(Wt); //再将Wt写回LCD
Page++; //页位置移到下半个汉字位置
n++;
tmp=m; //将取得的上半个字模数据交给tmp
m=HZK_12[n]; //取下半个字模数据
Rd=ReadData(); //读LCD下半个字模数据
Rd=ReadData();
Wt=tmp>>(8-offset)|(m|(rd&(0xff<(offset+4))); br="">|(rd&(0xff<(offset+4))); br=""> WriteData(Wt);//再写回LCD
Col++;//列数增加一
Page--;//将页数返回上半个汉字位置。
n++;
}
}
else //如果偏移量大于或等于5,竖向就要用3个页的范围来显示一个汉字了。
{
for(i=12;i>0;i--)
|(rd&(0xff<(offset+4)));>|(rd&(0xff<(offset+4)));>

{
Rd=ReadData();
Rd=ReadData(); //读取LCD上汉字上部位置的原来数据。
m=HZK_12[n]; //读取汉字模数据
Wt=Rd&(0xff>>(8-offset))|(m WriteData(Wt); //写回
Page++; //到下一页即汉字中部位置
n++;
tmp=m; //上半个字模交给tmp
m=HZK_12[n]; //读取下半个字模
Wt=tmp>>(8-offset)|(m WriteData(Wt); //写回
Page++; //到下一页即汉字下部位置
n++;
Rd=ReadData();
Rd=ReadData(); //读取LCD上汉字下部位置的原来数据
Wt=m>>(8-offset)|(Rd&(0xff<(offset-4))); //嵌入
WriteData(Wt); //写回
Page=Page-2;//恢复位置
Col++; //修正下一个汉字的起始位置
}
}
}
}

uchar * uchartostr(uchar unm)
{
uchar x00,xx,x0,x,n;
x00=unm/100;
xx=unm%100;
x0=xx/10;
x=xx%10;
n=0;
if(x00!=0)
{ str[n]=x00+48; //值加48即为字符
n++;
}
if(!(x00==0&x0==0))
{ str[n]=x0+48;
n++;
}
str[n]=x+48;
n++;
str[n]=\0;
return str;

}
void LcmPutAsc( uchar asc )
{
uchar j;
uint x;
x = 5*(asc-32);
for(j=0;j<5;j++)
{
WriteData(ASC_5x7[x]);
x++;
Col++;
}
WriteData(0x00);
Col++;

}

void LcmPutstr( uchar row,uchar y,uchar * str )
{ unsigned char * x;
x=str;
Page=row;
Col=y;
while(*x!=\0)
{ LcmPutAsc( *x );
x++;
}

}

void LcmPutpoint( uchar ro,uchar lie,uchar colour ) //画点函数
{
if((ro<64)&(lie<128))
{
uchar modbyte,outByte;
uchar offsetbit;
Col=lie; //列等于lie
Page=(ro & 0x38)>>3; //页等于行数row与00111000B再右移3位
offsetbit=ro&0x07; //偏移量为行数与00000111
modbyte=1;
modbyte<= offsetbit; //输出位的模00000001左移offsetbit位
outByte=ReadData();
outByte=ReadData();
if(colour==0)
{
modbyte=~modbyte;
outByte=modbyte&outByte; //输出位不影响其它位
}
else outByte=modbyte|ReadData(); //输出位不影响其它位
WriteData(outByte);
}
}

void Delay(uint MS)
{
uchar us,usn;
while(MS!=0)
{
usn = 2; //for 12M
while(usn!=0)
{
us=0xf6;
while (us!=0){us--;};
usn--;
}
MS--;
}
}
void Main( void )
{
uchar x,i;
LcmInit();
LcmClear();
while(1)
{
LcmClear();
LcmPutBMP(BMP1);
Delay(3000);
LcmClear();
//LcmReverseBMP();
Delay(1000);
//LcmClear();
x=0;
for(i=0;i<8;i++)
{
LcmPutHZ_12(x,i*7,i);
x=x+16;
}
LcmPutstr( 4,2,"Hello" );
LcmPutstr( 6,35,"World!" );
Delay(5000);

}
}

unsigned char code BMP1[]={ //字节倒序
//-- 调入了一幅图像:
//宽度x高度=1264

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x80,0xE0,0xF0,0xFC,0xFE,0xFE,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0x9F,0xCF,0xDF,0x9F,
0x9E,0x3E,0xFF,0xFE,0xFE,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFA,0xFC,0xF8,0xE0,0xC0,0x80,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x80,0xC0,0xF0,0xF8,0xFC,0xFE,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xDF,0xEF,
0xCF,0xDF,0x9F,0x0F,0x1F,0x7F,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFE,0xFC,0xF0,0xC0,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0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x7F,0x7F,0x7F,0x7F,0x7C,
0x7C,0x7C,0x78,0x78,0x70,0x58,0x00,0x00,
0x40,0x70,0x78,0x7C,0x7F,0x7F,0x7F,0x7F,
0x7F,0x7F,0x07,0x07,0x0F,0x1F,0x3F,0x7F
};

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top