您的位置 首页 厂商

单片机选用串行方法对LCD12864的驱动

单片机采用串行方式对LCD12864的驱动-#i nclude

#i nclude

sbit SCLK =P1^3 //E

sbit SID =P1^4; //RW

sbit RST =P1^2; // low active 可以不用,也就是说,只用两条线和LCD通信

#define ROW1 0x80

#define ROW2 0x90

#define ROW3 0x88

#define ROW4 0x98

file&: lcd.h

DescripTIon: LCD12864 驱动 ,选用串行方法,

Author:kassey@126.comJuly,22th,2005

********************************************/

#i nclude

#i nclude

sbit SCLK =P1^3 //E

sbit SID =P1^4; //RW

sbit RST =P1^2; // low acTIve 能够不必,也就是说,只用两条线和LCD通讯

#define ROW1 0x80

#define ROW2 0x90

#define ROW3 0x88

#define ROW4 0x98

单片机选用串行方法对LCD12864的驱动

unsigned char code AC_TABLE[]={

0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87, //榜首行汉字方位

0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97, //第二行汉字方位

0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f, //第三行汉字方位

0x98,0x99,0x9a,0x9b,0x9c,0x9d,0x9e,0x9f, //第四行汉字方位

};

/*****************************************

FucnTIon: delay10US(char x)

DescripTIon: delay for 10 us

Parameter: x

Author:kassey@126.com

Date: July,7th,2005

*****************************************/

void delay10US(uchar x)

{

uchar k;

for(k=0;k

}

/*****************************************

Fucntion: delay1MS(char x)

Description: delay for 10 us

Parameter: x delay for 1MS

Author:kassey@126.com

Date: July,7th,2005

*****************************************/

void delay1MS(uchar x)

{

uchar k,j;

x=x《《1;

for(k=0;k for(j=0;j《255;j++)_nop_();

}

void SendByteLCD(uchar WLCDData)

{

uchar i;

for(i=0;i《8;i++)

{

if((WLCDData《else SID=0;

SCLK=0;

SCLK=1

}

}

SPIWR(uchar Wdata,uchar RS)

{

SendByteLCD(0xf8+(RS《《1));

SendByteLCD(Wdata&0xf0);

SendByteLCD((Wdata《《4)&0xf0);

}

void SendCMD(uchar CMD)

{

SPIWR(CMD,0);

delay10US(90);//8155来模仿串行通讯,所以,加上8155的延时,

}

void SendData(uchar Data)

{

SPIWR(Data,1);

}

void LCDInit()

{

RST=0;

delay1MS(50);

RST=1;

SendCMD(0x30);//功用设置,一次送8位数据,根本指令集

SendCMD(0x0C);//0000,1100 全体显现,游标off,游标方位off

SendCMD(0x01);//0000,0001 清DDRAM

SendCMD(0x02);//0000,0010 DDRAM地址归位

SendCMD(0x80);//1000,0000 设定DDRAM 7位地址000,0000到地址计数器AC//

SendCMD(0x04);//点设定,显现字符/光标从左到右移位,DDRAM地址加 一//

SendCMD(0x0C);//显现设定,开显现,显现光标,当时显现位反白闪烁

}

/*****************************

清文本区

*****************************/

void LcmClearTXT( void )

{

unsigned char i;

SendCMD(0x30); //8BitMCU,根本指令调集

SendCMD(0x80); //AC归开始位

for(i=0;i《64;i++)

SendData(0x20);

}

/*****************************

发送字符

*****************************/

void PutStr(unsigned char row,unsigned char col,unsigned char *puts)

{

SendCMD(0x30); //8BitMCU,根本指令调集

SendCMD(AC_TABLE[8*row+col]); //开始方位

while(*puts != ‘\0’) //判别字符串是否显现结束

{

if(col==8) //判别换行

{ //若不判别,则主动从榜首行到第三行

col=0;

row++;

}

if(row==4) row=0; //一屏显现完,回到屏左上角

SendCMD(AC_TABLE[8*row+col]);

SendData(*puts); //一个汉字要写两次

puts++;

SendData(*puts);

puts++;

col++;

}

}

/*****************************

绘图

*****************************/

void PutBMP(unsigned char *puts)

{

unsigned int x=0;

unsigned char i,j;

SendCMD(0x34); //8Bit扩大指令集,即使是36H也要写两次

SendCMD(0x36); //绘图ON,根本指令集里边36H不能开绘图

for(i=0;i《32;i++) //12864实践为256×32

{

SendCMD(0x80|i); //行方位

SendCMD(0x80); //列方位

for(j=0;j《32;j++) //256/8=32 byte

{ //列方位每行主动添加

SendData(puts[x]);

x++;

}

}

}

void ClearScreen()

{ uchar i,j,x,y;

LCDInit();

SendCMD(0x3e);// RE=1 扩展指令挑选 G=1 开图形显现

x=0x80;

y=0x80;

for(j=0;j《64;j++)

{

y=0x80;

SendCMD(x);

SendCMD(y);

for(i=0;i《32;i++)

{

SendData(0x00);

}

x=x+1;

}

}

void Sendint(uint dd)

{

SendData(dd》》8);

SendData(dd);

}

/*****************************

打点 x=0:128; y=0:64;

*****************************/

void Gra(uchar x,uchar y)

{

uchar xx,yy;

SendCMD(0x34);

SendCMD(0x36);

xx=x/16;

yy=63-y;

if(yy》=32){xx=xx+8;yy-=32;}

SendCMD(0x80+yy);

SendCMD(0x80+xx);

Sendint(0x8000》》(x%16));

}

uchar code IBM[]=

{

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x7F,0xFF,0xFF,0x87,0xFF,0xFF,0xFF,0xF0,0x00,0xFF,0xFF,0xE0,0x00,0x07,0xFF,0xFE,

0x7F,0xFF,0xFF,0x87,0xFF,0xFF,0xFF,0xF0,0x00,0xFF,0xFF,0xE0,0x00,0x0F,0xFF,0xFE,

0x7F,0xFF,0xFF,0x87,0xFF,0xFF,0xFF,0xF8,0x00,0xFF,0xFF,0xE0,0x00,0x0F,0xFF,0xFE,

0x7F,0xFF,0xFF,0x87,0xFF,0xFF,0xFF,0xFC,0x00,0xFF,0xFF,0xF0,0x00,0x1F,0xFF,0xFE,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x7F,0xFF,0xFF,0x87,0xFF,0xFF,0xFF,0xFF,0x00,0xFF,0xFF,0xF8,0x00,0x3F,0xFF,0xFE,

0x7F,0xFF,0xFF,0x87,0xFF,0xFF,0xFF,0xFF,0x80,0xFF,0xFF,0xFC,0x00,0x7F,0xFF,0xFE,

0x7F,0xFF,0xFF,0x87,0xFF,0xFF,0xFF,0xFF,0x80,0xFF,0xFF,0xFC,0x00,0x7F,0xFF,0xFE,

0x7F,0xFF,0xFF,0x87,0xFF,0xFF,0xFF,0xFF,0x80,0xFF,0xFF,0xFC,0x00,0x7F,0xFF,0xFE,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0xFF,0xC0,0x00,0x0F,0xF8,0x00,0xFF,0xC0,0x03,0xFF,0xFE,0x01,0xFF,0xFF,0x00,

0x00,0xFF,0xC0,0x00,0x0F,0xF8,0x00,0xFF,0xC0,0x03,0xFF,0xFF,0x01,0xFF,0xFF,0x00,

0x00,0xFF,0xC0,0x00,0x0F,0xF8,0x00,0xFF,0xC0,0x03,0xFF,0xFF,0x03,0xFF,0xFF,0x00,

0x00,0xFF,0xC0,0x00,0x0F,0xF8,0x00,0xFF,0x80,0x03,0xFF,0xFF,0x83,0xFF,0xFF,0x00,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0xFF,0xC0,0x00,0x0F,0xFF,0xFF,0xFF,0x00,0x03,0xFF,0xFF,0xCF,0xFF,0xFF,0x00,

0x00,0xFF,0xC0,0x00,0x0F,0xFF,0xFF,0xFE,0x00,0x03,0xFF,0xFF,0xEF,0xFF,0xFF,0x00,

0x00,0xFF,0xC0,0x00,0x0F,0xFF,0xFF,0xFE,0x00,0x03,0xFF,0xFF,0xEF,0xFF,0xFF,0x00,

0x00,0xFF,0xC0,0x00,0x0F,0xFF,0xFF,0xFC,0x00,0x03,0xFF,0xBF,0xFF,0xFB,0xFF,0x00,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0xFF,0xC0,0x00,0x0F,0xFF,0xFF,0xFC,0x00,0x03,0xFF,0x8F,0xFF,0xF3,0xFF,0x00,

0x00,0xFF,0xC0,0x00,0x0F,0xFF,0xFF,0xFE,0x00,0x03,0xFF,0x87,0xFF,0xE3,0xFF,0x00,

0x00,0xFF,0xC0,0x00,0x0F,0xFF,0xFF,0xFE,0x00,0x03,0xFF,0x87,0xFF,0xE3,0xFF,0x00,

0x00,0xFF,0xC0,0x00,0x0F,0xFF,0xFF,0xFF,0x00,0x03,0xFF,0x87,0xFF,0xC3,0xFF,0x00,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0xFF,0xC0,0x00,0x0F,0xF8,0x00,0xFF,0x80,0x01,0xFF,0x83,0xFF,0x83,0xFF,0x00,

0x00,0xFF,0xC0,0x00,0x0F,0xF8,0x00,0xFF,0xC0,0x01,0xFF,0x81,0xFF,0x03,0xFF,0x00,

0x00,0xFF,0xC0,0x00,0x0F,0xF8,0x00,0xFF,0xC0,0x01,0xFF,0x81,0xFF,0x03,0xFF,0x00,

0x00,0xFF,0xC0,0x00,0x0F,0xF8,0x00,0xFF,0xC0,0x01,0xFF,0x80,0xFF,0x03,0xFF,0x00,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x7F,0xFF,0xFF,0x87,0xFF,0xFF,0xFF,0xFF,0xC0,0xFF,0xFF,0xC0,0x7E,0x03,0xFF,0xFE,

0x7F,0xFF,0xFF,0x87,0xFF,0xFF,0xFF,0xFF,0xC0,0xFF,0xFF,0xC0,0x7C,0x03,0xFF,0xFE,

0x7F,0xFF,0xFF,0x87,0xFF,0xFF,0xFF,0xFF,0xC0,0xFF,0xFF,0xC0,0x3C,0x03,0xFF,0xFE,

0x7F,0xFF,0xFF,0x87,0xFF,0xFF,0xFF,0xFF,0x80,0xFF,0xFF,0xC0,0x3C,0x03,0xFF,0xFE,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x7F,0xFF,0xFF,0x87,0xFF,0xFF,0xFF,0xFE,0x00,0xFF,0xFF,0xC0,0x18,0x03,0xFF,0xFE,

0x7F,0xFF,0xFF,0x87,0xFF,0xFF,0xFF,0xFE,0x00,0xFF,0xFF,0xC0,0x18,0x03,0xFF,0xFE,

0x7F,0xFF,0xFF,0x87,0xFF,0xFF,0xFF,0xFC,0x00,0xFF,0xFF,0xC0,0x08,0x03,0xFF,0xFE,

0x7F,0xFF,0xFF,0x87,0xFF,0xFF,0xFF,0xF8,0x00,0xFF,0xFF,0xC0,0x00,0x03,0xFF,0xFE,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

};

void Put(uchar *p)

{

uchar xx,yy

for(yy=0;yy《32;yy++)

for(xx=0;xx《8;xx++)

{

SendCMD(0x80+yy); //y 按位

SendCMD(0x80+xx);//x 按16位

SendData(*p);

p++;

SendData(*p);

p++;

}

for(yy=0;yy《32;yy++)

for(xx=8;xx《16;xx++)

{

SendCMD(0x80+yy); //y 按位

SendCMD(0x80+xx);//x 按16位

SendData(*p);

p++;

SendData(*p);

p++;

}

}

void Clear()

{ uchar i,j;

LCDInittest();

SendCMD(0x34);

SendCMD(0x3e);// RE=1 扩展指令挑选 G=1 开图形显现

for(j=0;j《16;j++)

for(i=0;i《32;i++)

{

SendCMD(0x80+i);

SendCMD(0x80+j);

SendData(0x00);

SendData(0x00);

}

}

void main()

{

LCDInittest();

LcmClearBMP();

Put(IBM);

while(1)

{

}

}

声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/changshang/346872.html

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部