# Include <reg52.h>
# Include <string. h>
# Include <intrins. h>
# Define uchar unsigned char
# Define uint unsigned int
# Define data 1
# Define command 0
Sbit cs = p1 ^ 0;
Sbit SID = p1 ^ 1;
Sbit sclk = p1 ^ 2;
Sbit PSB = p1 ^ 3;
Sbit rst = p1 ^ 4;
Void delayus (uint Z );
Void Init ();
Void writebyte (uchar flag, uchar content );
Void imgclr ();
Void imgdischar (uchar X, uchar y, uchar Code * imgchar );
Uchar code table [] = {
0 x, 0 x, 0 x, 0x18, 0x8c, 0x2e, 0xb2, 0x41, 0xc2, 0x40, 0 x, 0 x, 0 x, 0 x, 0x04,
0x10, 0x0c, 0 x, 0 x, 0 x, 0 x, 0 x, 0 x, 0 x, 0 x, 0 x, 0 x, 0 x, 0 x, 0 x, 0x00,
};
Void main ()
{
Uchar I;
Init ();
Imgclr ();
For (I = 0; I <16; I ++)
{
Imgdischar (I, 0, table );
Imgdischar (I, 16, table );
}
While (1 );
}
Void delayus (uint Z)
{
While (Z --);
}
Void Init ()
{
RST = 0;
Delayus (40 );
RST = 1;
Delayus (40 );
PSB = 0;
Delayus (8 );
Writebyte (command, 0x30 );
Delayus (8 );
Writebyte (command, 0x01 );
Delayus (8 );
Writebyte (command, 0x06 );
Delayus (8 );
Writebyte (command, 0x0c );
Delayus (8 );
}
Void writebyte (uchar flag, uchar content)
{
Char I, J, K;
Cs = 1;
Sclk = 0;
For (I = 0; I <5; I ++)
{
SID = 1;
Sclk = 1;
Sclk = 0;
}
SID = 0; // R/W = 0
Sclk = 1;
Sclk = 0;
If (FLAG)
SID = 1; // rs = 1, write data
Else
SID = 0; // rs = 0, write command
Sclk = 1;
Sclk = 0;
SID = 0;
Sclk = 1;
Sclk = 0;
For (k = 0; k <2; k ++)
{
For (j = 0; j <4; j ++)
{
SID = content & 0x80;
Sclk = 1;
Sclk = 0;
Content = content <1;
}
For (j = 0; j <4; j ++)
{
SID = 0;
Sclk = 1;
Sclk = 0;
}
}
Cs = 0;
}
Void imgclr ()
{
Uchar I, J;
For (I = 0; I <32; I ++)
{
For (j = 0; j <8; j ++)
{
Writebyte (command, 0x34); // disable the graphic display function first.
Writebyte (command, 0x80 + I); // sets the vertical coordinate
Writebyte (command, 0x80 + J); // sets the horizontal coordinate.
Writebyte (command, 0x30 );
Writebyte (data, 0x00); // put the data in high bytes
Writebyte (data, 0x00); // low data bytes
}
}
For (I = 32; I <64; I ++)
{
For (j = 0; j <8; j ++)
{
Writebyte (command, 0x34); // disable the graphic display function first.
Writebyte (command, 0x80 + i-32 );
Writebyte (command, 0x88 + J );
Writebyte (command, 0x30 );
Writebyte (data, 0x00 );
Writebyte (data, 0x00 );
}
}
Writebyte (command, 0x36); // display the image
}
// Function: draws a 16*16 dot matrix pattern at (x, y) using the plotting method. It can also be a character.
Void imgdischar (uchar X, uchar y, uchar Code * imgchar)
{
Uchar I;
Writebyte (command, 0x34 );
For (I = 0; I <16; I ++)
{
Writebyte (command, 0x80 + Y + I );
Writebyte (command, 0x80 + x );
Writebyte (data, imgchar [I * 2]);
Writebyte (data, imgchar [I * 2 + 1]);
}
Writebyte (command, 0x36 );
}