My 12864 study notes_3---Control 12864 LCD display curve

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
3. LCD display curve

    In order to use 12864 to display the curve, you must first be able to freely control the brightness of any pixel in 12864 without affecting the status of other adjacent points.

Because when writing to a 12874 LCD, the smallest unit of written data is also a hexadecimal number, which is 8 bits and can control 8 pixels. Therefore, when operating the LCD, the minimum number of pixels that can be controlled at one time is 8.

Therefore, if you want to control the on and off of a certain point in the liquid crystal, you must find a way to make the writing of the data of this point realized by writing this hexadecimal number, and the basic principle is that it cannot affect the state of the other 7 bits of data. Therefore, if you want to control a certain pixel point, you must first know the current data of the other 7 bits around this pixel point in the liquid crystal, and then add the data of this point bit by bit to this data, without affecting the state of the other 7 bits of data.

There are two ways to know the currently displayed data: 1. Implement the LCD read operation and read the corresponding data in GDRAM; 2. Artificially construct a virtual cache register (actually a two-dimensional array) to save the last written data of the LCD GDRAM, that is, the data currently displayed by the LCD. Because it saves 8-bit hexadecimal numbers, 128*64 pixels only need a 16*64 array to store them. Write the virtual register at the same time as writing 12864, and before writing, read the value of the virtual register and the point position, so as not to overwrite the previous point.

 

Because the IO pins of msp430g2553 are limited, my 12864 is connected in series. If it is connected in parallel,  the LCD reading operation is not difficult to implement. Now the serial one, although more complicated, is very similar to the serial reading operation. The main thing is to understand the timing, and then write it strictly according to the timing. I have realized the LCD reading and writing operations. The functions of the read and write operations are as follows, and the comments are also quite detailed:

//12864 serial connection  writes data, write command function     is programmed according to the timing in the manual

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*****************8The   first 5 high-level synchronization codes

  {

  LCD_SCLK1;

  LCD_SCLK0;

  }

  LCD_SID0;        //wr=0   write operation

 

  LCD_SCLK1;       //en=1   for one clock

  LCD_SCLK0;       //en=0

  if(dat_comm)

  LCD_SID1;   //RS=1   write data

  else

  LCD_SID0;    //RS=0   write instruction

 

 

  LCD_SCLK1;  //A clock

  LCD_SCLK0;

 

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

 

  LCD_SCLK1;   //A clock

  LCD_SCLK0;

 

   for(j=0;j<2;j++)//

{

  uchar  i,j;

  uchar  a=0; //a stores the read data

      delay_us(50);

       LCD_SCLK0;  //en=0;

       LCD_SID1;   //wr=1

  for(i=0;i<5;i++)  //Data timing*****************8The  first 5 high-level synchronization codes

  {

  LCD_SCLK1;

  LCD_SCLK0;

  }

  LCD_SID1;        //wr=1  read operation

 

  LCD_SCLK1;       //en=1   for one clock

  LCD_SCLK0;       //en=0

 

  LCD_SID1;    //RS=1   read data

 

 

 

  LCD_SCLK1;  //A clock

  LCD_SCLK0;

 

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

 

  LCD_SCLK1;   //A clock

  LCD_SCLK0;

 

   for(j=0;j<2;j++)/

void  Draw_Point(unsigned  char  x, unsigned  char  y0, unsigned  char  color)

{

   unsigned  char  row,collum,cbite;

   unsigned  char  tempH,tempL;

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

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

 

 

//    uchar  y_Byte,y_bit,x_Byte,x_bit;

//    y_Byte  y/32;  //0: upper half of the screen 1: lower half of the screen

//    y_bit  y2;  //y  row number

//    x_Byte  x/16;  //x  column number

//    x_bit  x;  //x  bit

//    Write_Cmd(0x34);  //Open the extended instruction set

//    Write_Cmd(0x36);  //Open drawing display

//    Write_Cmd(0x80+31-y_bit);

//    Write_Cmd(0x80+x_Byte+(1-y_Byte)*8);

 

   collum=x>>4;    //Shifting right by 4 bits   is equivalent to dividing by 16 and rounding up, and the result is the column number of the large column where x is located

   cbite=x&0x0f;

 

   if(y0<32)

    row=y0;

   else

   {

   row=y0-32;

   collum+=8;

}

 

   wr_lcd(comm,0x80+row);    //Set the vertical position first

   wr_lcd(comm,0x80+collum);   //Reset the horizontal position

//The above two sentences specify the address. The following will read the current data first, and then write the new data

 rd_lcd();    //The read operation   must first execute an empty read instruction

 tempH=rd_lcd();   //Two read operations

 tempL=rd_lcd();

 

 //Because each read or write operation is not performed, the address pointer AC will be incremented by 1, so the address needs to be re-entered below.   The vertical address is entered first, and then the horizontal address is entered.

 wr_lcd(comm,0x80+row);

 wr_lcd(comm,0x80+collum);

 if  (color)    //color=1, light up; color=0, erase

 {

 if(cbite<8)

 {

 tempH|=(1<<(7-cbite));

 //tempL=(1<<(7-cbite));

 }

 else

 {

 //tempH=(1<<(15-cbite));

 tempL|=(1<<(15-cbite));

 }

 }

 else

 {

    if(cbite<8)

 {

 tempH&=~(1<<(7-cbite));

 //tempL=(1<<(7-cbite));

 }

 else

 {

 //tempH=(1<<(15-cbite));

 tempL&=~(1<<(15-cbite));

 }

 }

 wr_lcd(dat,tempH);   //Write data

 wr_lcd(dat,tempL);

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

}

 

 

Using the above function, you can control the brightness of any pixel. With the above function, you can control the LCD to display any curve or image of any shape. Here is a function to display the coordinate axis. The function displays the X, Y coordinate axis on the LCD screen and divides the coordinate axis into segments of 10 points. The function is as follows:

 

To be continued...

Reference address:My 12864 study notes_3---Control 12864 LCD display curve

Previous article:My 12864 study notes_4---A few additional explanations
Next article:12864 LCD In-depth Study Notes_2——Based on msp430g2553

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号