paradisespace 发表于 2012-5-29 09:49 ![](static/image/common/back.gif)
我没加忙检测。昨天加了忙检测效果更乱,我今天再试试。若是你现在有时间的话,帮我把程序看看吧。辛苦了 ...
我看了。关键不在你发的那部分程序上面呀。我发我的例程给你看看。
#include <reg52.h>
#define uint unsigned int
#define uchar unsigned char
#define x 0x80
#define y 0x80
#define comm 0
#define dat 1
sbit rs = P3^0; //H=data; L=command;
sbit rw = P3^1; //H=read; L=write;
sbit e = P3^2; //input enable;
sbit psb= P3^3; //H=并口; L=串口;
sbit rst= P3^4; //Reset Signal 低电平有效
sbit busy=P1^7; //lcd busy bit
void wr_lcd (uchar dat_comm,uchar content);
void chk_busy (void);
void delay (uint us);
uchar code tab1[]={
"锐显科技有限公司"
"NS:www.rxlcd.com"
};
uchar code tab5[]={
/*------------------------------------------------------------------------------
; 若数据乱码,请检查字模格式设置,注意选择正确的取模方向和字节位顺序。
; 源文件 / 文字 : C:\Documents and Settings\Administrator\桌面\新建文件夹\图片\16032(1).bmp字模
; 宽×高(像素): 128×32
; 字模格式/大小 : 单色点阵液晶字模,横向取模,字节正序/512字节
; 数据转换日期 : 2011-4-25 9:28:51
------------------------------------------------------------------------------*/
0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x03,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x07,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x0F,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x1F,0xF8,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x3E,0xFC,0x0C,0x00,0x70,0xE7,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x7C,0x7E,0x1E,0x00,0xF0,0xF2,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0xF8,0x3F,0x3F,0x00,0x70,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x01,0xF0,0x1F,0xFF,0x80,0x79,0xEF,0x0F,0x9E,0xF7,0x80,0x00,0x00,0x00,0x00,0x00,
0x03,0xE0,0x0F,0xFB,0xC0,0x79,0xEF,0x1F,0xDE,0xF7,0x80,0x00,0x00,0x00,0x00,0x00,
0x07,0xC0,0x07,0xF1,0xE0,0x39,0xC7,0x39,0xDE,0xF7,0x80,0x00,0x00,0x00,0x00,0x00,
0x0F,0x80,0x03,0xE0,0xF0,0x39,0xC7,0x3F,0xCF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,
0x1F,0x00,0x07,0xC0,0x78,0x19,0x87,0x3F,0xCF,0x9F,0x00,0x38,0x00,0x00,0x00,0x00,
0x3E,0x00,0x0F,0x80,0x3C,0x1F,0x87,0x38,0x0F,0x9F,0x3F,0x38,0x00,0x00,0x00,0x00,
0x7C,0x00,0x1F,0x00,0x1E,0x0F,0x07,0x3C,0xC7,0x9E,0x7F,0xB8,0x00,0x00,0x00,0x00,
0xFC,0x00,0x3E,0x00,0x0F,0x0F,0x07,0x1F,0xC7,0x9E,0x7B,0xB8,0x00,0x00,0x00,0x00,
0x7E,0x00,0x3E,0x00,0x0F,0x0F,0x07,0x1F,0x87,0x9E,0x70,0x3F,0x87,0xC6,0x6F,0xF0,
0x3F,0x00,0x1F,0x00,0x1E,0x00,0x00,0x00,0x00,0x00,0x70,0x3F,0xC7,0xE7,0xEF,0xF8,
0x1F,0x80,0x0F,0x80,0x3C,0x00,0x00,0x00,0x00,0x00,0x7E,0x3D,0xE0,0xF7,0x8F,0x78,
0x0F,0xC0,0x07,0xC0,0x78,0x00,0x00,0x00,0x00,0x00,0x3F,0x38,0xE7,0xF7,0x0E,0x38,
0x07,0xE0,0x0F,0xE0,0xF0,0x00,0x00,0x00,0x00,0x00,0x0F,0xB8,0xE7,0xF7,0x0E,0x38,
0x03,0xF0,0x1F,0xF1,0xE0,0x00,0x00,0x00,0x00,0x00,0x03,0xB8,0xEE,0x77,0x0E,0x38,
0x01,0xF8,0x3F,0xFB,0xC0,0x00,0x00,0x00,0x00,0x00,0x7F,0xB8,0xEE,0x77,0x0F,0x78,
0x00,0xFC,0x7E,0x7F,0x80,0x00,0x00,0x00,0x00,0x00,0x7F,0xB8,0xEF,0xF7,0x0F,0xF8,
0x00,0x7E,0xFC,0x3F,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0x38,0xE7,0xFF,0x0E,0xF0,
0x00,0x3F,0xF8,0x1E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0E,0x00,
0x00,0x1F,0xF0,0x0C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0E,0x00,
0x00,0x0F,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0E,0x00,
0x00,0x07,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x03,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
/*------------------初始化-----------------*/
void init_lcd (void)
{
rst=1;
psb=1;
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);
}
/*--------------显示点阵----------------*/
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
}
P1=content; //output data or comm
e=1;
;
e=0;
}
void chk_busy (void)
{
P1=0xff;
rs=0;
rw=1;
e =1;
while(busy==1);
e =0;
}
/*---------------------------------------*/
void delay (uint us) //delay time
{
while(us--);
}
void delay1 (uint ms)
{
uint i,j;
for(i=0;i<ms;i++)
for(j=0;j<15;j++)
delay(1);
}
/*------------------主程序--------------------*/
void main ()
{
SP=0x5f;
init_lcd ();
while (1)
{
lat_disp (0x00,0x00);
chn_disp (tab1);
con_disp (0xff,0xff,0x80,0x90,1,16);
delay1 (5000);
clrram();
lat_disp (0xcc,0xcc);
delay1 (5000);
clrram();
lat_disp (0xff,0x00);
delay1 (5000);
img_disp (tab5);
delay1 (5000);
}
}
|