12864 LCD uses 16*16 lattice, 128 characters (8*16 lattice), and 64*256 lattice display RAM (gdram ). parallel or serial control mode is used with external CPU interface compaction.
The second line of the random number 0-9 displayed on 12864 shows www. csdn. Blog
The third line shows "Seeking for 07 blogs"
The fourth line shows "welcome"
Below is the basic code
# Include <reg52.h>
# Include <intrins. h>
# Include <stdlib. h>
# Define uchar unsigned char
# Define uint unsigned int
# Define LCD _data = P0;
Sbit rs = P3 ^ 5;
Sbit wR = P3 ^ 6;
Sbit en = P3 ^ 4;
Sbit RD = P3 ^ 7;
Sbit wela = P2 ^ 6;
Sbit Dula = P2 ^ 7;
Uchar display1 [10];
Uchar code display2 [] = {"www.csdn.blog.com "};
Uchar code display3 [] = {" 07 blog "};
Uchar code display4 [] = {"welcome "};
Void delay_1ms (uint X)
{
Uint I, J;
For (I = 0; I <X; I ++)
For (j = 0; j <100; j ++ );
}
Void write_cmd (uchar cmd)
{
Rs = 0;
WR = 0;
En = 0;
P0 = cmd;
Delay_1ms (5 );
En = 1;
Delay_1ms (5 );
En = 0;
}
Void write_data (uchar dat)
{
Rs = 1;
WR = 0;
En = 0;
P0 = dat;
Delay_1ms (5 );
En = 1;
Delay_1ms (5 );
En = 0;
}
Void LCD _pos (uchar X, uchar y)
{
Uchar Pos;
If (x = 0)
{X = 0x80 ;}
If (x = 1)
{
X = 0x90;
}
If (x = 2)
{
X = 0x88;
}
If (x = 3)
{
X = 0x98;
}
Pos = x + y;
Write_cmd (POS );
}
Void makerand () // Random Function
{
Uint ran;
Ran = rand ();
Display1 [0] = ran/10000 + 0x30;
Display1 [1] = ran % 10000/1000 + 0x30;
Display1 [2] = ran % 1000/100 + 0x30;
Display1 [3] = ran % 100/10 + 0x30;
Display1 [4] = ran % 10 + 0x30;
Ran = rand ();
Display1 [5] = ran/10000 + 0x30;
Display1 [6] = ran % 10000/1000 + 0x30;
Display1 [7] = ran % 1000/100 + 0x30;
Display1 [8] = ran % 100/10 + 0x30;
Display1 [9] = ran % 10 + 0x30;
}
Void LCD _init ()
{
RD = 1; // set the parallel port Mode
Write_cmd (0x30); // set the basic command action here
Delay_1ms (5 );
Write_cmd (0x0c); // display on, light cursor
Delay_1ms (5 );
Write_cmd (0x01); // clear the screen
Delay_1ms (5 );
}
Main ()
{
Uchar I;
Wela = 0;
Dula = 0;
Delay_1ms (5 );
LCD _init ();
LCD _pos (1, 0 );
I = 0;
While (display2 [I]! = '\ 0 ')
{
Write_data (display2 [I]);
I ++;
}
LCD _pos (2, 0 );
I = 0;
While (display3 [I]! = '\ 0 ')
{
Write_data (display3 [I]);
I ++;
}
LCD _pos (3, 0 );
I = 0;
While (display4 [I]! = '\ 0 ')
{
Write_data (display4 [I]);
I ++;
}
While (1)
{
LCD _pos (0, 0 );
Makerand ();
For (I = 0; I <10; I ++)
{
Write_data (display1 [I]);
}
}
}