LCD12864驱动采用串行方式
发布时间:2008-3-25 21:05:32 点击: : 来源:互联网
12864(控制器为st7920)
[ 2005-8-23 21:47:57 | By: kassey ]
/********************************************
file&: lcd.h
Description: LCD12864 驱动
采用串行方式
Author: kassey@126.com July
22
2005
也就是说
只用两条线和LCD通信
#define ROW1 0x80
#define ROW2 0x90
#define ROW3 0x88
#define ROW4 0x98
unsigned char code AC_TABLE[]={
0x80
0
0
0
0
0
0
0
//第一行汉字位置
0x90
0
0
0
0
0
0
0
//第二行汉字位置
0x88
0
0
0
0
0
0
0
//第三行汉字位置
0x98
0
0
0
0
0
0
0
//第四行汉字位置
};
/*****************************************
Fucntion: delay10US(char x)
Description: delay for 10 us
Parameter: x
Author: kassey@126.com
Date: July
7
2005
7
2005
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
所以
加上8155的延时
}
void SendData(uchar Data)
{
SPIWR(Data
1
1100
1
10
0
基本指令集合
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实际为256x32
{
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
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0x7F
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0x7F
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0x7F
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0x7F
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0x00
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0x00
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0x00
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0x00
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0x7F
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0x7F
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0x7F
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0x7F
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0x00
0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
0
0
0
0
0
0
0
0
0
0
0
0
0x00
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0x00
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0x00
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0x00
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0x00
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0x00
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0x7F
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0x7F
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0x7F
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0x7F
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0x00
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0x00
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0x00
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0x00
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0x7F
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0x7F
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0x7F
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0x7F
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0x00
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
};
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)
{
}
}(出处:互联网)
链接网站:
在线监测专家网 |
芯源电子 |
5C国际商城 |
SALEIC社区 |
IC销售网 |
东方电子元件 |
SALEIC国际站 |
搜博网 更多服务可联系:QQ:71182854 369668563或电话:021-51083595