#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit rs=P3^0;
sbit rw=P3^1;
sbit e=P3^2;
uchar busy;
void delay(uchar z)
{
uchar x,y;
for(x=z; x>0;x--)
for(y=110;y>0;y--);
}
void delay100(uint n)
{
uchar i;
while(n--)
for(i=0;i<40;i++);
}
void check_busy(void)
{
rs = 0;
rw = 1; //读命令
do {
e = 1;
busy = P0; //busy=P0这条语句一定要在 "e=1 "的后面 谨记
delay(5);
e = 0;
}while(busy&0x80);
}
void write_com(uchar com)
{
check_busy();
rs=0;
rw=0;
e=1;
P0=com;
delay(5);
e=0;
delay(5);
}
void write_dat(uchar dat)
{
check_busy();
rs=1;
rw=0;
e=1;
P0=dat;
delay(5);
e=0;
delay(5);
}
uchar code pic[]={
/*-- 宽度x高度=128x64 --*/
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x80,0x00,0x00,0x1F,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x80,0x00,0x01,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x80,0x00,0x07,0xFC,0x7F,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x80,0x00,0x1F,0x00,0x03,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x80,0x00,0x7C,0x00,0x00,0x7C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x80,0x00,0xF0,0x00,0x00,0x1E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x80,0x01,0xC0,0x00,0x00,0x07,0x00,0x0E,0x1C,0x00,0x00,0x07,0x00,0x00,0x00,0x01,
0x80,0x03,0x80,0x00,0x00,0x03,0x90,0x0E,0x1C,0x00,0x10,0x3F,0x80,0x00,0x00,0x01,
0x80,0x07,0x40,0x00,0x00,0x01,0xC0,0x0C,0x1C,0x00,0x3F,0xFF,0x80,0x00,0x60,0x01,
0x80,0x0E,0x00,0x00,0x00,0x00,0xE0,0x0C,0x1C,0x60,0x3E,0x40,0x07,0xFF,0xE0,0xF1,
0x80,0x1C,0x00,0x00,0x00,0x00,0x70,0x0D,0xFF,0xE0,0x38,0x70,0x03,0xFF,0xE3,0xF1,
0x80,0x3A,0x00,0x00,0x00,0x00,0x38,0x3F,0x9C,0xE0,0x38,0x70,0x03,0x80,0x63,0xF1,
0x80,0x30,0x00,0x00,0x00,0x00,0x18,0x3F,0x9C,0xE0,0x30,0x60,0x03,0x80,0x03,0xF1,
0x80,0x70,0x00,0x00,0x00,0x00,0x1C,0x3F,0x9C,0xE0,0x30,0x60,0xC3,0x9E,0x03,0x71,
0x80,0xE0,0x00,0x00,0x00,0x00,0x0C,0x7D,0x9C,0xE0,0x70,0x61,0xE3,0xFF,0xC0,0x71,
0x80,0xC0,0x00,0x00,0x00,0x00,0x0E,0x7C,0x1C,0xF8,0x7F,0xFF,0xE7,0xFF,0xE0,0x71,
0x80,0xC0,0x0F,0x00,0x00,0xC0,0x06,0x6F,0xFF,0xF8,0x30,0x60,0x03,0xE1,0xE0,0x71,
0x81,0x80,0x1F,0x80,0x01,0xE0,0x07,0x0F,0xFF,0xF8,0x0E,0x6C,0x01,0xC0,0xF0,0x71,
0x81,0x80,0x1F,0x80,0x03,0xF0,0x03,0x0C,0x1E,0x00,0x0F,0x6F,0x00,0x00,0x70,0x71,
0x83,0x80,0x1F,0x80,0x03,0xF0,0x03,0x0C,0x3F,0x00,0x1E,0x67,0x81,0x00,0x70,0x71,
0x83,0x80,0x1F,0x80,0x03,0xF0,0x03,0x8C,0x3B,0x00,0x3C,0x63,0xC3,0x80,0xE0,0x71,
0x83,0x00,0x1F,0x80,0x03,0xF0,0x01,0x8C,0x73,0x80,0x78,0x61,0xC7,0xC1,0xE0,0x71,
0x83,0x00,0x1F,0x80,0x03,0xF0,0x01,0x8C,0xF1,0xC0,0xE0,0x61,0xC7,0xFF,0xC0,0x71,
0x83,0x00,0x1F,0x80,0x03,0xF0,0x01,0x8C,0xE1,0xF1,0xC3,0xE0,0xC0,0xFF,0x80,0xF1,
0x87,0x00,0x0F,0x00,0x01,0xE0,0x01,0x8F,0xC0,0xF9,0x83,0xE0,0x00,0x3E,0x00,0x01,
0x87,0x00,0x06,0x00,0x00,0xD0,0x01,0xCF,0x80,0x70,0x00,0xE0,0x00,0x00,0x00,0x01,
0x87,0x00,0x00,0x00,0x00,0x00,0x01,0xC8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x87,0x00,0x00,0x00,0x00,0x00,0x01,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x87,0x00,0x00,0x00,0x00,0x00,0x01,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x87,0x00,0x00,0x00,0x00,0x00,0x01,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x87,0x00,0x00,0x00,0x00,0x00,0x01,0xBF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xF1,
0x83,0x00,0x00,0x00,0x00,0x00,0x01,0xBF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xF1,
0x83,0x00,0x00,0x00,0x00,0x00,0x01,0xBF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xF1,
0x83,0x00,0x00,0x00,0x00,0x00,0x01,0xBF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xF1,
0x83,0x00,0x00,0x00,0x00,0x20,0x03,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x83,0x80,0x18,0x00,0x00,0x60,0x03,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x81,0x80,0x1C,0x00,0x00,0xF0,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x81,0x80,0x1E,0x00,0x01,0xE0,0x07,0x03,0xFC,0x03,0xFC,0x03,0xFC,0x07,0xF8,0x01,
0x81,0xC0,0x1F,0x00,0x03,0xE0,0x06,0x07,0xFF,0x07,0xFE,0x07,0xFE,0x0F,0xFE,0x01,
0x80,0xC0,0x0F,0x80,0x07,0xE0,0x0E,0x1F,0x8F,0x0F,0x9F,0x0F,0x9F,0x1F,0x1E,0x01,
0x80,0xE0,0x0F,0xC0,0x07,0xE0,0x0E,0x1E,0x07,0x1E,0x07,0x9E,0x07,0x9C,0x0F,0x01,
0x80,0x60,0x07,0xE0,0x0F,0xC0,0x1C,0x0E,0x03,0x1C,0x03,0x9C,0x03,0x9C,0x07,0x01,
0x80,0x70,0x03,0xF0,0x3F,0x80,0x18,0x00,0x07,0x1C,0x03,0x9C,0x03,0x9C,0x07,0x81,
0x80,0x38,0x01,0xFC,0xFF,0x00,0x38,0x00,0x0F,0x38,0x03,0xB8,0x03,0x9C,0x0F,0x81,
0x80,0x18,0x00,0xFF,0xFE,0x00,0x70,0x00,0x3E,0x38,0x01,0xB8,0x01,0x9F,0x1F,0x81,
0x80,0x0C,0x00,0x3F,0xF8,0x00,0xE0,0x00,0xFC,0x38,0x01,0xB8,0x01,0x8F,0xFF,0x81,
0x80,0x0E,0x00,0x07,0x80,0x01,0xC0,0x03,0xF0,0x3C,0x03,0xBC,0x03,0x87,0xFB,0x01,
0x80,0x07,0x00,0x00,0x00,0x03,0xC0,0x07,0xC0,0x1C,0x03,0x9C,0x03,0x80,0x07,0x01,
0x80,0x03,0xC0,0x00,0x00,0x07,0x00,0x07,0x80,0x1E,0x07,0x9E,0x07,0x98,0x0F,0x01,
0x80,0x01,0xE0,0x00,0x00,0x1E,0x00,0x0F,0x00,0x8F,0x0F,0x0F,0x0F,0x1E,0x1E,0x01,
0x80,0x00,0x78,0x00,0x00,0x7C,0x00,0x0F,0xFF,0x8F,0xFE,0x0F,0xFE,0x3F,0xFE,0x01,
0x80,0x00,0x3E,0x00,0x01,0xF8,0x00,0x1F,0xFF,0x83,0xFC,0x03,0xFC,0x0F,0xF8,0x01,
0x80,0x00,0x0F,0xE0,0x1F,0xE0,0x00,0x18,0x01,0x80,0xF0,0x00,0xF0,0x01,0xE0,0x01,
0x80,0x00,0x03,0xFF,0xFF,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x80,0x00,0x00,0x7F,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF
};
void lcdcls(void)
{
write_com(0x01);
write_com(0x34);
write_com(0x30);
}
void init(void)
{
write_com(0x30) ; //基本指令集
delay(10) ;
write_com(0x06) ; //光标右移
delay(10) ;
write_com(0x0c); //开显示 游标位置不显示 0x0e 则显示
delay(10) ;
write_com(0x01) ; //清屏
}
void lcd_dis(void)
{
uchar i,j,k;//先设垂直地址再设水平地址(连续写入两个字节的资料来完成垂直与水平的坐标地址)
uint x=0;
uchar LCD_X=0x80;
for(k=0;k<2;k++)
{
for(i=0;i<32;i++) //写垂直(Y轴)数据
{
write_com(0x80+i);
write_com(LCD_X);
for(j=0;j<16;j++) //写水平(X轴)数据
{
write_dat(pic[x]);
x++;
}
}
LCD_X=0x88;
}
}
void main(void)
{
init();
delay100(10);
while(1)
{
write_com(0x36); //设置显示图形方式
lcd_dis(); //图形方式下显示(我的电脑和我的文档)
delay100(5000);
lcdcls(); //清除当前显示
delay100(100);
}
}
你可以参考一下我的程序 还不懂的话 可以联系我 Q262439672 |