摸索了好几天,终于把普中16个管脚的12864使用起来了。
不仅管脚排列与20脚的不一样,而且命令也不一样,关键是初始化命令
以下是我结合普中的例程写的,请大家参考:
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar code dis1[]=
{
0x40,0x44,0x54,0x54,0x54,0x54,0x54,0x7F,0x54,0x54,0x54,0x54,0x54,0x44,0x40,0x00,//青
0x00,0x00,0x00,0xFF,0x15,0x15,0x15,0x15,0x15,0x55,0x95,0x7F,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0xFC,0x04,0x04,0x16,0x25,0x04,0x24,0x44,0x3C,0x00,0x00,0x00,0x00,//岛
0x00,0x00,0x1C,0x11,0x11,0x11,0x1F,0x11,0x11,0x11,0x5D,0x81,0x41,0x3F,0x00,0x00,
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0xFF,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x00,//大
0x80,0x80,0x40,0x20,0x10,0x0C,0x03,0x00,0x03,0x0C,0x10,0x20,0x40,0x80,0x80,0x00,
0x40,0x30,0x11,0x96,0x90,0x90,0x91,0x96,0x90,0x90,0x98,0x14,0x13,0x50,0x30,0x00,//学
0x04,0x04,0x04,0x04,0x04,0x44,0x84,0x7E,0x06,0x05,0x04,0x04,0x04,0x04,0x04,0x00,
0x00,0x00,0xF8,0x88,0x88,0x88,0x88,0xFF,0x88,0x88,0x88,0x88,0xF8,0x00,0x00,0x00,//电
0x00,0x00,0x1F,0x08,0x08,0x08,0x08,0x7F,0x88,0x88,0x88,0x88,0x9F,0x80,0xF0,0x00,
0x80,0x82,0x82,0x82,0x82,0x82,0x82,0xE2,0xA2,0x92,0x8A,0x86,0x82,0x80,0x80,0x00,//子
0x00,0x00,0x00,0x00,0x00,0x40,0x80,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x40,0x30,0x11,0x96,0x90,0x90,0x91,0x96,0x90,0x90,0x98,0x14,0x13,0x50,0x30,0x00,//学
0x04,0x04,0x04,0x04,0x04,0x44,0x84,0x7E,0x06,0x05,0x04,0x04,0x04,0x04,0x04,0x00,
0x00,0x00,0x22,0x32,0x2A,0xA6,0xA2,0x62,0x21,0x11,0x09,0x81,0x01,0x00,0x00,0x00,//系
0x00,0x42,0x22,0x13,0x0B,0x42,0x82,0x7E,0x02,0x02,0x0A,0x12,0x23,0x46,0x00,0x00,
};
sbit wr=P2^7; //wr=1 从LCD读出
sbit rs=P2^6; //rs=0 命令,rs=1数据
sbit rd=P2^5; //rd=1 往LCD写入
sbit cs=P3^2; //片选信号,低电平有效
sbit reset=P3^3;
uchar a;
void delay(uchar z)
{
uchar x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void write_com(uchar com)
{
cs=0;
rd=1; //读禁用
rs=0; //选用命令
wr=0;
delay(1);
P0=com;
delay(1);
wr=1; //写入命令
}
void write_date(uchar date)
{
cs=0;
rd=1;
rs=1; //选用数据
wr=0;
delay(1);
P0=date;
delay(1);
wr=1;
}
void init()
{
reset=0;
delay(1);
cs=0;
reset=1;
delay(10);
write_com(0xe2); //软件初始化
delay(10);
write_com(0xa0); //表格第8个命令,设置显示方向(左右),A1为反向显示,A0为正常显示
delay(10);
write_com(0xc8); //表格第15个命令,设置显示方向(上下),C8为反向显示,C0为正常显示
delay(10);
write_com(0xa6); //表格第9个命令,A6黑字白底,A7白字黑底
delay(10);
write_com(0xa4); //表格第10个命令,A4正常显示,A5像素全开
delay(10);
write_com(0xa2); //第11个命令,a3偏压为1/7,a2偏压为1/9
delay(10);
write_com(0xf8);
write_com(0xf1); //第19个命令,双字节命令,0xf800增压为4x,f801为5x,效果差不多
delay(10);
write_com(0x81);
write_com(0x23); //第18个命令,设置背光对比度,范围0x00到0x3f
delay(10);
write_com(0x25); //第17个命令,选择调节电阻率
delay(10);
write_com(0x2f); //第16个命令,电源设置
delay(10);
write_com(0x40); //第2个命令,设置显示开始位置
delay(10);
write_com(0xaf); //第一个命令,开启显示
}
void clearscreen()
{
uchar i,j;
for(i=0;i<8;i++)
{
write_com(0xb0+i); //设置page,共8个page,每个page 8行
write_com(0x10); //设置x轴
write_com(0x04);
for(j=0;j<128;j++)
write_date(0x00); //向每个点中填入数据
}
}
void writechar(uchar x, uchar y,uchar num)
{
uchar j,x1,x2,y1,wordnum;
for(wordnum=0;wordnum<=num;wordnum++)
{
y1=y+0xb0;
write_com(y1);
x1 = (x >> 4) & 0x0F;
x2 = x & 0x0F;
write_com(0x10+x1);
write_com(0x40+x2);
j=0;
for(j=0;j<32;j++)
{
if(j==16)
{
write_com(y1+1);
write_com(0x10+x1);
write_com(0x40+x2);
}
write_date(dis1[j+32*wordnum]);
}
x=x+16;
}
}
void main()
{
init();
delay(10);
clearscreen();
while(1)
{
writechar(0,2,7);
delay(100);
}
}
|