12864只是想显示一个点,为啥全屏都有点,求大神指教
时间:10-02
整理:3721RD
点击:
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit PSB=P3^2;//串,并选择端
sbit RST=P3^4;//复位(低电平有效)
sbit rs=P2^6; //数据命令选择端
sbit wr=P2^5; //读写选择端
sbit E=P2^7; //使能
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void read_busy() //读取12864是否忙
{
uchar t;
E=0;
P0=0xff;//释放数据线
rs=0;
wr=1;
E=1;
delay(10);
t=P0;
while((t&0x80)==0x80)
{
t=P0;
}
E=0;
}
void write_order(uchar com) //写指令
{
read_busy();
E=0;
rs=0;
wr=0;
P0=com;
delay(10);
E=1;
delay(10);
E=0;
}
void write_data(uchar dat) //写数据
{
read_busy();
E=0;
rs=1;
wr=0;
P0=dat;
delay(10);
E=1;
delay(10);
E=0;
}
uint read_data() //读数据
{
uint date;
read_busy();
P0=0xff;//释放数据线
E=0;
rs=1;
wr=0;
E=1;
delay(10);
date=P0;
delay(10);
E=0;
return date;
}
void draw_point(uchar x,uchar y) //画点
{
uchar i,j,n,bt1,bt2,yloc,xloc;
uint h_bite,l_bite,t_byte,n_byte,byte;
i=x/16; //确定横坐标
j=y%32; //确定纵坐标
n=x%16; //确定点亮的具体点位置
yloc=0x80+j;//y坐标
if(y>=32)
{
xloc=0x88+i; //X坐标
}
else
{
xloc=0x80+i; //X坐标
}
n_byte=0x8000>>n;
write_order(0x34);//打开扩充指令集,关闭绘图显示
write_order(yloc);//写Y轴坐标
write_order(xloc);//写X轴坐标
read_data();
h_bite=read_data()<<8;//读出高八位数据
l_bite=read_data();//读出低八位数据
t_byte=h_bite|l_bite;//读出的两字节数据
byte=t_byte|n_byte; //重新写入的值
bt1=byte>>8; //重新写入的第一字节(高八位)
bt2=byte; //重新写入的第二字节 (低八位)
write_order(yloc); //重新写入Y坐标
write_order(xloc); //重新写入X坐标
write_data(bt1);
write_data(bt2);
write_order(0x36); //打开绘图显示
write_order(0x30); //恢复基本操作指令
}
void clean() //绘图操作的清屏函数
{
uchar i,j;
write_order(0x34);
for(i=0;i<16;i++)
{
write_order(0x80+i);//写横坐标
for(j=0;j<32;j++)
{
write_order(0x80+j); //写纵坐标
write_data(0x00); //清屏高八位
write_data(0x00); //清屏低八位
}
}
write_order(0x36);
write_order(0x30);
}
void intil() //12864初始化
{
PSB=1;//并行通信
RST=0;//液晶复位
delay(10);
RST=1;
write_order(0x0c);//开显示,关游标,关反白
write_order(0x06);//数据读取和写入时游标右移,显示右移
write_order(0x30);//8位数据并行通信,基本操作
write_order(0x01); //清屏
}
void main()
{
intil();
clean();
draw_point(127,63);
while(1);
}
#define uint unsigned int
#define uchar unsigned char
sbit PSB=P3^2;//串,并选择端
sbit RST=P3^4;//复位(低电平有效)
sbit rs=P2^6; //数据命令选择端
sbit wr=P2^5; //读写选择端
sbit E=P2^7; //使能
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void read_busy() //读取12864是否忙
{
uchar t;
E=0;
P0=0xff;//释放数据线
rs=0;
wr=1;
E=1;
delay(10);
t=P0;
while((t&0x80)==0x80)
{
t=P0;
}
E=0;
}
void write_order(uchar com) //写指令
{
read_busy();
E=0;
rs=0;
wr=0;
P0=com;
delay(10);
E=1;
delay(10);
E=0;
}
void write_data(uchar dat) //写数据
{
read_busy();
E=0;
rs=1;
wr=0;
P0=dat;
delay(10);
E=1;
delay(10);
E=0;
}
uint read_data() //读数据
{
uint date;
read_busy();
P0=0xff;//释放数据线
E=0;
rs=1;
wr=0;
E=1;
delay(10);
date=P0;
delay(10);
E=0;
return date;
}
void draw_point(uchar x,uchar y) //画点
{
uchar i,j,n,bt1,bt2,yloc,xloc;
uint h_bite,l_bite,t_byte,n_byte,byte;
i=x/16; //确定横坐标
j=y%32; //确定纵坐标
n=x%16; //确定点亮的具体点位置
yloc=0x80+j;//y坐标
if(y>=32)
{
xloc=0x88+i; //X坐标
}
else
{
xloc=0x80+i; //X坐标
}
n_byte=0x8000>>n;
write_order(0x34);//打开扩充指令集,关闭绘图显示
write_order(yloc);//写Y轴坐标
write_order(xloc);//写X轴坐标
read_data();
h_bite=read_data()<<8;//读出高八位数据
l_bite=read_data();//读出低八位数据
t_byte=h_bite|l_bite;//读出的两字节数据
byte=t_byte|n_byte; //重新写入的值
bt1=byte>>8; //重新写入的第一字节(高八位)
bt2=byte; //重新写入的第二字节 (低八位)
write_order(yloc); //重新写入Y坐标
write_order(xloc); //重新写入X坐标
write_data(bt1);
write_data(bt2);
write_order(0x36); //打开绘图显示
write_order(0x30); //恢复基本操作指令
}
void clean() //绘图操作的清屏函数
{
uchar i,j;
write_order(0x34);
for(i=0;i<16;i++)
{
write_order(0x80+i);//写横坐标
for(j=0;j<32;j++)
{
write_order(0x80+j); //写纵坐标
write_data(0x00); //清屏高八位
write_data(0x00); //清屏低八位
}
}
write_order(0x36);
write_order(0x30);
}
void intil() //12864初始化
{
PSB=1;//并行通信
RST=0;//液晶复位
delay(10);
RST=1;
write_order(0x0c);//开显示,关游标,关反白
write_order(0x06);//数据读取和写入时游标右移,显示右移
write_order(0x30);//8位数据并行通信,基本操作
write_order(0x01); //清屏
}
void main()
{
intil();
clean();
draw_point(127,63);
while(1);
}
有效果图不?最好都上来看看
http://bbs.elecfans.com/jishu_481228_1_1.html
这是一个好用的版本,你可以用这个。