#include <regx52.h>
#define DataPort P2
sbit Wr=P1^0;
sbit Rd=P1^1;
sbit CD=P1^2;
sbit CS=P1^3;
sbit RST=P1^4;
//unsigned char
void t(unsigned char para)
{for(;para;para--);}
void delay(unsigned int para)
{
unsigned int wdtime=0xffff;
for(;para;para--)
for(;wdtime;wdtime--);
}
void InstruWrite(unsigned char param)
{ RST=1;CS=1;Wr=1;Rd=1;CD=1;
CS=0;Wr=1;Rd=1;CD=1;
Wr=0;//CD=1;
t(5);
DataPort=param;
t(6);
CS=0;Wr=1;CD=1;
RST=1;CS=1;Wr=1;Rd=1;CD=1;
}
void DataWrite(unsigned char param)
{ RST=1;CS=1;Wr=1;Rd=1;CD=1;
CS=0;Wr=1;Rd=1;CD=0;
Wr=0;//CD=0;
t(5);
DataPort=param;
t(6);
CS=0;Wr=1;CD=1;
RST=1;CS=1;Wr=1;Rd=1;CD=1;
}
void AutoWrite(void)
{
InstruWrite(0xb0);
}
void AutoEnd(void)
{
InstruWrite(0xb2);
}
void TextHomeSet(unsigned char paraH,unsigned char paraL)
{
DataWrite(paraL); DataWrite(paraH);
InstruWrite(0x40);
}
void TextAreaSet(unsigned char columns)
{
DataWrite(columns);DataWrite(0x00);
InstruWrite(0x41);
}
void GraphicHomeSet(unsigned char paraH,unsigned char paraL)
{
DataWrite(paraL);DataWrite(paraH);
InstruWrite(0x42);
}
void GraphicAreaSet(unsigned char columns)
{
DataWrite(columns);DataWrite(0x00);
InstruWrite(0x43);
}
/*
void CursorSet(unsigned char para)
{
InstruWrite(para);
}
*/
void AddressSet(unsigned char paraH,unsigned char paraL)
{
DataWrite(paraL);
DataWrite(paraH);
InstruWrite(0x24);
}
void ModeSet(unsigned char para)
{
InstruWrite(para);
}
void InitLcd(void)
{
TextHomeSet(0x00,0x00);
TextAreaSet(22);
GraphicHomeSet(0x00,0xb0);
GraphicAreaSet(22);
ModeSet(0x80);
}
/*
void Printf(unsigned char position,unsigned char leng,unsigned char ptr)
{
InstruWrite(0x97);
AddressSet(0x00,position);
InstruWrite(0xa7);
AutoWrite();
for(;leng;leng--)
{ DataWrite(ptr++);
if(ptr>0x80)ptr=0x00;
}
AutoEnd();
}
*/
void Character(void)
{ unsigned char x,y,d=0x00;
InstruWrite(0x97); //text mode
AddressSet(0x00,0x00);
InstruWrite(0xa7);
AutoWrite();
for(x=0x00;x<22;x++)
{ for(y=0x00;y<16;y++)
{ DataWrite(d++);
if(d>0x80) d=0x00; //7f
}
}
AutoEnd();
}
void Bar(void)
{
unsigned char x,y;
InstruWrite(0x98);
AddressSet(0x00,0xb0);
AutoWrite();
for(y=0;y<64;y++)
for(x=0;x<11;x++)
{ if(y+6*x>=64) DataWrite(0xff);
else DataWrite(0x00);
DataWrite(0x00);
}
AutoEnd();
}
void ET(void)
{ unsigned char x,y;
InstruWrite(0x97);
AddressSet(0x00,0x00);
AutoWrite();
for(y=0;y<8;y++)
for(x=0;x<22;x++)
{ DataWrite(0x25);DataWrite(0x34); }
AutoEnd();
}
void Boundary(void)
{
unsigned char x,y;
InstruWrite(0x98);
AddressSet(0x00,0xb0);
AutoWrite();
for(y=0;y<64;y++)
for(x=0;x<22;x++)
{ if(y==0||y==63) DataWrite(0xff);
else
{ if(x==0) DataWrite(0x20);
else { if(x==21) DataWrite(0x10);
else DataWrite(0x00);
}
}
}
AutoEnd();
}
void CheckBoard(unsigned char paraA,unsigned char paraB)
{ unsigned char i,j;
InstruWrite(0x98); //graghic mode
AddressSet(0x00,0xb0);
AutoWrite();
for(i=0;i<32;i++)
{ for(j=0;j<22;j++) DataWrite(paraA);
for(j=0;j<22;j++) DataWrite(paraB);
}
AutoEnd();
}
void main(void)
{ unsigned char i=0;
InitLcd();
for(;1;i++,i%=8)
{
switch(i)
{ case 0: Character(); break;
case 1: Boundary(); break;
case 2: Bar(); break;
case 3: CheckBoard(0xff,0xff);break;
case 4: CheckBoard(0x00,0x00);break;
case 5: CheckBoard(0xaa,0x55);break;
case 6: CheckBoard(0x55,0xaa);break;
case 7: ET(); break;
}
delay(0x5fff);
//while(1);
}
}
|