12864 LCD in-depth study notes_1

Publisher:德州小孙Latest update time:2015-08-18 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
Created on: 2012-8-30

      Author: zhang bin

 

Study Notes

for 12864

redesigned by zhang bin

2012-08-30

versions:12_08_01

 

This is my study note on 12864. The 12864 LCD has comprehensive functions and is easy to use, and can meet the needs of general research and engineering applications.

Below I will talk about my experience in learning it in several aspects. I will try to introduce it as comprehensively as possible, and will mainly explain some special applications and some places that I think need special attention in more detail. For those more fixed and commonly used aspects, I will be brief.

Whether it is serial mode or parallel mode, the basic operations such as writing instructions, writing data, and reading operations on LCD are relatively fixed and basic. I think it is enough to understand and be able to port it on different processors. There is no need to write it out by yourself according to the manual timing diagram. Because someone has already written it and it works stably, we just need to learn to apply it on its basis. Now is the era of knowledge explosion, knowledge and information are expanding rapidly. We must learn to use existing results, and then carry out research on development and application on this basis. We don’t have to start from the bottom and do something that others have done very maturely again. This is not only inefficient, but also our energy is not allowed.

Okay, without further ado, I’ll start the introduction. Of course, I’ll also introduce the basic things.

The programs involved below are for msp430g2553. I have already adjusted them and can be used directly.

 

1. Introduction of 12864

1. The LCD module is a 128×64  dot Chinese graphic LCD module that can display Chinese characters and graphics. It has a built-in GB2312  simplified Chinese character library (16X16  dot), 128  characters (8X16  dot) and 64X256  dot display RAM (GDRAM). It can  be directly interfaced with the CPU and provides two interfaces to connect to the microprocessor: 8-bit parallel and serial connection. It has multiple functions: cursor display, screen shift, sleep mode, etc.

2. The commonly used 12864 LCDs all use the ST7920 controller.

    1) ST7920 provides three microprocessor control modes: 8-bit, 4-bit and serial. The 8-bit and serial control modes are commonly used in mainland China.

2) ST7920 can control the display of letters, numbers, Chinese fonts and custom pictures. It can be used to display graphics, demonstrate animations, draw curves, etc.

3) Character Display RAM  (DDRAM)

The character display RAM (DDRAM) of ST7920  can control up to 16 characters*4 lines, and the display range of LCD is 16 characters*2 lines.

It should be noted here that each row of ST7920 DDRAM can control 16 Chinese characters, and there are 4 rows in total. However, each row of LCD can only display 8 characters. In order to facilitate display observation, two rows of DDRAM are split into four rows during the LCD production process, and then displayed on the LCD, which means that only half of the DDRAM is used.

The coordinate addresses of the LCD display characters are as follows:

Chinese character display coordinates

Line1 80H 81H 82H 83H 84H 85H 86H 87H

Line2  90H  91H  92H  93H  94H  95H  96H  97H

Line3 88H 89H 8AH 8BH 8CH 8DH 8EH 8FH

Line4  98H  99H  9AH  9BH  9CH  9DH  9EH  9FH

It is not difficult to see from the above table that the first row and the third row are split from the same row in DDRAM, and similarly, the 2nd and  4th  rows are also split from the same row in DDRAM.

Knowing this, it is not difficult to understand that in the following program, when the line is changed, the address of the next line should be manually specified. For example, if the first line is displayed, I want to display the following data on the second line, so that it conforms to people's observation habits, then I have to manually switch the display address to the second line before changing the second line. Otherwise, after the first line is displayed, the address will automatically increase and will be displayed on the third line, which will be unnatural for us to observe. The program example will be involved below.

 

    4), Chinese character library ROM  (CGROM)

The built-in simplified Chinese font library is GB2312, which provides 8192 16*16 point Chinese fonts.

5), Half-width font ROM  (HCGROM)

Provides 126 16*8 point half-width letter and symbol fonts.

6) Graphics Display RAM  (GDRAM)

Provides 64*256-bit GDRAM

 

The RAM we commonly use is the one mentioned above. There are also some CGRAM  and IRAM that we don’t use often, so we will not introduce them here.

The DDRAM control described above displays Chinese characters. GDRAM controls the display of pictures. After power-on, DDRAM is turned on by default to control the LCD display. GDRAM is not turned on by default, and the data in it is random. If GDRAM is turned on at this time, the LCD will be controlled by both DDRAM and GDRAM. Since the data in GDRAM is random, garbled characters will be displayed. Therefore, the random data in GDRAM must be cleared before using it.

The function to clear GDRAM is as follows:

 

void  Clear_GDRAM(void)    // Clear the random data in GDRAM. Because the data in GDRAM is random after power-on, if you open the GDRAM display directly without clearing it, garbled characters will be displayed.

                        //So when using GDRAM locally to display graphics, you must first clear the random data. If GDRAM is used globally, that is, the entire LCD screen is set to display data, you can

                       //No need to clear, because the new data will overwrite the random data

{

    flying  i,j,k;

 

    wr_lcd(comm,0x34);         //Open the extended instruction set    operation GDRAM is an extended instruction set

0x80;

for(j 0;j 32;j++)

{

wr_lcd(comm,i++);

wr_lcd(comm,0x80);

   for(k 0;k 16;k++)

   {

   wr_lcd(dat,0x00);    //Writing a null character is equivalent to clearing

   }

}

0x80;

  for(j 0;j 32;j++)

{

  wr_lcd(comm,i++);

  wr_lcd(dat,0x88);

   for(k 0;k 16;k++)

   {

   wr_lcd(dat,0x00);

    }

}

  wr_lcd(comm,0x30);         //Return to the basic instruction set

}

 

   3. 12864 has two working modes

   1) Parallel mode and serial mode. Parallel mode is the commonly used 8-bit data line and 4-bit control line. Although this mode occupies more IO ports, it is easier to send and receive data to the LCD and the data transmission speed is faster. Therefore, this mode should be considered in some occasions where multiple pictures are displayed continuously, animations are demonstrated, or the real-time display is required. In the parallel mode, before writing data or commands to the LCD, the LCD busy flag  BF must be judged to make sure that the LCD display is not busy before the operation can be performed.

The command functions for reading and writing data of the parallel mode LCD are as follows:

 

void Write_Cmd(uchar cmd)

{

    float  lcdtemp  0;

 

    LCD_RS_L;

    LCD_RW_H;

    LCD_DataIn;     //Data input to microcontroller

    do                        // busy

    {

        LCD_EN_H;

        _NOP();

        lcdtemp LCD2MCU_Data;

        LCD_EN_L;

 

    }

    while(lcdtemp  0x80);   //Judge the busy flag    and wait for busy

 

    LCD_DataOut;    //Data output to LCD

    LCD_RW_L;

    MCU2LCD_Data  cmd;    //MCU inputs command to LCD

    LCD_EN_H;

    _NOP();

    LCD_EN_L;

}

 

void   Write_Data(uchar  dat)

{

    float  lcdtemp  0;

 

    LCD_RS_L;

    LCD_RW_H;

    LCD_DataIn;

    do                        // busy

    {

        LCD_EN_H;

        _NOP();

        lcdtemp LCD2MCU_Data;

        LCD_EN_L;

    }

    while(lcdtemp  0x80);      //Wait for busy

 

    LCD_DataOut;

    LCD_RS_H;

    LCD_RW_L;

 

    MCU2LCD_Data  dat;    //MCU inputs data to LCD

    LCD_EN_H;

    _NOP();

    LCD_EN_L;

}

 

   2) The serial mode uses only two wires, WR and   EN, to communicate with the microcontroller. This method can greatly reduce the overhead of the microcontroller's IO port and is suitable for microcontrollers with limited IO port resources (such as msp430g2553). However, this method is more troublesome to implement and the data transmission efficiency is not high. For general text and simple graphics, it is still possible to display. (It may be because the processing power of msp430g2553 is strong. I now use the serial connection method to display the following pictures. The display effect is very good, and there is no problem of slow data transmission speed).

Since I am using msp430g2553, I have always used serial control mode.

//The following focuses on the serial timing

//SCLK: Serial synchronous clock line. Each operation of a data bit requires an SCLK transition edge, and here the rising edge is valid. That is to say, every time SCLK changes from low level to high level, the LCD controller

//The controller reads or outputs the data on the SID.

//SID: serial data, each operation consists of three bytes of data. The first byte sends a command control word to the controller, telling the controller what operation to do next. If it is a write instruction, send 11111000

//(0xf8), if it is write data, send 11111010(0xfa), if it is read status, send 11111100(0xfc), if it is read data, send 11111110(0xfe).

//The high 4 bits of the second byte are the high 4 bits of the sent instruction or data, and the low 4 bits of the second byte are filled with 0.

//The high 4 bits of the third byte are the low 4 bits of the sent instruction or data, and the low 4 bits of the third byte are filled with 0

//You can observe the timing to understand the details

12864 LCD In-depth Study Notes_1——Based on msp430g2553

 

The function of data transmission is as follows:

//12864 serial connection write data, write command function     according to the timing in the manual programming
void wr_lcd(uchar dat_comm,uchar content)//
  //               data to be written
  uchar a,i,j;
      delay_us(50);
  a=content;
       LCD_SCLK0; //en=0;
       LCD_SID1;   //wr=1
  for(i=0;i<5;i++) //data timing **********************8   first 5 high-level synchronization codes
  {
  LCD_SCLK1;
  LCD_SCLK0;
  }
  LCD_SID0;        //wr=0   write operation

  LCD_SCLK1;       //en=1   to get a clock
  LCD_SCLK0;       //en=0
  if(dat_comm)
   LCD_SID1;   //RS=1   write data
  else
   LCD_SID0;    //RS=0   write instruction


  LCD_SCLK1; //Get a clock
  LCD_SCLK0;

  LCD_SID0;   //The last bit of the control word is 0

  LCD_SCLK1;   //Get a clock
  LCD_SCLK0;

   for(j=0;j<2;j++)//************Total 2*4 loops to write one byte of data, the first large loop writes the upper 4 bits, the second large loop writes the lower 4 bits
  {
    for(i=0;i<4;i++)
    {
      if(a&0x80)
           LCD_SID1;
        else
           LCD_SID0;
      a=a<<1;
      LCD_SCLK1;
      LCD_SCLK0;
    }
      LCD_SID0;
   for(i=0;i<4;i++)   //4 clock pulses come from the clock
    {
       LCD_SCLK1;
       LCD_SCLK0;
    }
  }
}

 [page]

void  Draw_TX(volat  Memory,volat  Hddr,const  volat  dp)

{

    flying  j;

    uchar  k=0;

 

   //  wr_lcd(comm,0x01);   //Clear screen, can only clear DDRAM

    wr_lcd(comm,0x34);   //Use the extended instruction set, turn off the drawing display    and turn on the extended instruction set

    for(j=0;j<16;j++)

    {

     wr_lcd(comm,Yaddr++);       //Y地址

     wr_lcd(comm,Xaddr);     //X address

     wr_lcd(dat,dp[k++]);      //Write data

     wr_lcd(dat,dp[k++]);

    }

    wr_lcd(comm,0x36);   //Open drawing display

  //   wr_lcd(comm,0x30);   //Return to basic instruction set mode

}

 

 

5. The function to write an image to the full screen of the LCD is as follows:

 

void  Draw_PM(const  uchar  *ptr)     //Display graphics on the entire screen

{

    flying  i,j,k;

 

    wr_lcd(comm,0x34);         //Open the extended instruction set

0x80;

for(j 0;j 32;j++)

{

wr_lcd(comm,i++);

wr_lcd(comm,0x80);

   for(k 0;k 16;k++)

   {

   wr_lcd(dat,*ptr++);       //Write 32*16 data first

   }

}

0x80;

  for(j 0;j 32;j++)

{

  wr_lcd(comm,i++);

  wr_lcd(comm,0x88);

   for(k 0;k 16;k++)

   {

   wr_lcd(dat,*ptr++);       //Write 32*16 data again

    }

}

  wr_lcd(comm,0x36);         //Open drawing display

  wr_lcd(comm,0x30);         //Return to the basic instruction set

}

 

6. Below I will paste a function for testing the LCD function, which uses many functions of the LCD. You can observe the implementation phenomenon and the comments are also detailed. The code is as follows:

 

#include  "msp430g2553.h"

#include  "ser_12864.h"

 

 

void main( void )

{

    uint i;

    uchar  laba[]=      //16*16 size graphic data

    0x00,0x00,0x00,0xC0,0x01,0x48,0x02,0x44,0x04,0x52,0xF8,0x49,0x88,0x49,0x88,0x49,

      0x88,0x49,0x88,0x49,0xF8,0x49,0x04,0x52,0x02,0x44,0x01,0x48,0x00,0xC0,0x00,0x00};

 

    WDTCTL WDTPW WDTHOLD;    //关狗

 

    BCSCTL1  CALBC1_12MHZ;   //Set the CPU clock DCO frequency to 12MHz

    DCOCTL CALDCO_12MHZ;

    P2DIR  |=BIT5+BIT4;       //Two lines of LCD

 

    init_lcd();                  //Initialize LCD

 

 

    //The following is the characters in the LCD character table

    wr_lcd(comm,0x80);             //Write the display address of the first line     Write command 0x80

    for(i  0;  16;  i++)         // Each line can display 16 characters

     wr_lcd(dat,0x00  i);  //Display the character write data     corresponding to 0x00~0x0f  

 

    wr_lcd(comm,0x90);             //Write the display address of the second line.  Because the 13th and 24th  lines    of 12864  are cut from two lines of the controller ST7920, for the sake of convenience

    //Here you need to manually switch the address to the second line. Otherwise, after displaying the first line, the LCD will automatically switch to the third line.

    for(i 0; 16; i++)

     wr_lcd(dat,0x10  i);      //Display the characters corresponding to 0x10~0x1f

 

    wr_lcd(comm,0x88);             //Write the display address of the third line

    for(i 0; 16; i++)

     wr_lcd(dat,0x20  i);      //Display the characters corresponding to 0x20~0x2f

 

    wr_lcd(comm,0x98);             //Write the display address of the fourth line

    for(i 0; 16; i++)

     wr_lcd(dat,0x30  i);      //Display the characters corresponding to 0x30~0x3f

 

//      delay_ms(1000);    // Delay 1s and observe the effect

 

 

 

//When debugging, you can set a breakpoint here, execute the following instructions step by step, and observe the results

    //When displaying, DDAM and GDRAM are displayed at the same time, that is, their display results are superimposed on each other

    

    //1. Set DDRAM address command

     wr_lcd(comm,0x90);             //Set the DDRAM address, because the DDRAM address has overflowed at this time

    //2. Display status command

     wr_lcd(comm,0x08);             //Overall display off, cursor off, cursor position off

     wr_lcd(comm,0x0c);             //Overall display on, cursor off, cursor position off

     wr_lcd(comm,0x0e);             //Overall display on, cursor on, cursor position off

     wr_lcd(comm,0x0f);             //Overall display on, cursor on, cursor position on,   cursor flashing

    //3. Address return

     wr_lcd(comm,0x02);             //Address return, cursor returns to origin

 

     wr_lcd(comm,0x84);             //Set the DDRAM address to 0x88, and the cursor will flash here

    //4. Click to set the command

    // (The following four commands control the movement of the cursor and the entire screen after writing characters)

     wr_lcd(comm,0x07);             //Move the cursor right and the whole display left

     wr_lcd(comm,0x20);            //Write two spaces

     wr_lcd(dat,0x20);

 

    wr_lcd(comm,0x05);             //Move the cursor left and the whole display right

    wr_lcd(dat,0x20);            //Write two spaces

    wr_lcd(dat,0x20);

 

    wr_lcd(comm,0x06);             //Move the cursor to the right but the whole display does not move

    wr_lcd(dat,0x20);            //Write two spaces

    wr_lcd(dat,0x20);

 

    wr_lcd(comm,0x04);             //Move the cursor to the left but the whole display does not move

    wr_lcd(dat,0x20);            //Write two spaces

    wr_lcd(dat,0x20);

    //5. Cursor and display shift control

    // (The following four commands do not need to write display data, directly control the movement of the cursor and the entire screen display. The command executed above writes a space to achieve the movement of the cursor and the entire screen)

    wr_lcd(comm,0x10);             //Move cursor left

    wr_lcd(comm,0x14);             //Move cursor right

    wr_lcd(comm,0x18);             //The whole display moves left, and the cursor follows

    wr_lcd(comm,0x1c);             //The whole display moves right, and the cursor follows

 

    wr_lcd(comm,0x0c);             //Close the cursor

 

    //6. Enter the extended function mode command

    wr_lcd(comm,0x34);             //Open extended function mode, close drawing display

    //7. Reverse command

    wr_lcd(comm,0x04);             //Highlight lines 1 and 3 at the same time

    wr_lcd(comm,0x04);             //Highlight lines 1 and 3 again, which is equivalent to turning off the highlight of lines 1 and 3

    wr_lcd(comm,0x05);             //Highlight lines 2 and 4 at the same time

    wr_lcd(comm,0x05);             //Highlight lines 2 and 4 again, which is equivalent to turning off the highlight of lines 2 and 4

    //8. Sleep mode command

    wr_lcd(comm,0x08);             //Enter sleep mode.   The LCD controller ST7920 is turned off to reduce power consumption. But the backlight is still on.

    wr_lcd(comm,0x0c);             //Exit sleep mode    and continue displaying

    //9. Standby mode command

    wr_lcd(comm,0x01);  // No display is displayed            in standby mode  . The LCD is ready to receive data or commands. 

    //10. Turn on GDRAM display                         // Turn on GDRAM display, the LCD's GDRAM and DDRAM will control the LCD display at the same time

    wr_lcd(comm,0x36);             //Open the extended function mode and turn on the drawing display.   Since the data in the GDRAM is random after power-on, if it is not cleared before display, garbled characters will be displayed.

    Draw_TX(0x80,0x84,laba);     //Display a 16*16 size graphic   to display the image defined above, which is a small speaker

    Clear_GDRAM();               // Clear the random value in GDRAM after power-on reset. At this time, GDRAM displays empty characters, but there is still data in DDRAM, so the data in DDRAM will be displayed at this time

    Draw_TX(0x80,0x84,laba);     //Redisplay the graphics in 16*16 size

   //11. Turn off GDRAM display

    wr_lcd(comm,0x34);             //Open the extended function mode, close the drawing display    to display the data in DDRAM

    //12. Set the basic instruction set

    wr_lcd(comm,0x30);               //Return to the basic instruction set

    //13. Clear display command

    wr_lcd(comm,0x01);             //Clearing the screen   can only clear DDRAM.   At this time, the LCD will not display anything.

 

 

     //The following is the characters in the LCD character table

     wr_lcd(comm,0x80);             //Write the display address of the first line

    for(i 0; 16; i++)

     wr_lcd(dat,0x40  i);      //Display the characters corresponding to 0x40~0x4f

 

    wr_lcd(comm,0x90);             //Write the display address of the second line

    for(i 0; 16; i++)

     wr_lcd(dat,0x50  i);      //Display the characters corresponding to 0x50~0x5f

 

    wr_lcd(comm,0x88);             //Write the display address of the third line

    for(i 0; 16; i++)

     wr_lcd(dat,0x60  i);      //Display the characters corresponding to 0x60~0x6f

 

    wr_lcd(comm,0x98);             //Write the display address of the second line

    for(i 0; 16; i++)

     wr_lcd(dat,0x70  i);      //Display the characters corresponding to 0x70~0x7f

 

    LPM4;

}

Reference address:12864 LCD in-depth study notes_1

Previous article:12864 LCD In-depth Study Notes_2——Based on msp430g2553
Next article:Summary of electrical design work - MSP430G2553 study notes - 3

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号