本帖最后由 yuanguojian260 于 2012-7-21 18:19 编辑
显示lcd的时候显示的第一行被第二行覆盖,而且第二行与第一行显示的也是一样的字符,我猜是CGRAM的地址设置问题,但我不知道怎么改,上代码,各位大侠看看,我想知道详细的原因。
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit rs=P3^5;
sbit lcden=P3^4;
sbit dula=P2^6;
sbit wela=P2^7;
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
uchar code table[]={0x0f,0x01,0x01,0x01,0x01,0x01,0x1f,0x10,
0x08,0x08,0x08,0x09,0x0a,0x0c,0x1f,0x08,
0x01,0x00,0x10,0x03,0x00,0x00,0x19,0x00,
0x1e,0x0a,0x0a,0x1f,0x12,0x12,0x1e,0x00,
0x11,0x0a,0x04,0x1f,0x04,0x04,0x0e,0x04,
0x00,0x01,0x02,0x06,0x0a,0x02,0x02,0x02,
0x04,0x1f,0x04,0x04,0x0e,0x04,0x04,0x1f};
uchar code table1[]={0x10,0x1f,0x01,0x01,0x01,0x09,0x05,0x03,
0x08,0x0c,0x0a,0x09,0x08,0x09,0x0a,0x0c,
0x01,0x01,0x02,0x02,0x10,0x08,0x00,0x00,
0x00,0x1e,0x12,0x12,0x12,0x1e,0x00,0x00,
0x1f,0x04,0x04,0x04,0x04,0x04,0x00,0x00,
0x02,0x02,0x02,0x02,0x00,0x00,0x00,0x00,
0x05,0x05,0x05,0x06,0x04,0x00,0x00,0x00};
void write_com(uchar com) //写指令
{
rs=0;
lcden=0;
P0=com;
delay(5);
lcden=1;
delay(5);
lcden=0;
}
void write_date(uchar date) //写数据
{
rs=1;
lcden=0;
P0=date;
delay(5);
lcden=1;
delay(5);
lcden=0;
}
void init() //LCD初始化
{
dula=0;
wela=0;
rs=0;
lcden=1;
write_com(0x38);
write_com(0x0c);
write_com(0x06);
write_com(0x01);
}
void main()
{
uchar i;
init();
write_com(0x40); //设置CGRAM的地址
for(i=0;i<56;i++)
{
write_date(table); //读上半部分
delay(5);
}
write_com(0x80);
for(i=0;i<7;i++)
{
write_date(i);
}
write_com(0x40); // (我才是这里设置有问题)设置下半部分CGRAM地址
for(i=0;i<56;i++)
{
write_date(table1); //读下半部分
delay(5);
}
write_com(0x80+0x40);
for(i=0;i<7;i++)
{
write_date(i);
}
while(1);
} |