#include<reg52.h>
sbit EN=P0^3;
sbit RS=P0^1;
sbit RW=P0^2;
sbit CS1=P0^4;
sbit CS2=P0^5;
sbit RST=P0^6;
void Delay (unsigned int z)
{
unsigned int i,j;
for(i=z;i>0;i--)
for(j=2;j>0;j--);
}
void WriteCode(unsigned char com)
{
Delay(1);
RS=0;
RW=0;
P2=com;
EN=1;
EN=0;
Delay(1);
}
void WriteData(unsigned char dat)
{
Delay(1);
RS=1;
RW=0;
P2=dat;
EN=1;
EN=0;
Delay(1);
}
unsigned char ReadData()
{
unsigned char save;
Delay(1);
RS=1;
RW=1;
EN=1;
save=P2;
EN=0;
return(save);
Delay(1);
}
void LcdInitialize()
{
Delay(1);
CS1=0; CS2=0;
WriteCode(0x3e);
WriteCode(0xb8);
WriteCode(0xc0);
WriteCode(0x40);
WriteCode(0x3f);
}
void SetXy(unsigned char x,unsigned char y)
{
WriteCode(0xb8+x);
WriteCode(0x40+y);
Delay(1);
}
void LcdClear()
{
unsigned char i,j;
CS1=0;CS2=0;
for(i=0;i<8;i++)
{
SetXy(i,0);
for(j=0;j<64;j++)
WriteData(0x00);
}
}
void DrawPoint(unsigned char x,unsigned char y,unsigned char dat)
{
unsigned char he;
SetXy(x,y);
he=ReadData();
he=ReadData();
SetXy(x,y);
WriteData(dat+he);
}
void DrawHanzi(unsigned char x,unsigned char y,unsigned char code *dat)
{
unsigned char i=0,j=0;
for(i=0;i<2;i++)
{
SetXy(x+i,y);
for(j=0;j<16;j++)
WriteData(dat[16*i+j]);
}
}
unsigned char code a[2][32]=
{
{
0xFF,0xFF,0x03,0xFB,0x9B,0xAB,0xBB,0x3A,0x81,0xBB,0xBB,0xAB,0x9B,0xBB,0xBB,0xFF,
0x7F,0x9F,0xE0,0xBF,0xDF,0x67,0x79,0xBE,0xB8,0xD6,0xEE,0xD6,0xBA,0x7C,0x7F,0xFF
},
{
0xBF,0xC3,0xEF,0x00,0xEF,0xEF,0xDF,0xEF,0x70,0x87,0xF7,0x07,0xF7,0x07,0xFF,0xFF,
0xFD,0xF9,0xFD,0x00,0xFE,0xFE,0xFB,0xBD,0xDE,0xE7,0xB9,0x7E,0xBF,0xC0,0xFF,0xFF
},
};
void main()
{
unsigned char i,j;
LcdInitialize();
LcdClear();
for(i=0;i<4;i++){DrawHanzi(2*i,16*j,a[0]);DrawHanzi(2*i,16*j+16,a[1]);}
for(i=0;i<4;i++){DrawHanzi(2*i,16*j+32,a[0]);DrawHanzi(2*i,16*j+16+32,a[1]);}
while(1);
}
|