Principle and example program of 12864 lattice LCD module (HJ12864M-1)

Source: Internet
Author: User
Tags xms xpage

The 12864 dot matrix LCD module (LCM) is a 128*64-row array consisting of 128*64 LCD display points. Each display point corresponds to a binary number. 1 indicates bright, and 0 indicates extinct. The ram that stores the dot matrix information is called the display data storage. To display a graphic or Chinese character, you need to write the corresponding dot matrix information to the corresponding storage unit. The dot matrix information of graphics or Chinese characters is designed by yourself. The key to the problem is the relationship between the position (row and column) of the display point on the LCD screen and its address in the memory.

 

The driving circuit of most LCD modules consists of one row drive and two column drives. Therefore, the 12864 LCD screen is actually spliced by two independent 64*64 LCD screens, each half screen has a 512*8 bits display data Ram. The left and right half screens drive circuit and memory are selected by the chip selection signal CS1 and CS2. (To simplify the User Design, a few manufacturers add decoding circuits in the module, making the 128*64 LCD screen a full screen, requiring only one chip signal .)

 

The position of the display point on the 64*64 LCD screen consists of line, 0 ~ 63) and column number (column, 0 ~ 63) OK. 512*8 the address of a storage unit in BITs Ram is from the page address (xpage, 0 ~ 7) and column address (yaddress, 0 ~ 63) OK. Each storage unit stores the display information of 8 LCD points.

 

In order to make the correspondence between the location information of the LCD point and the storage address more intuitive, 64*64 LCD screens are divided into eight display blocks from top to bottom 8, each part contains 8 rows and 64 columns of lattice. The eight lines of dot matrix information in each column constitute an 8 bits binary number, which is stored in a storage unit. (Note: The relationship between the binary high/low valid bits and the row number varies with sellers.) a ram zone that stores a display block is called a storage page. That is, the dot matrix information of 64*64 LCD screens is stored in 8 storage pages, with 64 bytes per page. Each byte stores a column (8 rows) of dot matrix information. Therefore, the storage unit address includes the page address (xpage, 0 ~ 7) and column address (yaddress, 0 ~ 63 ).

 

For example, the LCD point at the position (20, 30) of the 128*64 screen is effective for CS1 because the column address 30 is smaller than 64 and the point is in the 29th column of the left half screen; the row address 20 divided by 8 is rounded to 2, and the remaining 4 is obtained. The page address in Ram is 2, and the serial number in the byte is 4. Therefore, the binary data is 00010000 (or 00001000, the order of high and low depends on the manufacturer). When xpage = 2 is written, the liquid crystal points on (20, 30) are switched on in the storage unit of yaddress = 29.

//// Lcd12864 LCD screen test program (passed )//////
////// LCD model: HJ12864M-1 //////////
///////////////////////////////////////

# Include <reg52.h>
# Define uchar unsigned char
# Define uint unsigned int

// 8-Bit Data Access IO port
# Define part P0 // P0 connects to an 8-bit data line
// Control the data end
Sbit LCD _rs = P2 ^ 5; // defines the 12864 LCD Rs end, register selection signal H: data register L: instruction register
Sbit LCD _rw = P2 ^ 6; // defines the 12864 LCD RW End, read/write signal H: Read L: Write
Sbit LCD _en = P2 ^ 7; // defines the 12864 LCD lcden end. The chip selection signal is triggered along the descent and the data is locked.
//
Sbit LCD _psb = P3 ^ 2; // defines the 12864 LCD PSB end, H: Parallel L: Serial
Sbit LCD _rst = P3 ^ 4; // defines the 12864 LCD rst end, H: not reset L: reset
Uchar code dis1 [] = {"Moonlight in front of bed "};
Uchar code dis2 [] = {"suspected ground cream "};
Uchar code dis3 [] = {"Looking forward to the bright moon "};
Uchar code dis4 [] = {"My Hometown "};
// ==============================================
// Millisecond latency Function
Void delay (uint XMS)
{
Uint I, J;
For (j = 0; I <XMS; j ++)
For (I = 0; I <110; I ++ );
}
// ==============================================
// LCD busy Detection Function
Bit LCD _busy ()
{
Bit result;
LCD _rs = 0;
LCD _rw = 1;
LCD _en = 1;
Result = (BIT) (Part & 0x80 );
LCD _en = 0;
Return result;
}
// ==============================================
// LCD write command function
Void LCD _write_cmd (uchar Com)
{
While (LCD _busy ());
LCD _rs = 0; // select the instruction register
LCD _rw = 0; // write
LCD _en = 0;
Part = com; // The command value is assigned to the P0 port.
Delay (5 );
LCD _en = 1;
Delay (5 );
LCD _en = 0;
}
// ==============================================
// A character data function written by the LCD
Void LCD _write_dat (uchar date)
{
While (LCD _busy ());
LCD _rs = 1; // select a data register
LCD _rw = 0; // write
LCD _en = 0;
P0 = date; // the data value is assigned to the P0 port.
Delay (5 );
LCD _en = 1;
Delay (5 );
LCD _en = 0;
}
// ==============================================
// LCD writes a string Function
Void LCD _write_string (uchar * Str)
{
While (* Str! = '\ 0') // not completed
{
LCD _write_dat (* STR ++ );
Delay (5 );
}
}
// ==============================================
// LCD position Function
Void LCD _pos (uchar X, uchar y) // It is displayed at the Y position of row X.
{
Uchar Pos;
If (x = 1) // The first line
{X = 0x80 ;}
Else if (x = 2) // The second row
{X = 0x90 ;}
Else if (x = 3) // the third row
{X = 0x88 ;}
Else if (x = 4) // The fourth row
{X = 0x98 ;}
Pos = x + Y-1; // The first address is 0x80
LCD _write_cmd (POS );
}
// ==============================================
// LCD initialization Function
Void LCD _init ()
{
LCD _psb = 1; // Parallel Mode
LCD _rst = 1; // do not reset
LCD _write_cmd (0x30 );
Delay (5 );
LCD _write_cmd (0x0c); // The cursor is not displayed.
Delay (5 );
LCD _write_cmd (0x06); // after writing a character, the address pointer automatically adds 1
Delay (5 );
LCD _write_cmd (0x01); // clear the screen
Delay (5 );
}
// ==============================================
// Main Function
Void main ()
{
// Uchar I;
LCD _init ();
While (1)
{
LCD _pos (1, 1 );
// LCD _write_string (dis1 );
LCD _write_string ("Moonlight in front of bed ");
Delay (5 );
LCD _pos (2, 1 );
// LCD _write_string (dis2 );
LCD _write_string ("suspected ground cream ");
Delay (5 );
LCD _pos (3, 1 );
// LCD _write_string (dis3 );
LCD _write_string ("Looking forward to the Moon ");
Delay (5 );
LCD _pos (4, 1 );
// LCD _write_string (dis4 );
LCD _write_string ("shousi hometown ");
Delay (500 );
}
}

 


 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.