SPI Graphic Lcd Library

mikroC PRO for PIC32 provides a library for operating Graphic Lcd 128x64 (with commonly used Samsung KS108/KS107 controller) via SPI interface.

For creating a custom set of Glcd images use Glcd Bitmap Editor Tool.

  Important :

Library Dependency Tree

SPI Graphic Lcd Library Dependency Tree

External dependencies of SPI Lcd Library

The implementation of SPI Lcd Library routines is based on Port Expander Library routines.

External dependencies are the same as Port Expander Library external dependencies.

Library Routines

Basic routines:

Advanced routines:

SPI_Glcd_Init

Prototype

void SPI_Glcd_Init(char DeviceAddress);

Description

Initializes the Glcd module via SPI interface.

Parameters
  • DeviceAddress: SPI expander hardware address, see schematic at the bottom of this page
Returns

Nothing.

Requires Global variables :
  • SPExpanderCS: Chip Select line
  • SPExpanderRST: Reset line
  • SPExpanderCS_Direction: Direction of the Chip Select pin
  • SPExpanderRST_Direction: Direction of the Reset pin
must be defined before using this function.


The SPI module needs to be initialized. See SPIx_Init and SPIx_Init_Advanced routines.

Example
// Port Expander module connections
sbit  SPExpanderRST at LATF0_bit;
sbit  SPExpanderCS  at LATF1_bit;
sbit  SPExpanderRST_Direction at TRISF0_bit;
sbit  SPExpanderCS_Direction  at TRISF1_bit;
// End Port Expander module connections

...

// If Port Expander Library uses SPI module :
SPI1_Init();  // Initialize SPI module used with PortExpander
SPI_Glcd_Init(0);
Notes

None.

SPI_Glcd_Set_Side

Prototype

void SPI_Glcd_Set_Side(char x_pos);

Description

Selects Glcd side. Refer to the Glcd datasheet for detail explanation.

Parameters
  • x_pos: position on x-axis. Valid values: 0..127

The parameter x_pos specifies the Glcd side: values from 0 to 63 specify the left side, values from 64 to 127 specify the right side.

Returns

Nothing.

Requires

Glcd needs to be initialized for SPI communication, see SPI_Glcd_Init routine.

Example

The following two lines are equivalent, and both of them select the left side of Glcd:

SPI_Glcd_Set_Side(0);
SPI_Glcd_Set_Side(10);
Notes

For side, x axis and page layout explanation see schematic at the bottom of this page.

SPI_Glcd_Set_Page

Prototype

void SPI_Glcd_Set_Page(char page);

Description

Selects page of Glcd.

Returns
  • page: page number. Valid values: 0..7
Requires

Glcd needs to be initialized for SPI communication, see SPI_Glcd_Init routine.

Example
SPI_Glcd_Set_Page(5);
Notes

For side, x axis and page layout explanation see schematic at the bottom of this page.

SPI_Glcd_Set_X

Prototype

void SPI_Glcd_Set_X(char x_pos);

Description

Sets x-axis position to x_pos dots from the left border of Glcd within the selected side.

Parameters
  • x_pos: position on x-axis. Valid values: 0..63
Returns

Nothing.

Requires

Glcd needs to be initialized for SPI communication, see SPI_Glcd_Init routine.

Example
SPI_Glcd_Set_X(25);
Notes

For side, x axis and page layout explanation see schematic at the bottom of this page.

SPI_Glcd_Read_Data

Prototype

char SPI_Glcd_Read_Data();

Description

Reads data from the current location of Glcd memory and moves to the next location.

Returns

One byte from Glcd memory.

Requires

Glcd needs to be initialized for SPI communication, see SPI_Glcd_Init routine.

Glcd side, x-axis position and page should be set first. See the functions SPI_Glcd_Set_Side, SPI_Glcd_Set_X, and SPI_Glcd_Set_Page.

Parameters

None.

Example
char data_;
...
data_ = SPI_Glcd_Read_Data();
Notes

None.

SPI_Glcd_Write_Data

Prototype

void SPI_Glcd_Write_Data(char data_);

Description

Writes one byte to the current location in Glcd memory and moves to the next location.

Parameters
  • data_: data to be written
Returns

Nothing.

Requires

Glcd needs to be initialized for SPI communication, see SPI_Glcd_Init routine.

Glcd side, x-axis position and page should be set first. See the functions SPI_Glcd_Set_Side, SPI_Glcd_Set_X, and SPI_Glcd_Set_Page.

Example
char data_;
...
SPI_Glcd_Write_Data(data_);
Notes

None.

SPI_Glcd_Set_Ext_Buffer

Prototype

void SPI_Glcd_Set_Ext_Buffer(char* (*getExtDataPtr)(unsigned long offset, unsigned long count, unsigned long* num));

Returns

Nothing.

Description

Function sets pointer to the user function which manipulates the external resource.

Parameters :

  • offset - offset from the beginning of the resource from where the data is requested.
  • count - requested number of bytes.
  • num - variable for holding the returned number ob byte (less or equal to the number of acqired bytes).

Requires

Glcd needs to be initialized for SPI communication, see SPI_Glcd_Init routine.

Glcd side, x-axis position and page should be set first. See the functions SPI_Glcd_Set_Side, SPI_Glcd_Set_X, and SPI_Glcd_Set_Page.

Example
char* ReadExternalBuffer(unsigned long offset, unsigned int count, unsigned int *num){
  unsigned long start_sector;
  unsigned int pos;

  start_sector = Mmc_Get_File_Write_Sector() + offset/512;
  pos = (unsigned long)offset%512;

  if(start_sector == currentSector+1){
    Mmc_Multi_Read_Buffer(EXT_BUFFER);
    currentSector = start_sector;
  }else
    if(start_sector != currentSector){
      Mmc_Multi_Read_Stop();
      Mmc_Multi_Read_Start(start_sector);
      Mmc_Multi_Read_Buffer(EXT_BUFFER);
      currentSector = start_sector;
    }

  if(count>512-pos){
    *num = 512-pos;
  }
  else
    *num = count;

  return EXT_BUFFER+pos;
}

SPI_Glcd_Set_Ext_Buffer(ReadExternalBuffer);

SPI_Glcd_Fill

Prototype

void SPI_Glcd_Fill(char pattern);

Description

Fills Glcd memory with byte pattern.

To clear the Glcd screen, use SPI_Glcd_Fill(0).

To fill the screen completely, use SPI_Glcd_Fill(0xFF).

Parameters
  • pattern: byte to fill Glcd memory with
Returns

Nothing.

Requires

Glcd needs to be initialized for SPI communication, see SPI_Glcd_Init routine.

Example
// Clear screen
SPI_Glcd_Fill(0);
Notes

None.

SPI_Glcd_Dot

Prototype

void SPI_Glcd_Dot(char x_pos, char y_pos, char color);

Description

Draws a dot on Glcd at coordinates (x_pos, y_pos).

Parameters
  • x_pos: x position. Valid values: 0..127
  • y_pos: y position. Valid values: 0..63
  • color: color parameter. Valid values: 0..2

The parameter color determines the dot state: 0 clears dot, 1 puts a dot, and 2 inverts dot state.

Returns

Nothing.

Requires

Glcd needs to be initialized for SPI communication, see SPI_Glcd_Init routine.

Example
// Invert the dot in the upper left corner
SPI_Glcd_Dot(0, 0, 2);
Notes

For x and y axis layout explanation see schematic at the bottom of this page..

SPI_Glcd_Line

Prototype

void SPI_Glcd_Line(int x_start, int y_start, int x_end, int y_end, char color);

Description

Draws a line on Glcd.

Parameters :

Parameters
  • x_start: x coordinate of the line start. Valid values: 0..127
  • y_start: y coordinate of the line start. Valid values: 0..63
  • x_end: x coordinate of the line end. Valid values: 0..127
  • y_end: y coordinate of the line end. Valid values: 0..63
  • color: color parameter. Valid values: 0..2

Parameter color determines the line color: 0 white, 1 black, and 2 inverts each dot.

Returns

Nothing.

Requires

Glcd needs to be initialized for SPI communication, see SPI_Glcd_Init routine.

Example
// Draw a line between dots (0,0) and (20,30)
SPI_Glcd_Line(0, 0, 20, 30, 1);
Notes

None.

SPI_Glcd_V_Line

Prototype

void SPI_Glcd_V_Line(char y_start, char y_end, char x_pos, char color);

Description

Draws a vertical line on Glcd.

Parameters
  • y_start: y coordinate of the line start. Valid values: 0..63
  • y_end: y coordinate of the line end. Valid values: 0..63
  • x_pos: x coordinate of vertical line. Valid values: 0..127
  • color: color parameter. Valid values: 0..2

Parameter color determines the line color: 0 white, 1 black, and 2 inverts each dot.

Returns

Nothing.

Requires

Glcd needs to be initialized for SPI communication, see SPI_Glcd_Init routine.

Example
// Draw a vertical line between dots (10,5) and (10,25)
SPI_Glcd_V_Line(5, 25, 10, 1);
Notes

None.

SPI_Glcd_H_Line

Prototype

void SPI_Glcd_H_Line(char x_start, char x_end, char y_pos, char color);

Description

Draws a horizontal line on Glcd.

Parameters
  • x_start: x coordinate of the line start. Valid values: 0..127
  • x_end: x coordinate of the line end. Valid values: 0..127
  • y_pos: y coordinate of horizontal line. Valid values: 0..63
  • color: color parameter. Valid values: 0..2

The parameter color determines the line color: 0 white, 1 black, and 2 inverts each dot.

Returns

Nothing.

Requires

Glcd needs to be initialized for SPI communication, see SPI_Glcd_Init routine.

Example
// Draw a horizontal line between dots (10,20) and (50,20)
SPI_Glcd_H_Line(10, 50, 20, 1);
Notes

None.

SPI_Glcd_Rectangle

Prototype

void SPI_Glcd_Rectangle(char x_upper_left, char y_upper_left, char x_bottom_right, char y_bottom_right, char color);

Description

Draws a rectangle on Glcd.

Parameters
  • x_upper_left: x coordinate of the upper left rectangle corner. Valid values: 0..127
  • y_upper_left: y coordinate of the upper left rectangle corner. Valid values: 0..63
  • x_bottom_right: x coordinate of the lower right rectangle corner. Valid values: 0..127
  • y_bottom_right: y coordinate of the lower right rectangle corner. Valid values: 0..63
  • color: color parameter. Valid values: 0..2

The parameter color determines the color of the rectangle border: 0 white, 1 black, and 2 inverts each dot.

Returns

Nothing.

Requires

Glcd needs to be initialized for SPI communication, see SPI_Glcd_Init routine.

Example
// Draw a rectangle between dots (5,5) and (40,40)
SPI_Glcd_Rectangle(5, 5, 40, 40, 1);
Notes

None.

SPI_Glcd_Rectangle_Round_Edges

Prototype

void SPI_Glcd_Rectangle_Round_Edges(unsigned short x_upper_left, unsigned short y_upper_left, unsigned short x_bottom_right, unsigned short y_bottom_right, unsigned short round_radius, unsigned short color);

Description

Draws a rounded edge rectangle on Glcd.

Parameters
  • x_upper_left: x coordinate of the upper left rectangle corner. Valid values: 0..127
  • y_upper_left: y coordinate of the upper left rectangle corner. Valid values: 0..63
  • x_bottom_right: x coordinate of the lower right rectangle corner. Valid values: 0..127
  • y_bottom_right: y coordinate of the lower right rectangle corner. Valid values: 0..63
  • round_radius: radius of the rounded edge.
  • color: color parameter. Valid values: 0..2

The parameter color determines the color of the rectangle border: 0 white, 1 black, and 2 inverts each dot.

Returns

Nothing.

Requires

Glcd needs to be initialized, see SPI_Glcd_Init routine.

Example
// Draw a rounded edge rectangle between dots (5,5) and (40,40) with the radius of 12
SPI_Glcd_Rectangle_Round_Edges(5, 5, 40, 40, 12, 1);
Notes

None.

SPI_Glcd_Rectangle_Round_Edges_Fill

Prototype

void SPI_Glcd_Rectangle_Round_Edges_Fill(unsigned short x_upper_left, unsigned short y_upper_left, unsigned short x_bottom_right, unsigned short y_bottom_right, unsigned short round_radius, unsigned short color);

Description

Draws a filled rounded edge rectangle on Glcd with color.

Parameters
  • x_upper_left: x coordinate of the upper left rectangle corner. Valid values: 0..127
  • y_upper_left: y coordinate of the upper left rectangle corner. Valid values: 0..63
  • x_bottom_right: x coordinate of the lower right rectangle corner. Valid values: 0..127
  • y_bottom_right: y coordinate of the lower right rectangle corner. Valid values: 0..63
  • round_radius: radius of the rounded edge
  • color: color parameter. Valid values: 0..2

The parameter color determines the color of the rectangle : 0 white, 1 black, and 2 inverts each dot.

Returns

Nothing.

Requires

Glcd needs to be initialized, see SPI_Glcd_Init routine.

Example
// Draws a filled rounded edge rectangle between dots (5,5) and (40,40) with the radius of 12
SPI_Glcd_Rectangle_Round_Edges_Fill(5, 5, 40, 40, 12, 1);
Notes

None.

SPI_Glcd_Box

Prototype

void SPI_Glcd_Box(char x_upper_left, char y_upper_left, char x_bottom_right, char y_bottom_right, char color);

Description

Draws a box on Glcd.

Parameters
  • x_upper_left: x coordinate of the upper left box corner. Valid values: 0..127
  • y_upper_left: y coordinate of the upper left box corner. Valid values: 0..63
  • x_bottom_right: x coordinate of the lower right box corner. Valid values: 0..127
  • y_bottom_right: y coordinate of the lower right box corner. Valid values: 0..63
  • color: color parameter. Valid values: 0..2

The parameter color determines the color of the box fill: 0 white, 1 black, and 2 inverts each dot.

Returns

Nothing.

Requires

Glcd needs to be initialized for SPI communication, see SPI_Glcd_Init routine.

Example
// Draw a box between dots (5,15) and (20,40)
SPI_Glcd_Box(5, 15, 20, 40, 1);
Notes

None.

SPI_Glcd_Circle

Prototype

void SPI_Glcd_Circle(int x_center, int y_center, int radius, char color);

Description

Draws a circle on Glcd.

Parameters
  • x_center: x coordinate of the circle center. Valid values: 0..127
  • y_center: y coordinate of the circle center. Valid values: 0..63
  • radius: radius size
  • color: color parameter. Valid values: 0..2

The parameter color determines the color of the circle line: 0 white, 1 black, and 2 inverts each dot.

Returns

Nothing.

Requires

Glcd needs to be initialized for SPI communication, see SPI_Glcd_Init routine.

Example
// Draw a circle with center in (50,50) and radius=10
SPI_Glcd_Circle(50, 50, 10, 1);
Notes

None.

SPI_Glcd_Circle_FIll

Prototype

void SPI_Glcd_Circle_Fill(int x_center, int y_center, int radius, char color);

Description

Draws a filled circle on Glcd.

Parameters
  • x_center: x coordinate of the circle center. Valid values: 0..127
  • y_center: y coordinate of the circle center. Valid values: 0..63
  • radius: radius size
  • color: color parameter. Valid values: 0..2

The parameter color determines the color of the circle : 0 white, 1 black, and 2 inverts each dot.

Returns

Nothing.

Requires

Glcd needs to be initialized for SPI communication, see SPI_Glcd_Init routine.

Example
// Draw a circle with center in (50,50) and radius=10
SPI_Glcd_Circle_Fill(50, 50, 10, 1);
Notes

None.

SPI_Glcd_Set_Font

Prototype

void SPI_Glcd_Set_Font(const code char *activeFont, char aFontWidth, char aFontHeight, unsigned int aFontOffs);

Description

Sets font that will be used with SPI_Glcd_Write_Char and SPI_Glcd_Write_Text routines.

Parameters

None.

Returns
  • activeFont: font to be set. Needs to be formatted as an array of char
  • aFontWidth: width of the font characters in dots.
  • aFontHeight: height of the font characters in dots.
  • aFontOffs: number that represents difference between the mikroC PRO for PIC32 character set and regular ASCII set (eg. if 'A' is 65 in ASCII character, and 'A' is 45 in the mikroC PRO for PIC32 character set, aFontOffs is 20). Demo fonts supplied with the library have an offset of 32, which means that they start with space.

The user can use fonts given in the file __Lib_GLCDFonts file located in the Uses folder or create his own fonts.

List of supported fonts:
  • Font_Glcd_System3x5
  • Font_Glcd_System5x7
  • Font_Glcd_5x7
  • Font_Glcd_Character8x7

For the sake of the backward compatibility, these fonts are supported also:

  • System3x5 (equivalent to Font_Glcd_System3x5)
  • FontSystem5x7_v2 (equivalent to Font_Glcd_System5x7)
  • font5x7 (equivalent to Font_Glcd_5x7)
  • Character8x7 (equivalent to Font_Glcd_Character8x7)
Requires

Glcd needs to be initialized for SPI communication, see SPI_Glcd_Init routine.

Example
// Use the custom 5x7 font "myfont" which starts with space (32):
SPI_Glcd_Set_Font(myfont, 5, 7, 32);
Notes

None.

SPI_Glcd_Set_Font_Adv

Prototype

void SPI_Glcd_Set_Font_Adv(const char *activeFont, unsigned char font_color, char font_orientation);

Description

Sets font that will be used with SPI_Glcd_Write_Char_Adv and SPI_Glcd_Write_Text_Adv routines. Font is located in an external resource.

Parameters
  • activeFont: font to be set. Needs to be formatted as an array of char.
  • font_color: sets font color.
  • font_orientation: sets font orientation.
Returns

Nothing.

Requires

Glcd needs to be initialized for SPI communication, see SPI_Glcd_Init routine.

Example
Glcd_Set_Font_Adv(@myfont, 0, 0);
Notes

None.

SPI_Glcd_Set_Ext_Font_Adv

Prototype

void SPI_Glcd_Set_Ext_Font_Adv(unsigned long activeFont, unsigned short aFontWidth, unsigned short aFontHeight, unsigned int aFontOffs);

Description

Sets font that will be used with SPI_Glcd_Write_Char_Adv and SPI_Glcd_Write_Text_Adv routines. Font is located in an external resource.

Parameters
  • activeFont: font to be set. This parameter represents the address in the exteral resource from where the font data begins.
  • font_color: sets font color.
  • font_orientation: sets font orientation.
Returns

Nothing.

Requires

Glcd needs to be initialized for SPI communication, see SPI_Glcd_Init routine.

Example
SPI_Glcd_Set_Ext_Font_Adv(173296, 5, 7, 32);
Notes

None.

SPI_Glcd_Write_Char

Prototype

void SPI_Glcd_Write_Char(char chr1, char x_pos, char page_num, char color);

Description

Prints character on Glcd.

Parameters
  • chr1: character to be written
  • x_pos: character starting position on x-axis. Valid values: 0..(127-FontWidth)
  • page_num: the number of the page on which character will be written. Valid values: 0..7
  • color: color parameter. Valid values: 0..2

The parameter color determines the color of the character: 0 white, 1 black, and 2 inverts each dot.

Returns

Nothing.

Requires

SPI_Glcd needs to be initialized for SPI communication, see SPI_Glcd_Init routine.

Use the SPI_Glcd_Set_Font to specify the font for display; if no font is specified, then the default Font_Glcd_System5x7 font supplied with the library will be used.

Example
// Write character 'C' on the position 10 inside the page 2:
SPI_Glcd_Write_Char('C', 10, 2, 1);
Notes

For x axis and page layout explanation see schematic at the bottom of this page.

SPI_Glcd_Write_Char_Adv

Prototype

void SPI_Glcd_Write_Char_Adv(unsigned int c, unsigned int x, unsigned int y);

Returns

Nothing.

Description

Writes a char on the glcd at coordinates (x, y).

  • c: char to be written.
  • x: char position on x-axis.
  • y: char position on y-axis.
Requires

Glcd needs to be initialized for SPI communication, see SPI_Glcd_Init routine.

Example
SPI_Glcd_Write_Char_Adv('A',22,23);

SPI_Glcd_Write_Text

Prototype

void SPI_Glcd_Write_Text(char text[], char x_pos, char page_num, char color);

Description

Prints text on Glcd.

Parameters
  • text: text to be written
  • x_pos: text starting position on x-axis.
  • page_num: the number of the page on which text will be written. Valid values: 0..7
  • color: color parameter. Valid values: 0..2

The parameter color determines the color of the text: 0 white, 1 black, and 2 inverts each dot.

Returns

Nothing.

Requires

SPI_Glcd needs to be initialized for SPI communication, see SPI_Glcd_Init routine.

Use the SPI_Glcd_Set_Font to specify the font for display; if no font is specified, then the default Font_Glcd_System5x7 font supplied with the library will be used.

Example
// Write text "Hello world!" on the position 10 inside the page 2:
SPI_Glcd_Write_Text("Hello world!", 10, 2, 1);
Notes

For x axis and page layout explanation see schematic at the bottom of this page.

SPI_Glcd_Write_Text_Adv

Prototype

void SPI_Glcd_Write_Text_Adv(unsigned char *text, unsigned int x, unsigned int y);

Returns

Nothing.

Description

Writes text on the glcd at coordinates (x, y).

Parameters :

  • text: text to be written.
  • x: text position on x-axis.
  • y: text position on y-axis.
Requires

Glcd needs to be initialized for SPI communication, see SPI_Glcd_Init routine.

Example
SPI_Glcd_Write_Text_Adv("GLCD LIBRARY DEMO, WELCOME !", 0, 0);	

SPI_Glcd_Image

Prototype

void SPI_Glcd_Image(const code char *image);

Description

Displays bitmap on Glcd.

Parameters
  • image: image to be displayed. Bitmap array can be located in both code and RAM memory (due to the mikroC PRO for PIC32 pointer to const and pointer to RAM equivalency).
Returns

Nothing.

Requires

SPI_Glcd needs to be initialized for SPI communication, see SPI_Glcd_Init routine.

Example
// Draw image my_image on Glcd
SPI_Glcd_Image(my_image);
Notes

Use the mikroC PRO for PIC32 integrated Glcd Bitmap Editor, Tools > Glcd Bitmap Editor, to convert image to a constant array suitable for displaying on Glcd.

SPI_Glcd_Ext_Image

Prototype

void SPI_Glcd_Ext_Image(unsigned long image);

Description

Displays a bitmap from an external resource on a desired address.

Parameters
  • image: image to be displayed. This parameter represents the address in the exteral resource from where the image data begins.
Returns

Nothing.

Requires

Glcd needs to be initialized for SPI communication, see SPI_Glcd_Init routine.

Example
SPI_Glcd_Ext_Image(153608);
Notes

Use the mikroC PRO for PIC32 integrated Glcd Bitmap Editor, Tools > Glcd Bitmap Editor, to convert image to a constant array suitable for displaying on Glcd.

SPI_Glcd_PartialImage

Prototype

void SPI_Glcd_PartialImage(unsigned int x_left, unsigned int y_top, unsigned int width, unsigned int height, unsigned int picture_width, unsigned int picture_height, code const unsigned short * image);

Description

Displays a partial area of the image on a desired location.

Parameters
  • x_left: x coordinate of the desired location (upper left coordinate).
  • y_top: y coordinate of the desired location (upper left coordinate).
  • width: desired image width.
  • height: desired image height.
  • picture_width: width of the original image.
  • picture_height: height of the original image.
  • image: image to be displayed. Bitmap array can be located in both code and RAM memory (due to the mikroC PRO for PIC pointer to const and pointer to RAM equivalency).
Returns

Nothing.

Requires

SPI_Glcd needs to be initialized for SPI communication, see SPI_Glcd_Init routine.

Example
// Draws a 10x15 part of the image starting from the upper left corner on the coordinate (10,12). Original image size is 16x32. 
SPI_Glcd_PartialImage(10, 12, 10, 15, 16, 32, image);
Notes

Use the mikroC PRO for PIC32 integrated Glcd Bitmap Editor, Tools > Glcd Bitmap Editor, to convert image to a constant array suitable for displaying on Glcd.

SPI_Glcd_Ext_PartialImage

Prototype

void SPI_Glcd_Ext_PartialImage(unsigned int x_left, unsigned int y_top, unsigned int width, unsigned int height, unsigned int picture_width, unsigned int picture_height, unsigned long image);

Description

Displays a partial area of the image, located on an external resource, on a desired location of the screen.

Parameters
  • x_left: x coordinate of the desired location (upper left coordinate).
  • y_top: y coordinate of the desired location (upper left coordinate).
  • width: desired image width.
  • height: desired image height.
  • picture_width: width of the original image.
  • picture_height: height of the original image.
  • image: image to be displayed. This parameter represents the address in the exteral resource from where the image data begins.
Returns

Nothing.

Requires

Glcd needs to be initialized for SPI communication, see SPI_Glcd_Init routine.

Example
SPI_Glcd_Ext_PartialImage(10, 12, 10, 15, 16, 32, 0);
Notes

Use the mikroC PRO for PIC32 integrated Glcd Bitmap Editor, Tools > Glcd Bitmap Editor, to convert image to a constant array suitable for displaying on Glcd.

Library Example

The example demonstrates how to communicate to KS0108 Glcd via the SPI module, using serial to parallel convertor MCP23S17.

Copy Code To ClipboardCopy Code To Clipboard
const code char truck_bmp[1024];

// Port Expander module connections
sbit  SPExpanderRST at LATD8_bit;
sbit  SPExpanderCS  at LATD9_bit;
sbit  SPExpanderRST_Direction at TRISD8_bit;
sbit  SPExpanderCS_Direction  at TRISD9_bit;
// End Port Expander module connections

void Delay2s(){                         // 2 seconds delay function
  Delay_ms(2000);
}

void main() {
  char counter;
  char *someText;

  CHECON = 0x32;
  AD1PCFG = 0xFFFF;                     // Configure AN pins as digital

  // If Port Expander Library uses SPI2 module
  // Initialize SPI module used with PortExpander
  SPI2_Init_Advanced(_SPI_MASTER,_SPI_8_BIT, 4, _SPI_SS_DISABLE,_SPI_DATA_SAMPLE_MIDDLE,_SPI_CLK_IDLE_LOW,_SPI_ACTIVE_2_IDLE);

  SPI_Glcd_Init(0);                                        // Initialize Glcd via SPI
  SPI_Glcd_Fill(0x00);                                     // Clear Glcd

  while(1) {
    SPI_Glcd_Image(truck_bmp);                             // Draw image
    Delay2s(); Delay2s();
    SPI_Glcd_fill(0x00);                                   // Clear GLCD
    SPI_Glcd_PartialImage(0,0,68,30,128,64,truck_bmp);     // Partial image
    Delay_ms(500);
    SPI_Glcd_PartialImage(24,16,68,30,128,64,truck_bmp);
    Delay_ms(500);
    SPI_Glcd_PartialImage(56,34,68,30,128,64,truck_bmp);
    Delay2s(); Delay2s();
    SPI_Glcd_Fill(0x00);                                   // Clear GLCD

    SPI_Glcd_Box(62,40,124,56,1);                          // Draw box
    SPI_Glcd_Rectangle(5,5,84,35,1);                       // Draw rectangle
    Delay_ms(1000);
    SPI_Glcd_Rectangle_Round_Edges(2,2,87,38,7,1);
    Delay_ms(1000);
    SPI_Glcd_Rectangle_Round_Edges_Fill(8,8,81,32,12,1);
    Delay_ms(1000);
    SPI_Glcd_Line(0, 0, 127, 63, 1);                       // Draw line
    Delay2s();

    for(counter = 5; counter < 60; counter+=5 ) {          // Draw horizontal and vertical lines
      Delay_ms(250);
      SPI_Glcd_V_Line(2, 54, counter, 1);
      SPI_Glcd_H_Line(2, 120, counter, 1);
    }
    Delay2s();

    SPI_Glcd_Fill(0x00);                                   // Clear Glcd
    SPI_Glcd_Set_Font(Font_Glcd_Character8x7, 8, 7, 32);   // Choose font, see __Lib_GLCDFonts.c in Uses folder
    SPI_Glcd_Write_Text("mikroE", 5, 7, 2);                // Write string

    for (counter = 1; counter <= 10; counter++)            // Draw circles
      SPI_Glcd_Circle(63,32, 3*counter, 1);
    Delay2s();

    SPI_Glcd_Circle_Fill(63,32, 30, 1);                    // Draw circles
    Delay2S();

    SPI_Glcd_Box(12,20, 70,63, 2);                         // Draw box
    Delay2s();

    SPI_Glcd_Fill(0xFF);                                   // Fill Glcd
    SPI_Glcd_Set_Font(Font_Glcd_Character8x7, 8, 7, 32);   // Change font
    someText = "8x7 Font";
    SPI_Glcd_Write_Text(someText, 5, 0, 2);                // Write string
    Delay2s();

    SPI_Glcd_Set_Font(Font_Glcd_System3x5, 3, 5, 32);      // Change font
    someText = "3X5 CAPITALS ONLY";
    SPI_Glcd_Write_Text(someText, 60, 2, 2);               // Write string
    Delay2s();

    SPI_Glcd_Set_Font(Font_Glcd_System5x7, 5, 7, 32);      // Change font
    someText = "5x7 Font";
    SPI_Glcd_Write_Text(someText, 5, 4, 2);                // Write string
    Delay2s();

    SPI_Glcd_Set_Font(Font_Glcd_5x7, 5, 7, 32);            // Change font
    someText = "5x7 Font (v2)";
    SPI_Glcd_Write_Text(someText, 5, 6, 2);                // Write string
    Delay2s();
  }
}

HW Connection

SPI Glcd HW connection

SPI Glcd HW connection

Copyright (c) 2002-2012 mikroElektronika. All rights reserved.
What do you think about this topic ? Send us feedback!
Want more examples and libraries? 
Find them on LibStock - A place for the code