Forum >LCD4884 single pixel control
ArduinoGeneral

LCD4884 single pixel control

userHead Lauren 2012-12-12 03:09:10 3433 Views1 Replies
A question from Radoslav

[quote]

Hi,

I'd just like to know if it is possible to control single pixels on the LCD shield, and how?
Thank you

[/quote]
2012-12-12 21:24:33 Hello, Radoslav!  :)It is not difficult to display a single pixel on the LCD4884. Before displaying a lovely pixel on the screen, we should know several conceptions.

Firstly, we should know how the LCD4884 maps the pixels. LCD4884 has a 48*84 pixels matrix LCD controller and this means the screen has 84 columns and 48 rows. However, the RAM of LCD4884 is divided into 6 banks of 84 bytes (6*8*84 bits). This means when you turn the values of columns and rows into X_Y address, we should do some operations. The range of X is 0 to 83 and it’s not very difficult, but we should set the Y address according to the 6 banks as LCD4884 maps the pixels in bytes (from LSB to MSB). The range of Y address is 0 to 5 and we can have a better understand of the mapping progress from the following image.
[img]https://www.dfrobot.com/forum/index.php?action=dlattach;topic=640.0;attach=396[/img]
For example, if we have a pixel which has the position (column 40, row 40) in the 48*84 pixels matrix, we can know that the pixel‘s X address is 39 and its Y address can be obtained by a operation like this: (40-1)/8=4. This means the pixel is in bank 5 and its Y address is 4.

Secondly, we should know two functions that can help us display the pixel on the screen. These two functions are in the LCD4884 Library.
1) LCD_set_XY (unsigned char X, unsigned char Y)
This function helps us set the position in which we want to display our pixel. The parameter X equals to the X address of the pixel and has a range from 0 to 83 while the parameter Y equals to the Y address of the pixel within the range of 0 to 5.
2) LCD_write_byte(unsigned char dat, unsigned char dat_type)
This function can do the job of lighting a pixel on the screen. When we use this function, we should set the dat_type parameter equals to 1 so that the current data byte is interpreted as a data rather than a command byte. The parameter dat is a byte so we should go on more steps to display the pixel.

Just look back to the example mentioned above. Now we want to display the pixel on the screen. We know that its X address is 39 and Y address is 4, but we want to find out its accurate position in bank 5. We can regard one bank has 8 positions and each position represents a bit in one byte. So the pixel we want to display is in the 8th position in the bank and we can set the number of the byte equals to 10000000 (Attention: 39%8=7 while the numbers set for the positions are from 0 to 7). When we call the function as LCD_write_byte(10000000,1), we can light a pixel in (column 40, row 40) on the screen.

Finally, we can write an Arduino program to display the single pixel on our screen.
The program is like this:

// We want to display a pixel in column 41,row 48
#include "LCD4884.h"

#define DELAY1 200
#define DELAY2 1000
#define DELAY3 5000

void setup()
{
  lcd.LCD_init(); // creates instance of LCD
}
void loop()

    unsigned Pos_X=40;  //the range of Pos_X is 0 to 83
    unsigned Pos_Y=47;  // the range of Pos_Y is 0 to 47
    unsigned line=0;
    unsigned offset=0;
    unsigned Pix=0;
   
    lcd.LCD_clear();        // blanks the display
    delay(DELAY1);
 
    line = Pos_Y/8;        // the value of the bank
    offset = Pos_Y%8;    //the position of the pixel in the bank
   
    for(int i=0; i<8;i++)  //which position in the bank should be lighten
  {
      if(i==offset)
      {
        bitWrite(Pix,i,1);
      }else{
        bitWrite(Pix,i,0);
      }
  }
    lcd.LCD_set_XY(Pos_X,line);   
    lcd.LCD_write_byte(Pix,1);
   
    delay(DELAY2);
}
userHeadPic leletkt