|
|
A Group of C Functions for Using the Newhaven COG 128 x 128 pixel LCD Graphic Display
David V. Fansler
The Newhaven NHD-C128128BZ/NHD-C128128CZ displays are 128 x 128 pixel monochrome LCD Displays that are perfect to use in project requiring graphics at a low cost. Unfortunately, the use of a graphics display requires much more work on the part of the microprocessor than a standard ASCII display. While working on an astronomy project that used this display, I developed a series of functions, written in C, that make it easy for a user to display data text and graphics. These functions were developed while using a Renesas M16C/62P M30622F8P under the Renesas High Performance Workshop IDE. The functions are all contained within the file 128x128NewHaven_lcd.c, with defines being located in the file 128x128NewHaven_bsp.h A schematic of my hardware interface can be found in 128x128Newhaven_sch.pdf. Interface If your microprocessor runs from 3.3v, then no additional interface circuitry is needed, since the NHD-C128128BZ/NHD-C128128CZ displays are 3.3v devices. For those of us still running on 5v, the use of two 74LVC4245 ICs are needed, along with a 3.3 voltage regulator. The 74VC4245 is an octal transceiver with 3.3v to 5v shifter that handles the voltage change for us. There are only 12 lines needed - 8 data lines and 4 control lines (reset, enable, data/instruction, write). I typically use a 5th control line as a PWM to control the brightness of the LCD backlight. These lines are defined in 128x128NewHaven_bsp.h, making it easy to change for any microprocessor. The Functions While there are a total of 16 functions, only a few are called by the user, the rest handle the mundane work of talking to the display. void InitDisplay(void) this should be the first function called before using the display. This function calls Init_LCD_IO(void) which is the only function that needs to be modified for the particular microprocessor being used. DATA_PORT is a DEFINE for the 8 bit port used to send data to the display. The other pins should be self explanatory. void LCD_Init() should be the second function called before using the display. This function initializes the many registers of the display, as described in the data sheet for the display. I do not recommend making any changes to this function. void Clear_Display(int start, int end) as implied by its name, this function will clear any, or all lines of the display. The display has 16 lines (0-15). The user can call Clear_Display(0,15) to clear the entire display, or to clear the 5th 7th lines, Clear_Display(5,7). A single line is the minimum clear for this function. void PosSetUp(unsigned char Page, unsigned char column) before writing to the display, you must tell the display where you wish to have the data displayed. The term Page and Line are the same when using this display. The column is the horizontal position (0-127). To start data displaying on line 8, column 27 the call would be PosSetUp(8,27). This function calls two other functions that the user does not normally call LCD_write_Cntrl(page) and LCD_write_COLUMN(column). void DisplayChar(unsigned char Start_Col, char value, int nor_inv) is used to send a single ASCII character to the display. Within the 128x128NewHaven_lcd.c file is a list of const char arrays that define the graphic output needed for a large number of ASCII characters. These characters are typically in an 8x8 pixel block and include spacing between characters. To display a single ASCII character, first the user calls PosSetUp() to define the line and column where the character is to go. To display the letter S on line 3, column 35 the user would call PosSetUp(3,35); The column is define again in DisplayChar(), so that if writing to the same line again, you do not have to call PosSetUp() again. Simply change the value of Start_Col for the next use of DisplayChar(). void DisplayString(unsigned char Start_Col, _far char *value, int nor_inv) is used to send a string of ASCII characters to the display. The string must be terminated with a NULL as defined by C. Usage of this function is almost identical to DisplayChar(), with the exception of the pointer for the string. The _far is needed by the Renesas complier to indicate a region of memory outside of the current region your complier may or may not need this term. Again, call PosSetUp() to define the line and column to start the data display and then call DisplayString() to send the data to the display. As before, the ASCII data displayed is derived from the const char arrays in the file 128x128NewHaven_lcd.c. void OutputData(unsigned char Start_Col,int j,int nor_inv) this function is used by every display function in the 128x128NewHaven_lcd.c file. This function is responsible for outputting data to be displayed, in graphic form a single byte at the time. This function is useful for displaying or changing small amount of graphics. As with most of the other functions, a call to PosSetUp() should be made first to set the line and column position. After that, calling OutputData() with the column to write to, the single byte of data to write and whether the output is NORMAL or INVERTED. Data is always outputted a byte at the time, with a byte representing a column of 8 bits on a line. The data displayed has the top most bit of the 8 as the LSBit and the bottom most bit as the MSBit. void Show_Display(_far char *lcd_string, int nor_inv) this function is used to display canned graphics. It is the string version of OutputData(). It can be used to show as few as a single byte on a single line, to all 16 lines and 128 columns. The data to be displayed is stored as a const char array with a define format. As before, the words NORMAL and INVERTED are used to determine output. As an example, the following array will display a pirate ship const char pirate_ship [] = { This is the one display function that does not require the PosSetUp() function prior to being used. The layout of the array is
as follows Once the number of bytes of data defined to be shown are processed, if there is more data then the sequence of 2nd byte 4th byte repeat until the end of the array is reached. In the above example, there are 4 lines of data to be displayed. The first is on line 12 of the display, column 60 and is 40 bytes long. The second line of data is line 13, column 60 and is 40 characters long. Two more lines (14, 15) also start at column 60 and are 40 bytes long.
And there you have my functions for communicating with a Newhaven NHD-C128128BZ/NHD-C128128CZ display. I do not claim to be an expert in C, and therefore you may find more efficient ways of re-writing these functions, but it will give you an easy start. I hope you find these useful.
|
Please address general comments to web@dv-fansler.com This page was last modified:
01/22/14 |