这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 嵌入式开发 » MCU » 89c2051与LCD的接口

共1条 1/1 1 跳转至

89c2051与LCD的接口

菜鸟
2005-09-16 15:25:24     打赏


#include <reg51.h>
sbit lcddi=P3^0;
sbit lcdrw=P3^1;
sbit lcden=P3^2;
sbit lcdrs=P3^5;
sbit lcdcs1=P3^3;
sbit lcdcs2=P3^4;
sbit lcdbusy=ACC^7;
/*"南"字模*/
unsigned char code nan[32]={0x04,0x04,0xE4,0x24,0x24,0x64,0xB4,0x2F,
0x24,0xA4,0x64,0x24,0x24,0xE6,0x04,0x00,
0x00,0x00,0x7F,0x04,0x05,0x05,0x05,0x7F,
0x05,0x05,0x05,0x25,0x44,0x3F,0x00,0x00};
/*"京"字模*/
unsigned char code jin[32]={0x00,0x04,0x04,0xE4,0x24,0x24,0x25,0x26,
0x24,0x24,0x24,0xE4,0x06,0x04,0x00,0x00,
0x00,0x20,0x10,0x19,0x0D,0x41,0x81,0x7F,
0x01,0x01,0x05,0x0D,0x38,0x10,0x00,0x00};
/*片一图形阵*/
unsigned char code pic10[64];
unsigned char code pic11[64];
unsigned char code pic12[64];
unsigned char code pic13[64];
unsigned char code pic14[64];
unsigned char code pic15[64];
unsigned char code pic16[64];
unsigned char code pic17[64];

unsigned char code pic20[64];
unsigned char code pic21[64];
unsigned char code pic22[64];
unsigned char code pic23[64];
unsigned char code pic24[64];
unsigned char code pic25[64];
unsigned char code pic26[64];
unsigned char code pic27[64];
void delay(unsigned int x)
{unsigned int x1;
x1=x;
while(x1--);
x1=x;
while(x1--);
}
void lcdselect(unsigned char sl)
{
if(sl==1)
{lcdcs1=1;
lcdcs2=0;
}
if(sl==2)
{lcdcs1=0;
lcdcs2=1;
}
if(sl==3)
{lcdcs1=1;
lcdcs2=1;
}
}
void lcdwritecom(unsigned char x)
{
P1=x;
lcdrw=0;
lcddi=0;
lcden=1;
delay(1000);
lcden=0;
}
unsigned char lcdreadcom(void) /*液晶读命令字*/
{
unsigned char i;
P1=255;
lcdrw=1;
lcddi=0;
lcden=1;
i=P1;
lcden=0;
return i;
}
void lcdwritedata(unsigned char x) /*液晶写数据*/
{
P1=x;
lcdrw=0;
lcddi=1;
lcden=1;
delay(1000);
lcden=0;
}
unsigned char lcdreaddata(void) /*液晶读数据*/
{
unsigned char i;
P1=255;
lcdrw=1;
lcddi=1;
lcden=1;
i=P1;
lcden=0;
return i;
}
void wait(void) /*等待液晶不忙*/
{
do{ACC=lcdreadcom();
}
while(lcdbusy==1);
}
void initlcd(void) /*初始化液晶模块*/
{lcdselect(1); /*片一使能*/
lcdwritecom(0x3f);
wait();
lcdwritecom(0x40);
wait();
lcdwritecom(0xb8);
wait();
lcdwritecom(0xc0);
wait();
lcdselect(2); /*片二使能*/
lcdwritecom(0x3f);
wait();
lcdwritecom(0x40);
wait();
lcdwritecom(0xb8);
wait();
lcdwritecom(0xc0);
wait();
}
void main(void)
{int j,i;
IE=0x00;
lcdrs=0;
delay(1000);
lcdrs=1;
initlcd();
/*清屏*/
for(j=0;j<=7;j++)
{
lcdselect(1);
lcdwritecom(0xb8+j); /*选页*/
wait();
lcdselect(2);
lcdwritecom(0xb8+j);
wait();

for(i=0;i<=63;i++) /*写数据*/
{lcdselect(1);
lcdwritedata(0x55);
wait();
lcdselect(2);
lcdwritedata(0xaa);
wait();
}
}
/*关显示*/
/*lcdselect(1);
lcdwritecom(0x3e);
wait();
lcdselect(2);
lcdwritecom(0x3e);
wait();*/
/*送数据*/
for(j=0;j<=1;j++)
{lcdselect(1);
lcdwritecom(0xb8+j*4); /*nan up*/
wait();
lcdwritecom(0x40);
wait();
for(i=0;i<=63;i++)
{lcdwritedata(nan[i%16]);
wait();
}
lcdwritecom(0xb8+j*4+1); /*nan down*/
wait();
lcdwritecom(0x40);
wait();
for(i=0;i<=63;i++)
{lcdwritedata(nan[16+i%16]);
wait();
}

lcdwritecom(0xb8+j*4+2); /*jin up*/
wait();
lcdwritecom(0x40);
wait();
for(i=0;i<=63;i++)
{lcdwritedata(jin[i%16]);
wait();
}
lcdwritecom(0xb8+j*4+3); /*jin down*/
wait();
lcdwritecom(0x40);
wait();
for(i=0;i<=63;i++)
{lcdwritedata(jin[16+i%16]);
wait();
}
lcdselect(2); /*select 2*/
lcdwritecom(0xb8+j*4); /*nan up*/
wait();
lcdwritecom(0x40);
wait();
for(i=0;i<=63;i++)
{lcdwritedata(nan[i%16]);
wait();
}
lcdwritecom(0xb8+j*4+1); /*nan down*/
wait();
lcdwritecom(0x40);
wait();
for(i=0;i<=63;i++)
{lcdwritedata(nan[16+i%16]);
wait();
}

lcdwritecom(0xb8+j*4+2); /*jin up*/
wait();
lcdwritecom(0x40);
wait();
for(i=0;i<=63;i++)
{lcdwritedata(jin[i%16]);
wait();
}
lcdwritecom(0xb8+j*4+3); /*jin down*/
wait();
lcdwritecom(0x40);
wait();
for(i=0;i<=63;i++)
{lcdwritedata(jin[16+i%16]);
wait();
}
}
/*
lcdselect(1);
lcdwritecom(0x3f);
wait();
lcdselect(2);
lcdwritecom(0x3f);
wait();*/
delay(50000);
while(1)
{
lcdselect(1);
lcdwritecom(0xc0+i);
wait();
lcdselect(2);
lcdwritecom(0xc0+63-i);
wait();
delay(5000);
i=i+2;
if(i>=64) i=0;
}
}
--




关键词: 89c2051     接口     unsigned     lcdse    

共1条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]