Epson S1D13700 Graphic Lcd Library

The mikroPascal PRO for dsPIC30/33 and PIC24 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 :
var S1D13700_DATA : byte; sfr; external; System data bus. var S1D13700_DATA at PORTD;
var S1D13700_WR : sbit; sfr; external; Write signal. var S1D13700_WR : sbit at LATC2_bit;
var S1D13700_RD : sbit; sfr; external; Read signal. var S1D13700_RD : sbit at LATC1_bit;
var S1D13700_A0 : sbit; sfr; external; System Address pin. var S1D13700_A0 : sbit at LATC0_bit;
var S1D13700_RES : sbit; sfr; external; Reset signal. var S1D13700_RES : sbit at LATC3_bit;
var S1D13700_CS : sbit; sfr; external; Chip select. var S1D13700_CS : sbit at LATC4_bit;
var S1D13700_DATA_Direction : byte; sfr; external; Direction of the system data bus pins. var S1D13700_DATA_Direction sbit at PORTD;
var S1D13700_WR_Direction : sbit; sfr; external; Direction of the Write pin. var S1D13700_WR_Direction : sbit at TRISC2_bit;
var S1D13700_RD_Direction : sbit; sfr; external; Direction of the Read pin. var S1D13700_RD_Direction : sbit at TRISC1_bit;
var S1D13700_A0_Direction : sbit; sfr; external; Direction of the System Address pin. var S1D13700_A0_Direction : sbit at TRISC0_bit;
var S1D13700_RES_Direction : sbit; sfr; external; Direction of the Reset pin. var S1D13700_RES_Direction : sbit at TRISC3_bit;
var S1D13700_CS_Direction : sbit; sfr; external; Direction of the Chip select pin. var S1D13700_CS_Direction : sbit at TRISC4_bit;

Library Routines

S1D13700_Init

Prototype

procedure S1D13700_Init(width : word; height : word);

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
var S1D13700_Data_Port : byte at PORTD;
var S1D13700_WR : sbit at LATC2_bit;
var S1D13700_RD : sbit at LATC1_bit;
var S1D13700_A0 : sbit at LATC0_bit;
var S1D13700_RES : sbit at LATC3_bit;
var S1D13700_CS : sbit at LATC4_bit;

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

S1D13700_Write_Command

Prototype

procedure S1D13700_Write_Command(command : byte);

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

procedure S1D13700_Write_Parameter(parameter : byte);

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

function S1D13700_Read_Parameter() : byte;

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

procedure S1D13700_Fill(d : byte; start : word; len : word);

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

procedure S1D13700_GrFill(d : byte);

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

procedure S1D13700_TxtFill(d : byte);

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

<procedure S1D13700_Display_GrLayer(mode : byte);

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

procedure S1D13700_Display_TxtLayer(mode : byte);

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

procedure S1D13700_Set_Cursor(width : byte; height : byte; mode : byte);

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

procedure S1D13700_Display_Cursor(mode : byte);

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

procedure S1D13700_Write_Char(c : char; x : word; y : word; mode: byte);

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

procedure S1D13700_Write_Text(var str : string; x, y : word; mode : byte);

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

procedure S1D13700_Dot(x : word; y : word; color : byte);

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

procedure S1D13700_Line(x0, y0, x1, y1 : word; pcolor : byte);

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

procedure S1D13700_H_Line(x_start, x_end, y_pos : word; color : byte);

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

procedure S1D13700_V_Line(y_start, y_end, x_pos : word; color : byte);

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

procedure S1D13700_Rectangle(x0, y0, x1, y1 : word; pcolor : byte);

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

procedure S1D13700_Box(x0, y0, x1, y1 : word; pcolor : byte);

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

procedure S1D13700_Rectangle_Round_Edges(x_upper_left : word; y_upper_left : word; x_bottom_right : word; y_bottom_right : word; round_radius : word; color : byte);

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

procedure S1D13700_Rectangle_Round_Edges_Fill(x_upper_left : word; y_upper_left : word; x_bottom_right : word; y_bottom_right : word; round_radius : word; color : byte);

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

procedure S1D13700_Circle(x_center : word; y_center : word; radius : word; color : byte);

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

procedure S1D13700_Circle_Fill(x_center: word; y_center: word; radius: word; color : byte);

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

procedure S1D13700_Image(const image : ^byte);

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

procedure S1D13700_PartialImage(x_left, y_top, width, height, picture_width, picture_height : word; const image : ^byte);

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