hlxldb

单片机控制诺基亚2600彩屏(四)

0
阅读(1935)

 

Step 3LCD Protocol - Initialization (Phillips PCF8833 Only!)

The LCD has many functions that are available by sending commands over the SPI interface.  The important ones are explained here and will allow you to get your LCD up and running.  A full set of commands is listed in the PCF8833 datasheet here:

http://www.nxp.com/acrobat_download2/datasheets/PCF8833_1.pdf

The 9th bit is the command flag.  If set to 0, the data byte is interpreted as a command.  If 1, the data byte is interpreted as data.  Data may be sent after issuing an appropriate command.

Before you can write to the LCD, it must be initialized.  First, the Reset line must be pulled low for around 100ms and then raised high again.  The Reset line must remain high during operation.  Then, a sequence of commands must be sent, in the following order:

SLEEPOUT (Hex 0x11) - Exits LCD sleep mode

BSTRON (Hex 0x03) - Turns on booster voltage

COLMOD (Hex 0x3A) - Sets pixel format to the following data byte
Data 0x03 - The pixel format 0x03 is 12 bits per pixel

MADCTL (Hex 0x36) - Sets several LCD params - [<Mirror Y>, <Mirror X>, <Vertical Write>, <Bottom to Top>, <BGR/RGB>, -, -, -]
Data 0xC0 - Flips display upside down (my LCD was mounted upside down), uses RGB color format

SETCON (Hex 0x25) - Set Contrast to following data byte
Data 0x40 - This contrast value works fairly well for my LCD, adjust if yours does not display well

DISPON (Hex 0x29) - Turns on display

 

 

Step 4LCD Protocol - Drawing (Phillips PCF8833 Only!)

Continuing with the protocol, once the LCD is initialized it is ready to draw.  Drawing works by first defining a region to draw and then streaming pixel data to fill that region.  It is confusing at first, but if done properly is more efficient than pixel-by-pixel drawing.  A region is simply a rectangular area on the screen.  We'll say it begins at point (X1,Y1) and ends at point (X2, Y2).  Once defined, the LCD controller will fill in pixels from left to right starting at (X1, Y1).  When it reaches the edge of the region, it will jump to the next line [in my example, (X1, Y1+1) ].  It does this until it reaches (X2, Y2) at which it stops accepting data.  If you only want to draw one pixel, you simply set (X1, Y1) and (X2, Y2) to the pixel you want to draw.  This defines the region as a single pixel.  Any data sent after the first pixel's worth of data is discarded.

To define a region, you must send these commands in the following order:

PASET (Hex 0x2B) - Page Address Set
Data Y1 - The starting Y position
Data Y2 - The ending Y position

CASET (Hex 0x2A) - Column Address Set
Data X1 - The starting X position
Data X2 - The ending X position

RAMWR (Hex 0x2C) - RAM Write - Start sending pixel data after this command

<Pixel Data> - Formatting described below

After the screen is ready to accept pixel data, you must send color data for each pixel in order.  In the default color mode (0x03, 12 bits per pixel) color data uses 12 bits.  This means that you can send 2 pixels worth of data for every 3 bytes.  If you are only sending one pixel, you only need to send 2 bytes.  The 2-pixels-per-3-bytes format is shown below:

RRRR GGGG | BBBB RRRR | GGGG BBBB

If only sending one pixel, you may use this format instead:

XXXX RRRR | GGGG BBBB (X means "don't care", can be either 0 or 1, these bits are discarded)

In C, you may use this code to output 2-pixels-per-3-bytes format, color1 and color2 are 16-bit values (ints in AVR GCC)

(color_lcd_send_data(char dat) is a function that outputs a data byte to the LCD)

color_lcd_send_data(color1 >> 4);
color_lcd_send_data(((color1&0x0F)<<4)|(color2>>8));
color_lcd_send_data(color2);

This code is simplified for 1-pixel-2-bytes format for single-pixel writes:

color_lcd_send_data(color >> 4);
color_lcd_send_data(color<<4);