Epson S1D13700 Graphic Lcd Library

The mikroC PRO for PIC provides a library for working with Glcds based on Epson S1D13700 controller.

The S1D13700 Glcd is capable of displaying both text and graphics on an LCD panel. The S1D13700 Glcd allows layered text and graphics, scrolling of the display in any direction, and partitioning of the display into multiple screens.
It includes 32K bytes of embedded SRAM display memory which is used to store text, character codes, and bit-mapped graphics.

The S1D13700 Glcd handles display controller functions including :

The S1D13700 Glcd is designed with an internal character generator which supports 160, 5x7 pixel characters in internal mask ROM (CGROM) and 64, 8x8 pixel characters incharacter generator RAM (CGRAM).
When the CGROM is not used, up to 256, 8x16 pixel characters are supported in CGRAM.

External dependencies of the Epson S1D13700 Graphic Lcd Library

The following variables must be defined in all projects using S1D13700 Graphic Lcd library: Description : Example :
extern sfr char S1D13700_DATA; System data bus. char S1D13700_DATA at PORTD;
extern sfr sbit S1D13700_WR; Write signal. sbit S1D13700_WR at LATC2_bit;
extern sfr sbit S1D13700_RD; Read signal. sbit S1D13700_RD at LATC1_bit;
extern sfr sbit S1D13700_A0; System Address pin. sbit S1D13700_A0 at LATC0_bit;
extern sfr sbit S1D13700_RES; Reset signal. sbit S1D13700_RES at LATC4_bit;
extern sfr sbit S1D13700_CS; Chip select. sbit S1D13700_CS at LATC4_bit;
extern sfr sbit S1D13700_DATA_Direction; Direction of the system data bus pins. sbit S1D13700_DATA_Direction at TRISD;
extern sfr sbit S1D13700_WR_Direction; Direction of the Write pin. sbit S1D13700_WR_Direction at TRISC2_bit;
extern sfr sbit S1D13700_RD_Direction; Direction of the Read pin. sbit S1D13700_RD_Direction at TRISC1_bit;
extern sfr sbit S1D13700_A0_Direction; Direction of the System Address pin. sbit S1D13700_A0_Direction at TRISC2_bit;
extern sfr sbit S1D13700_RES_Direction; Direction of the Reset pin. sbit S1D13700_RES_Direction at TRISC0_bit;
extern sfr sbit S1D13700_CS_Direction; Direction of the Chip select pin. sbit S1D13700_CS_Direction at TRISC4_bit;

Library Routines

S1D13700_Init

Prototype

void S1D13700_Init(unsigned int width, unsigned char height);

Returns

Nothing.

Description

Initializes S1D13700 Graphic Lcd controller.

Parameters :

  • width: width of the Glcd panel.
  • height: height of the Glcd panel.
Requires

Global variables :

  • S1D13700_Data_Port: Data Bus Port.
  • S1D13700_WR: Write signal pin.
  • S1D13700_RD: Read signal pin.
  • S1D13700_A0: Command/Data signal pin.
  • S1D13700_RES: Reset signal pin.
  • S1D13700_CS: Chip Select signal pin.


  • S1D13700_Data_Port_Direction: Data Bus Port Direction.
  • S1D13700_WR_Direction: Direction of Write signal pin.
  • S1D13700_RD_Direction: Direction of Read signal pin.
  • S1D13700_A0_Direction: Direction of Command/Data signal pin.
  • S1D13700_RES_Direction: Direction of Reset signal pin.
  • S1D13700_CS_Direction: Direction of Chip Select signal pin.
must be defined before using this function.

Example
// S1D13700 module connections
char S1D13700_Data_Port at PORTD;
sbit S1D13700_WR  at LATC2_bit;
sbit S1D13700_RD  at LATC1_bit;
sbit S1D13700_A0  at LATC0_bit;
sbit S1D13700_RES at LATC4_bit;
sbit S1D13700_CS  at LATC5_bit;

char S1D13700_Data_Port_Direction at TRISD;
sbit S1D13700_WR_Direction  at TRISC2_bit;
sbit S1D13700_RD_Direction  at TRISC1_bit;
sbit S1D13700_A0_Direction  at TRISC0_bit;
sbit S1D13700_RES_Direction at TRISC4_bit;
sbit S1D13700_CS_Direction at TRISC5_bit;
// End of S1D13700 module connections
...
// init display for 320 pixel width, 240 pixel height
S1D13700_Init(320, 240);

S1D13700_Write_Command

Prototype

void S1D13700_Write_Command(char command);

Returns

Nothing.

Description

Writes a command to S1D13700 controller.

Parameters :

  • command: command to be issued :
    Value Description
    S1D13700_SYSTEM_SET General system settings.
    S1D13700_POWER_SAVE Enter into power saving mode.
    S1D13700_DISP_ON Turn the display on.
    S1D13700_DISP_OFF Turn the display off.
    S1D13700_SCROLL Setup text and graphics address regions.
    S1D13700_CS_RIGHT Cursor moves right after write to display memory.
    S1D13700_CS_LEFT Cursor moves left after write to display memory.
    S1D13700_CS_UP Cursor moves up after write to display memory.
    S1D13700_CS_DOWN Cursor moves down after write to display memory.
    S1D13700_OVLAY Configure how layers overlay.
    S1D13700_CGRAM_ADR Configure character generator RAM address.
    S1D13700_HDOT_SCR Set horizontal scroll rate.
    S1D13700_CSRW Set the cursor address.
    S1D13700_CSRR Read the cursor address.
    S1D13700_GRAYSCALE Selects the gray scale depth, in bits-per-pixel (bpp).
    S1D13700_MEMWRITE Write to display memory.
    S1D13700_MEMREAD Read from display memory.
Requires

Glcd module needs to be initialized. See the S1D13700_Init routine.

Example
// Turn the display on
S1D13700_Write_Command(S1D13700_DISP_ON);

S1D13700_Write_Parameter

Prototype

void S1D13700_Write_Parameter(char parameter);

Returns

Nothing.

Description

Writes a parameter to S1D13700 controller.

Parameters :

  • parameter: parameter to be written.

Requires

Glcd module needs to be initialized. See the S1D13700_Init routine.

Previously, a command must be sent through S1D13700_Write_Command routine.

Example
S1D13700_Write_Command(S1D13700_CSRW); // set cursor address
S1D13700_Write_Parameter(Lo(start)); // send lower byte of cursor address
S1D13700_Write_Parameter(Hi(start)); // send higher byte cursor address

S1D13700_Read_Parameter

Prototype

char S1D13700_Read_Parameter();

Returns

Nothing.

Description

Reads a parameter from GLCD port.

Requires

Glcd module needs to be initialized. See the S1D13700_Init routine.

Example
parameter = S1D13700_Read_Parameter();

S1D13700_Fill

Prototype

void S1D13700_Fill(char d, unsigned int start, unsigned int len);

Returns

Nothing.

Description

Fills Glcd memory block with given byte.

Parameters :

  • d: byte to be written.
  • start: starting address of the memory block.
  • len: length of the memory block in bytes.

Requires

Glcd module needs to be initialized. See the S1D13700_Init routine.

Example
// from the starting address of 0x3000, fill the memory block size of 0x7FFF with 0x20
S1D13700_Fill(0x20, 0x3000, 0x7FFF);

S1D13700_GrFill

Prototype

void S1D13700_GrFill(char d);

Returns

Nothing.

Description

Fill graphic layer with appropriate value (0 to clear).

Parameters :

  • d: value to fill graphic layer with.
Requires

Glcd module needs to be initialized. See the S1D13700_Init routine.

Example
// clear current graphic panel 
S1D13700_GrFill(0);

S1D13700_TxtFill

Prototype

void S1D13700_TxtFill(char d);

Returns

Nothing.

Description

Fill current text panel with appropriate value (0 to clear).

Parameters :

  • d: this value will be used to fill text panel.
Requires

Glcd module needs to be initialized. See the S1D13700_Init routine.

Example
// clear current text panel
S1D13700_TxtFill(0);

S1D13700_Display_GrLayer

Prototype

void S1D13700_Display_GrLayer(char mode);

Returns

Nothing.

Description

Display selected graphic layer.

Parameters :

  • mode: graphic layer mode. Valid values :
    Value Description
    S1D13700_LAYER_OFF Turn off graphic layer.
    S1D13700_LAYER_ON Turn on graphic layer.
    S1D13700_LAYER_FLASH_2Hz Turn on graphic layer and flash it at the rate of 2 Hz.
    S1D13700_LAYER_FLASH_16Hz Turn on graphic layer and flash it at the rate of 16 Hz.
Requires

Glcd module needs to be initialized. See the S1D13700_Init routine.

Example
// Turn on graphic layer
S1D13700_Display_GrLayer(S1D13700_LAYER_ON);

S1D13700_Display_TxtLayer

Prototype

void S1D13700_Display_TxtLayer(char mode);

Returns

Nothing.

Description

Display selected text layer.

Parameters :

  • mode: text layer mode. Valid values :
    Value Description
    S1D13700_LAYER_OFF Turn off graphic layer.
    S1D13700_LAYER_ON Turn on graphic layer.
    S1D13700_LAYER_FLASH_2Hz Turn on graphic layer and flash it at the rate of 2 Hz.
    S1D13700_LAYER_FLASH_16Hz Turn on graphic layer and flash it at the rate of 16 Hz.
Requires

Glcd module needs to be initialized. See the S1D13700_Init routine.

Example
// Display on text layer
S1D13700_Display_TxtLayer(S1D13700_LAYER_ON);

S1D13700_Set_Cursor

Prototype

void S1D13700_Set_Cursor(char width, char height, char mode);

Returns

Nothing.

Description

Sets cursor properties.

Parameters :

  • width: in pixels-1 (must be less than or equal to the horizontal char size).
  • height: in lines-1 (must be less than or equal to the vertical char size).
  • mode: cursor mode. Valid values :
    Value Description
    S1D13700_CURSOR_UNDERSCORE Set cursor shape - underscore.
    S1D13700_CURSOR_BLOCK Set cursor shape - block.
Requires

Glcd module needs to be initialized. See the S1D13700_Init routine.

Example
// set cursor with the following properties : width 5px, height 10px, cursor shape - block
S1D13700_Set_Cursor(5, 10, S1D13700_CURSOR_BLOCK);

S1D13700_Display_Cursor

Prototype

void S1D13700_Display_Cursor(char mode);

Returns

Nothing.

Description

Displays cursor.

Parameters :

  • mode: mode parameter. Valid values:
    Value Description
    S1D13700_CURSOR_OFF Turn off graphic layer.
    S1D13700_CURSOR_ON Turn on graphic layer.
    S1D13700_CURSOR_FLASH_2Hz Turn on graphic layer and flash it at the rate of 2 Hz.
    S1D13700_CURSOR_FLASH_16Hz Turn on graphic layer and flash it at the rate of 16 Hz.
Requires

Glcd module needs to be initialized. See the S1D13700_Init routine.

Example
// set cursor on
S1D13700_Display_Cursor(S1D13700_CURSOR_ON);

S1D13700_Write_Char

Prototype

void S1D13700_Write_Char(unsigned char c, unsigned int x, unsigned int y, unsigned char mode);

Returns

Nothing.

Description

Writes a char in the current text layer of Glcd at coordinates (x, y).

Parameters :

  • c: char to be written.
  • x: char position on x-axis (column).
  • y: char position on y-axis (row).
  • mode: mode parameter. Valid values :
    Value Description
    S1D13700_OVERLAY_OR In the OR-Mode, text and graphics can be displayed and the data is logically "OR-ed".
    This is the most common way of combining text and graphics, for example labels on buttons.
    S1D13700_OVERLAY_XOR In this mode, the text and graphics data are combined via the logical "exclusive OR".
    S1D13700_OVERLAY_AND The text and graphic data shown on display are combined via the logical "AND function".
Requires

Glcd module needs to be initialized. See the S1D13700_Init routine.

Example
S1D13700_Write_Char('A',22,23,S1D13700_OVERLAY_OR);

S1D13700_Write_Text

Prototype

void S1D13700_Write_Text(unsigned char *str, unsigned char x, unsigned char y, char mode);

Returns

Nothing.

Description

Writes text in the current text panel of Glcd at coordinates (x, y).

Parameters :

  • str: text to be written.
  • x: text position on x-axis (column).
  • y: text position on y-axis (row).
  • mode: mode parameter. Valid values :
    Value Description
    S1D13700_OVERLAY_OR In the OR-Mode, text and graphics can be displayed and the data is logically "OR-ed".
    This is the most common way of combining text and graphics, for example labels on buttons.
    S1D13700_OVERLAY_XOR In this mode, the text and graphics data are combined via the logical "exclusive OR".
    S1D13700_OVERLAY_AND The text and graphic data shown on display are combined via the logical "AND function".
Requires

Glcd module needs to be initialized. See the S1D13700_Init routine.

Example
S1D13700_Write_Text("EPSON LIBRARY DEMO, WELCOME !", 0, 0, S1D13700_OVERLAY_OR);	

S1D13700_Dot

Prototype

void S1D13700_Dot(unsigned int x, unsigned int y, unsigned short color);

Returns

Nothing.

Description

Draws a dot in the current graphic panel of Glcd at coordinates (x, y).

Parameters :

  • x: dot position on x-axis.
  • y: dot position on y-axis.
  • color: color parameter. Valid values :
    Value Description
    S1D13700_BLACK Black color.
    S1D13700_WHITE White color.
    S1D13700_INVERT Invert color.
Requires

Glcd module needs to be initialized. See the S1D13700_Init routine.

Example
S1D13700_Dot(50, 50, S1D13700_WHITE);

S1D13700_Line

Prototype

void S1D13700_Line(unsigned int x0, unsigned int y0, unsigned int x1, unsigned int y1, unsigned char pcolor);

Returns

Nothing.

Description

Draws a line from (x0, y0) to (x1, y1).

Parameters :

  • x0: x coordinate of the line start.
  • y0: y coordinate of the line end.
  • x1: x coordinate of the line start.
  • y1: y coordinate of the line end.
  • pcolor: color parameter. Valid values :
    Value Description
    S1D13700_BLACK Black color.
    S1D13700_WHITE White color.
    S1D13700_INVERT Invert color.
Requires

Glcd module needs to be initialized. See the S1D13700_Init routine.

Example
S1D13700_Line(0, 0, 239, 127, S1D13700_WHITE);

S1D13700_H_Line

Prototype

void S1D13700_H_Line(unsigned int x_start, unsigned int x_end, unsigned int y_pos, unsigned short color);

Returns

Nothing.

Description

Draws a horizontal line.

Parameters :

  • x_start: x coordinate of the line start.
  • x_end: x coordinate of the line end.
  • y_pos: line position on the y axis.
  • pcolor: color parameter. Valid values :
    Value Description
    S1D13700_BLACK Black color.
    S1D13700_WHITE White color.
    S1D13700_INVERT Invert color.
Requires

Glcd module needs to be initialized. See the S1D13700_Init routine.

Example
S1D13700_Line(0, 0, 239, 127, S1D13700_WHITE);

S1D13700_V_Line

Prototype

void S1D13700_V_Line(unsigned int y_start, unsigned int y_end, unsigned int x_pos, unsigned short color);

Returns

Nothing.

Description

Draws a horizontal line.

Parameters :

  • y_start: y coordinate of the line start.
  • y_end: y coordinate of the line end.
  • x_pos: line position on the x axis.
  • pcolor: color parameter. Valid values :
    Value Description
    S1D13700_BLACK Black color.
    S1D13700_WHITE White color.
    S1D13700_INVERT Invert color.
Requires

Glcd module needs to be initialized. See the S1D13700_Init routine.

Example
S1D13700_Line(0, 0, 239, 127, S1D13700_WHITE);

S1D13700_Rectangle

Prototype

void S1D13700_Rectangle(unsigned int x0, unsigned int y0, unsigned int x1, unsigned int y1, unsigned char pcolor);

Returns

Nothing.

Description

Draws a rectangle on Glcd.

Parameters :

  • x0: x coordinate of the upper left rectangle corner.
  • y0: y coordinate of the upper left rectangle corner.
  • x1: x coordinate of the lower right rectangle corner.
  • y1: y coordinate of the lower right rectangle corner.
  • pcolor: color parameter. Valid values :
    Value Description
    S1D13700_BLACK Black color.
    S1D13700_WHITE White color.
    S1D13700_INVERT Invert color.
Requires

Glcd module needs to be initialized. See the S1D13700_Init routine.

Example
S1D13700_rectangle(20, 20, 219, 107, S1D13700_WHITE);

S1D13700_Box

Prototype

void S1D13700_Box(unsigned int x0, unsigned int y0, unsigned int x1, unsigned int y1, unsigned char pcolor);

Returns

Nothing.

Description

Draws a box on Glcd.

Parameters :

  • x0: x coordinate of the upper left box corner.
  • y0: y coordinate of the upper left box corner.
  • x1: x coordinate of the lower right box corner.
  • y1: y coordinate of the lower right box corner.
  • pcolor: color parameter. Valid values :
    Value Description
    S1D13700_BLACK Black color.
    S1D13700_WHITE White color.
    S1D13700_INVERT Invert color.
Requires

Glcd module needs to be initialized. See the S1D13700_Init routine.

Example
S1D13700_Box(0, 119, 239, 127, S1D13700_WHITE);

S1D13700_Rectangle_Round_Edges

Prototype

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

Returns

Nothing.

Description

Draws a rounded edge rectangle on Glcd.

Parameters :

  • x_upper_left: x coordinate of the upper left rectangle corner.
  • y_upper_left: y coordinate of the upper left rectangle corner.
  • x_bottom_right: x coordinate of the lower right rectangle corner.
  • y_bottom_right: y coordinate of the lower right rectangle corner.
  • round_radius: radius of the rounded edge.
  • pcolor: color parameter. Valid values :
    Value Description
    S1D13700_BLACK Black color.
    S1D13700_WHITE White color.
    S1D13700_INVERT Invert color.
Requires

Glcd module needs to be initialized. See the S1D13700_Init routine.

Example
S1D13700_Rectangle_Round_Edges(20, 20, 219, 107, 12, S1D13700_WHITE);

S1D13700_Rectangle_Round_Edges_Fill

Prototype

void S1D13700_Rectangle_Round_Edges_Fill(unsigned int x0, unsigned int y0, unsigned int x1, unsigned int y1, unsigned short round_radius, unsigned short color);

Returns

Nothing.

Description

Draws a filled rounded edge rectangle on Glcd.

Parameters :

  • x_upper_left: x coordinate of the upper left rectangle corner.
  • y_upper_left: y coordinate of the upper left rectangle corner.
  • x_bottom_right: x coordinate of the lower right rectangle corner.
  • y_bottom_right: y coordinate of the lower right rectangle corner.
  • round_radius: radius of the rounded edge.
  • pcolor: color parameter. Valid values :
    Value Description
    S1D13700_BLACK Black color.
    S1D13700_WHITE White color.
    S1D13700_INVERT Invert color.
Requires

Glcd module needs to be initialized. See the S1D13700_Init routine.

Example
S1D13700_Rectangle_Round_Edges_Fill(20, 20, 219, 107, 12, S1D13700_WHITE);

S1D13700_Circle

Prototype

void S1D13700_Circle(unsigned int x_center, unsigned int y_center, unsigned int radius, unsigned short color);

Returns

Nothing.

Description

Draws a circle on Glcd.

Parameters :

  • x_center: x coordinate of the circle center.
  • y_center: y coordinate of the circle center.
  • radius: radius size.
  • color: color parameter. Valid values :
    Value Description
    S1D13700_BLACK Black color.
    S1D13700_WHITE White color.
    S1D13700_INVERT Invert color.
Requires

Glcd module needs to be initialized. See the S1D13700_Init routine.

Example
S1D13700_Circle(120, 64, 110, S1D13700_WHITE);

S1D13700_Circle_Fill

Prototype

void S1D13700_Circle_Fill(unsigned int x_center, unsigned int y_center, unsigned int radius, unsigned short color);

Returns

Nothing.

Description

Draws a filled circle on Glcd.

Parameters :

  • x_center: x coordinate of the circle center.
  • y_center: y coordinate of the circle center.
  • radius: radius size.
  • color: color parameter. Valid values :
    Value Description
    S1D13700_BLACK Black color.
    S1D13700_WHITE White color.
    S1D13700_INVERT Invert color.
Requires

Glcd module needs to be initialized. See the S1D13700_Init routine.

Example
S1D13700_Circle_Fill(120, 64, 110, S1D13700_WHITE);

S1D13700_Image

Prototype

void S1D13700_Image(const code char *pic);

Returns

Nothing.

Description

Displays bitmap on Glcd.

Parameters :

  • image: image to be displayed. Bitmap array is located in code memory.
  Note : Image dimension must match the display dimension.
Requires

Glcd module needs to be initialized. See the S1D13700_Init routine.

Example
S1D13700_Image(image);

S1D13700_PartialImage

Prototype

void S1D13700_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);

Returns

Nothing.

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 is located in code memory.
  Note : Image dimension must match the display dimension.
Requires

Glcd module needs to be initialized. See the S1D13700_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. 
S1D13700_PartialImage(10, 12, 10, 15, 16, 32, image);
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