打印
[ZLG-MCU]

有用过P89LPC952驱动过液晶显示的吗

[复制链接]
1490|8
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
linhai1986|  楼主 | 2009-8-25 10:14 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
各位我用的是P89LPC952来驱动液晶显示 液晶是肇庆金鹏的OCMJ12232C-2的带中文字库的LCD,因为P89LPC952是普通8051的6倍,我由用的是内部RC,频率是7.373我不分频的时候液晶显示乱码,看不清显示的是什么,将DIVM分屏(做过 DIVM=0X02;和DIVM=0X03;这样频率在5M和3M多,这是8051的频率)可是这样之后液晶就没反应了。上有我的程序源码请高手指点!!!!!(如有P89LPC952驱动液晶的示例的话请传一个我参考一下。)

相关帖子

沙发
linhai1986|  楼主 | 2009-8-25 10:15 | 只看该作者
#include <reg952.h> //P89LPC952包含函数

#include <string.h>

#include <intrins.h> //字符串函数

#include <stdlib.h> //动态存储分配函数

#include <math.h> //数学函数

#include <stdio.h> //输入输出函数



#define uint unsigned int
#define uchar unsigned char
#define x 0x80
#define y 0x80
#define comm 0
#define dat 1


sbit rs = P2^3; //H=data; L=command;
sbit rw = P2^4; //H=read; L=write;
sbit e = P2^5; //input enable;
//sbit busy=P0^7; //lcd busy bit


void wr_lcd (uchar dat_comm,uchar content);
void chk_busy (void);
void delay (uint ms);







uchar code tab1[]={
"内置二级字库可在"
"任意位置反白显示"
};

uchar code tab3[]={
"金鹏电子有限公司"
"Golden Palm TECH"
};

uchar code tab5[]={
/*-- 调入了一幅图像:F:\梁\画图\HOCO12832.bmp --*/
/*-- 宽度x高度=128x32 --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x1E,0x00,0x00,0x00,0x00,0x00,0x07,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x7F,0x80,0x00,0x00,0x00,0x00,0x18,0x0C,0x00,0x00,0x01,0x00,0x00,0x00,0x00,
0x01,0xFF,0x80,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x13,0x10,0x03,0xFE,0x00,
0x03,0xFF,0xC0,0x00,0x00,0x00,0x00,0x58,0x00,0x00,0x00,0x3F,0x30,0x1F,0xFF,0xC0,
0x03,0xFF,0xE0,0x00,0x00,0x00,0x00,0x8C,0x03,0xF0,0x00,0x7F,0xE0,0x7C,0x01,0xE0,
0x03,0xFF,0xF0,0x00,0x00,0x00,0x01,0x36,0x06,0xC0,0x00,0x5F,0xC0,0xFF,0xFC,0x60,
0x01,0xFF,0xF0,0x00,0x00,0x00,0x02,0x1B,0x0F,0x80,0x00,0xFF,0x01,0xFE,0x0F,0x30,
0x00,0xEF,0xF0,0x00,0x00,0x00,0x02,0x6D,0x9F,0x00,0x00,0x3E,0x03,0xFF,0xF1,0x90,
0x00,0xFF,0xF8,0x00,0x00,0x00,0x04,0x36,0xFE,0x00,0x01,0xFF,0x07,0xFF,0xFC,0x90,
0x00,0xEF,0xFF,0xFF,0x80,0x00,0x04,0xDB,0x7E,0x00,0x03,0xFF,0x87,0xFF,0xFC,0xD0,
0x00,0x0F,0xFF,0xFF,0xC0,0x00,0x04,0x6D,0xFC,0x00,0x07,0xFF,0x8F,0xFF,0xFE,0x50,
0x00,0x0F,0xFF,0xFF,0xE0,0x00,0x04,0x36,0xFC,0x10,0x07,0xFF,0x8F,0xFF,0xFE,0x90,
0x00,0x0F,0xFF,0xFF,0xE0,0x00,0x04,0x1B,0xF8,0x10,0x07,0xFF,0xCF,0xFF,0xFE,0x80,
0x00,0x0F,0xFF,0xFF,0xF0,0x00,0x04,0x0F,0xF8,0x10,0x07,0xFF,0xFF,0xFF,0xFA,0x00,
0x00,0x07,0xFF,0xFF,0xF0,0x00,0x04,0x07,0xF0,0x10,0x07,0xFF,0xFF,0xFF,0xFA,0x00,
0x00,0xFF,0xFF,0xFF,0xF8,0x00,0x02,0x03,0xF0,0x20,0x07,0xFF,0xFF,0xFF,0xBA,0x00,
0x00,0xFD,0xFF,0xFF,0xFC,0x00,0x02,0x03,0xF0,0x20,0x03,0xFF,0xFF,0xDF,0xB8,0x00,
0x00,0xC1,0xC0,0x3F,0xFC,0x00,0x01,0x01,0xE0,0x40,0x00,0xFF,0xFF,0xDF,0xB0,0x00,
0x00,0x81,0xC0,0x3F,0xCE,0x00,0x00,0x81,0xE0,0x80,0x00,0x7F,0xFF,0xDF,0xA0,0x00,
0x00,0x81,0x80,0x1D,0xCF,0x00,0x00,0x41,0xE1,0x00,0x00,0x3F,0xFF,0x9B,0x00,0x00,
0x01,0x83,0x80,0x1F,0xC7,0x80,0x00,0x21,0xE2,0x00,0x00,0x1F,0xFD,0xB6,0x00,0x00,
0x01,0xC3,0x00,0x0E,0xE6,0x80,0x00,0x19,0xEC,0x00,0x00,0x07,0xFE,0x20,0x00,0x00,
0x00,0xC3,0x00,0x07,0x67,0x40,0x00,0x07,0xF0,0x00,0x00,0x03,0x3E,0x00,0x00,0x00,
0x00,0x02,0x00,0x03,0xE7,0xA0,0x00,0x00,0x00,0x00,0x00,0x02,0x8E,0x00,0x00,0x00,
0x00,0x06,0x00,0x03,0x83,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x03,0x00,0x00,0x00,
0x00,0x06,0x00,0x07,0x03,0x00,0x77,0x46,0x74,0x24,0x80,0x06,0x04,0x00,0x00,0x00,
0x00,0x1C,0x00,0x06,0x00,0x00,0x55,0x45,0x54,0x57,0x80,0x00,0x00,0x00,0x00,0x00,
0x00,0x1C,0x00,0x0E,0x00,0x00,0x45,0x45,0x74,0x57,0x80,0x08,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x1C,0x00,0x00,0x55,0x45,0x44,0x74,0x80,0xF0,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x38,0x00,0x00,0x77,0x76,0x47,0x54,0x80,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};


/*------------------初始化-----------------*/
void init_lcd (void)
{
wr_lcd (comm,0x30); /*30---基本指令动作*/
wr_lcd (comm,0x01); /*清屏,地址指针指向00H*/
wr_lcd (comm,0x06); /*光标的移动方向*/
wr_lcd (comm,0x0c); /*开显示,关游标*/
}
/*---------------显示汉字或字符----------------*/
void chn_disp (uchar code *chn)
{
uchar i,j;
wr_lcd (comm,0x30);
wr_lcd (comm,0x80);
j=0;
for (i=0;i<16;i++)
wr_lcd (dat,chn[j*16+i]);
wr_lcd (comm,0x90);
j=1;
for (i=0;i<16;i++)
wr_lcd (dat,chn[j*16+i]);
}
/*----------------显示图形-----------------*/
void img_disp (uchar code *img)
{
uchar i,j;
for(j=0;j<32;j++)
{
for(i=0;i<8;i++)
{
wr_lcd (comm,0x34);
wr_lcd (comm,y+j);
wr_lcd (comm,x+i);
wr_lcd (comm,0x30);
wr_lcd (dat,img[j*16+i*2]);
wr_lcd (dat,img[j*16+i*2+1]);
}
}
wr_lcd (comm,0x36);
}

使用特权

评论回复
板凳
linhai1986|  楼主 | 2009-8-25 10:15 | 只看该作者
/*--------------显示点阵----------------*/
void lat_disp (uchar data1,uchar data2)
{
uchar i,j;
for(j=0;j<16;j++)
{
for(i=0;i<8;i++)
{
wr_lcd (comm,0x34);
wr_lcd (comm,y+j*2);
wr_lcd (comm,x+i);
wr_lcd (comm,0x30);
wr_lcd (dat,data1);
wr_lcd (dat,data1);
}
for(i=0;i<8;i++)
{
wr_lcd (comm,0x34);
wr_lcd (comm,y+j*2+1);
wr_lcd (comm,x+i);
wr_lcd (comm,0x30);
wr_lcd (dat,data2);
wr_lcd (dat,data2);
}
}
wr_lcd (comm,0x36);
}
/*-----------------------------------------------*/
//当data1=0xff,data2=0xff时,在x0,y0处反白显示16xl*yl.
void con_disp (uchar data1,uchar data2,uchar x0,uchar y0,uchar xl,uchar yl)
{
uchar i,j;
for(j=0;j<yl;j++)
{
for(i=0;i<xl;i++)
{
wr_lcd (comm,0x34);
wr_lcd (comm,y0+j);
wr_lcd (comm,x0+i);
wr_lcd (comm,0x30);
wr_lcd (dat,data1);
wr_lcd (dat,data2);
}
}
wr_lcd (comm,0x36);
}
/*--------------清DDRAM------------------*/
void clrram (void)
{
wr_lcd (comm,0x30);
wr_lcd (comm,0x01);
}
/*-----一一><= |= 与&& 或||---*/
void wr_lcd (uchar dat_comm,uchar content)
{
chk_busy ();
if(dat_comm)
{
rs=1; //data
rw=0; //write
}
else
{
rs=0; //command
rw=0; //write
}
P5=content; //output data or comm
e=1;
;
e=0;
}

void chk_busy (void)
{
P5=0xff;
rs=0;
rw=1;
e =1;
P5=P5&&0X80;
while(P5==0X80);
// while(busy==1);
e =0;
}





//********************************************************
// 延时函数1MS //
//********************************************************

void delay(uint n) //delay timen=1为1ms,n=2为2ms。。。。

{

int j;

while(n>0)

{

for(j=0;j<=669;j++);

n--;

}

}



/*------------------主程序--------------------*/
void main ()
{

// P0M1 = 0x00; //0 0准双向//0 1推挽//1 0 仅输入//1 1开漏 FF
// P0M2 = 0x00; // E0
// P1M1 = 0x00; // EF
// P1M2 = 0x00; // 43
P2M1 = 0x00; // 1F
P2M2 = 0x00; // FF
// P4M1 = 0x00; // EF
// P4M2 = 0x00; // 43
P5M1 = 0x00; // 1F
P5M2 = 0x00; // FF

P2=0XFF;
P5=0XFF;

DIVM=0X02; //对RC分频

EA=1; //中断总允许
EWDRT=1; //看门狗中断允许
WDCON=0xE0; //关看门狗定时器




init_lcd ();
while (1)
{
lat_disp (0x00,0x00);
chn_disp (tab1);
con_disp (0xff,0xff,0x84,0x90,2,16);
delay (1000);
clrram();
lat_disp (0xcc,0xcc);
delay (1000);
wr_lcd (comm,0x34);
chn_disp (tab3);
delay (1000);
clrram();
lat_disp (0xff,0x00);
delay (1000);
img_disp (tab5);
delay (1000);
}

}

使用特权

评论回复
地板
xiaoxin1986| | 2009-8-25 10:17 | 只看该作者
程序好长啊!

使用特权

评论回复
5
xiaoxin1986| | 2009-8-25 10:17 | 只看该作者
教你个最简单的办法,向原厂要LCD的驱动范例

使用特权

评论回复
6
linhai1986|  楼主 | 2009-8-25 10:36 | 只看该作者
上面的程序就是LCD公司的范例啊,同样的程序我用938都可以显示的,952就不行啊,是不是952的P5口是外部的原因啊。谁能解惑啊。。。。。。

使用特权

评论回复
7
xiaoxin1986| | 2009-8-25 10:38 | 只看该作者
你怀疑P5口,那您可以改为其实的IO试一试啊。

使用特权

评论回复
8
xiaoxin1986| | 2009-8-25 10:38 | 只看该作者
【LPC900单片机三大特性】
1.速度快,6倍速
2.IO口要配置
3.电压低3.3V
4.外围功能多

使用特权

评论回复
9
xiaoxin1986| | 2009-8-25 10:38 | 只看该作者
关于LPC900单片机更多的问题解答可以到下面的网址里查找
http://www.zlgmcu.com/philips/philips-yingrong-lpc900.asp

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

172

主题

1451

帖子

0

粉丝