SPI T6963C Graphic Lcd Library
The mikroBasic PRO for 8051 provides a library for working with Glcds based on TOSHIBA T6963C controller via SPI interface. The Toshiba T6963C is a very popular Lcd controller for the use in small graphics modules. It is capable of controlling displays with a resolution up to 240x128. Because of its low power and small outline it is most suitable for mobile applications such as PDAs, MP3 players or mobile measurement equipment. Although this controller is small, it has a capability of displaying and merging text and graphics and it manages all interfacing signals to the displays Row and Column drivers.
For creating a custom set of Glcd images use Glcd Bitmap Editor Tool.
Note: The library uses the SPI module for communication. The user must initialize SPI module before using the SPI T6963C Glcd Library.
Note: This Library is designed to work with mikroElektronika's Serial Glcd 240x128 and 240x64 Adapter Boards pinout, see schematic at the bottom of this page for details.
Note: Some mikroElektronika's adapter boards have pinout different from T6369C datasheets. Appropriate relations between these labels are given in the table below:
Adapter Board | T6369C datasheet |
RS | C/D |
R/W | /RD |
E | /WR |
External dependencies of SPI T6963C Graphic Lcd Library
The implementation of SPI T6963C Graphic Lcd Library routines is based on Port Expander Library routines.
External dependencies are the same as Port Expander Library external dependencies.
Library Routines
- SPI_T6963C_Config
- SPI_T6963C_WriteData
- SPI_T6963C_WriteCommand
- SPI_T6963C_SetPtr
- SPI_T6963C_WaitReady
- SPI_T6963C_Fill
- SPI_T6963C_Dot
- SPI_T6963C_Write_Char
- SPI_T6963C_Write_Text
- SPI_T6963C_Line
- SPI_T6963C_Rectangle
- SPI_T6963C_Box
- SPI_T6963C_Circle
- SPI_T6963C_Image
- SPI_T6963C_Sprite
- SPI_T6963C_Set_Cursor
Note: The following low level library routines are implemented as macros. These macros can be found in the SPI_T6963C.h
header
file which is located in the SPI T6963C example projects folders.
- SPI_T6963C_ClearBit
- SPI_T6963C_SetBit
- SPI_T6963C_NegBit
- SPI_T6963C_DisplayGrPanel
- SPI_T6963C_DisplayTxtPanel
- SPI_T6963C_SetGrPanel
- SPI_T6963C_SetTxtPanel
- SPI_T6963C_PanelFill
- SPI_T6963C_GrFill
- SPI_T6963C_TxtFill
- SPI_T6963C_Cursor_Height
- SPI_T6963C_Graphics
- SPI_T6963C_Text
- SPI_T6963C_Cursor
- SPI_T6963C_Cursor_Blink
SPI_T6963C_Config
Prototype |
sub procedure SPI_T6963C_Config(dim width as word, dim height as byte, dim fntW as byte, dim DeviceAddress as byte, dim wr as byte, dim rd as byte, dim cd as byte, dim rst as byte) |
---|---|
Returns |
Nothing. |
Description |
Initalizes the Graphic Lcd controller. Parameters :
Display RAM organization: schematic: +---------------------+ /\ + GRAPHICS PANEL #0 + | + + | + + | + + | +---------------------+ | PANEL 0 + TEXT PANEL #0 + | + + \/ +---------------------+ /\ + GRAPHICS PANEL #1 + | + + | + + | + + | +---------------------+ | PANEL 1 + TEXT PANEL #1 + | + + | +---------------------+ \/ |
Requires |
The SPI module needs to be initialized. See the SPIx_Init and SPIx_Init_Advanced routines. |
Example |
' port expander pinout definition dim SPExpanderRST as sbit at P1_0bit dim SPExpanderCS sbit at P1_1_bit ... SPI1_Init_Advanced(MASTER_OSC_DIV4 OR CLK_IDLE_LOW OR IDLE_2_ACTIVE OR DATA_ORDER_MSB) SPI_T6963C_Config(240, 64, 8, 0, 0, 1, 3, 4) |
SPI_T6963C_WriteData
Prototype |
sub procedure SPI_T6963C_WriteData(dim Ddata as byte) |
---|---|
Returns |
Nothing. |
Description |
Writes data to T6963C controller via SPI interface. Parameters :
|
Requires |
Toshiba Glcd module needs to be initialized. See SPI_T6963C_Config routine. |
Example |
SPI_T6963C_WriteData(AddrL) |
SPI_T6963C_WriteCommand
Prototype |
sub procedure SPI_T6963C_WriteCommand(dim Ddata as byte) |
---|---|
Returns |
Nothing. |
Description |
Writes command to T6963C controller via SPI interface. Parameters :
|
Requires |
Toshiba Glcd module needs to be initialized. See SPI_T6963C_Config routine. |
Example |
SPI_T6963C_WriteCommand(SPI_T6963C_CURSOR_POINTER_SET) |
SPI_T6963C_SetPtr
Prototype |
sub procedure SPI_T6963C_SetPtr(dim p as word, dim c as byte) |
---|---|
Returns |
Nothing. |
Description |
Sets the memory pointer p for command c. Parameters :
|
Requires |
SToshiba Glcd module needs to be initialized. See SPI_T6963C_Config routine. |
Example |
SPI_T6963C_SetPtr(T6963C_grHomeAddr + start, T6963C_ADDRESS_POINTER_SET) |
SPI_T6963C_WaitReady
Prototype |
sub procedure SPI_T6963C_WaitReady() |
---|---|
Returns |
Nothing. |
Description |
Pools the status byte, and loops until Toshiba Glcd module is ready. |
Requires |
Toshiba Glcd module needs to be initialized. See SPI_T6963C_Config routine. |
Example |
SPI_T6963C_WaitReady() |
SPI_T6963C_Fill
Prototype |
sub procedure SPI_T6963C_Fill(dim v as byte, dim start as word, dim len as word) |
---|---|
Returns |
Nothing. |
Description |
Fills controller memory block with given byte. Parameters :
|
Requires |
Toshiba Glcd module needs to be initialized. See SPI_T6963C_Config routine. |
Example |
SPI_T6963C_Fill(0x33, 0x00FF, 0x000F) |
SPI_T6963C_Dot
Prototype |
sub procedure SPI_T6963C_Dot(dim x as integer, dim y as integer, dim color as byte) |
---|---|
Returns |
Nothing. |
Description |
Draws a dot in the current graphic panel of Glcd at coordinates (x, y). Parameters :
|
Requires |
Toshiba Glcd module needs to be initialized. See SPI_T6963C_Config routine. |
Example |
SPI_T6963C_Dot(x0, y0, pcolor) |
SPI_T6963C_Write_Char
Prototype |
sub procedure SPI_T6963C_Write_Char(dim c as byte, dim x as byte, dim y as byte, dim mode as byte) |
---|---|
Returns |
Nothing. |
Description |
Writes a char in the current text panel of Glcd at coordinates (x, y). Parameters :
Mode parameter explanation:
|
Requires |
Toshiba Glcd module needs to be initialized. See SPI_T6963C_Config routine. |
Example |
SPI_T6963C_Write_Char("A",22,23,AND) |
SPI_T6963C_Write_Text
Prototype |
sub procedure SPI_T6963C_Write_Text(dim str as ^byte, dim x as byte, dim y as byte, dim mode as byte) |
---|---|
Returns |
Nothing. |
Description |
Writes text in the current text panel of Glcd at coordinates (x, y). Parameters :
Mode parameter explanation:
|
Requires |
Toshiba Glcd module needs to be initialized. See SPI_T6963C_Config routine. |
Example |
SPI_T6963C_Write_Text("Glcd LIBRARY DEMO, WELCOME !", 0, 0, T6963C_ROM_MODE_EXOR) |
SPI_T6963C_Line
Prototype |
sub procedure SPI_T6963C_Line(dim x0 as integer, dim y0 as integer, dim x1 as integer, dim y1 as integer, dim pcolor as byte) |
---|---|
Returns |
Nothing. |
Description |
Draws a line from (x0, y0) to (x1, y1). Parameters :
|
Requires |
Toshiba Glcd module needs to be initialized. See SPI_T6963C_Config routine. |
Example |
SPI_T6963C_Line(0, 0, 239, 127, T6963C_WHITE) |
SPI_T6963C_Rectangle
Prototype |
sub procedure SPI_T6963C_Rectangle(dim x0 as integer, dim y0 as integer, dim x1 as integer, dim y1 as integer, dim pcolor as byte) |
---|---|
Returns |
Nothing. |
Description |
Draws a rectangle on Glcd. Parameters :
|
Requires |
Toshiba Glcd module needs to be initialized. See SPI_T6963C_Config routine. |
Example |
SPI_T6963C_Rectangle(20, 20, 219, 107, T6963C_WHITE) |
SPI_T6963C_Box
Prototype |
sub procedure SPI_T6963C_Box(dim x0 as integer, dim y0 as integer, dim x1 as integer, dim y1 as integer, dim pcolor as byte) |
---|---|
Returns |
Nothing. |
Description |
Draws a box on the Glcd Parameters :
|
Requires |
Toshiba Glcd module needs to be initialized. See SPI_T6963C_Config routine. |
Example |
SPI_T6963C_Box(0, 119, 239, 127, T6963C_WHITE) |
SPI_T6963C_Circle
Prototype |
sub procedure SPI_T6963C_Circle(dim x as integer, dim y as integer, dim r as longint, dim pcolor as byte) |
---|---|
Returns |
Nothing. |
Description |
Draws a circle on the Glcd. Parameters :
|
Requires |
Toshiba Glcd module needs to be initialized. See SPI_T6963C_Config routine. |
Example |
SPI_T6963C_Circle(120, 64, 110, T6963C_WHITE) |
SPI_T6963C_Image
Prototype |
sub procedure SPI_T6963C_image(const pic as ^byte) |
---|---|
Returns |
Nothing. |
Description |
Displays bitmap on Glcd. Parameters :
Use the mikroBasic’s integrated Glcd Bitmap Editor (menu option Tools › Glcd Bitmap Editor) to convert image to a constant array suitable for displaying on Glcd. |
Requires |
Toshiba Glcd module needs to be initialized. See SPI_T6963C_Config routine. |
Example |
SPI_T6963C_Image(my_image) |
SPI_T6963C_Sprite
Prototype |
sub procedure SPI_T6963C_sprite(dim px, py, sx, sy as byte, const pic as ^byte) |
---|---|
Returns |
Nothing. |
Description |
Fills graphic rectangle area (px, py) to (px+sx, py+sy) with custom size picture. Parameters :
Note: If |
Requires |
Toshiba Glcd module needs to be initialized. See SPI_T6963C_Config routine. |
Example |
SPI_T6963C_Sprite(76, 4, einstein, 88, 119) ' draw a sprite |
SPI_T6963C_Set_Cursor
Prototype |
sub procedure SPI_T6963C_set_cursor(dim x, y as byte) |
---|---|
Returns |
Nothing. |
Description |
Sets cursor to row x and column y. Parameters :
|
Requires |
Toshiba Glcd module needs to be initialized. See SPI_T6963C_Config routine. |
Example |
SPI_T6963C_Set_Cursor(cposx, cposy) |
SPI_T6963C_ClearBit
Prototype |
sub procedure SPI_T6963C_clearBit(dim b as byte) |
---|---|
Returns |
Nothing. |
Description |
Clears control port bit(s). Parameters :
|
Requires |
Toshiba Glcd module needs to be initialized. See SPI_T6963C_Config routine. |
Example |
' clear bits 0 and 1 on control port SPI_T6963C_ClearBit(0x03) |
SPI_T6963C_SetBit
Prototype |
sub procedure SPI_T6963C_setBit(dim b as byte) |
---|---|
Returns |
Nothing. |
Description |
Sets control port bit(s). Parameters :
|
Requires |
Toshiba Glcd module needs to be initialized. See SPI_T6963C_Config routine. |
Example |
' set bits 0 and 1 on control port SPI_T6963C_SetBit(0x03) |
SPI_T6963C_NegBit
Prototype |
sub procedure SPI_T6963C_negBit(dim b as byte) |
---|---|
Returns |
Nothing. |
Description |
Negates control port bit(s). Parameters :
|
Requires |
Toshiba Glcd module needs to be initialized. See SPI_T6963C_Config routine. |
Example |
' negate bits 0 and 1 on control port SPI_T6963C_NegBit(0x03) |
SPI_T6963C_DisplayGrPanel
Prototype |
sub procedure SPI_T6963C_DisplayGrPanel(dim n as byte) |
---|---|
Returns |
Nothing. |
Description |
Display selected graphic panel. Parameters :
|
Requires |
Toshiba Glcd module needs to be initialized. See SPI_T6963C_Config routine. |
Example |
' display graphic panel 1 SPI_T6963C_DisplayGrPanel(1) |
SPI_T6963C_DisplayTxtPanel
Prototype |
sub procedure SPI_T6963C_DisplayTxtPanel(dim n as byte) |
---|---|
Returns |
Nothing. |
Description |
Display selected text panel. Parameters :
|
Requires |
Toshiba Glcd module needs to be initialized. See SPI_T6963C_Config routine. |
Example |
' display text panel 1 SPI_T6963C_DisplayTxtPanel(1) |
SPI_T6963C_SetGrPanel
Prototype |
sub procedure SPI_T6963C_SetGrPanel(dim n as byte) |
---|---|
Returns |
Nothing. |
Description |
Compute start address for selected graphic panel and set appropriate internal pointers. All subsequent graphic operations will be preformed at this graphic panel. Parameters :
|
Requires |
Toshiba Glcd module needs to be initialized. See SPI_T6963C_Config routine. |
Example |
' set graphic panel 1 as current graphic panel. SPI_T6963C_SetGrPanel(1) |
SPI_T6963C_SetTxtPanel
Prototype |
sub procedure SPI_T6963C_SetTxtPanel(dim n as byte) |
---|---|
Returns |
Nothing. |
Description |
Compute start address for selected text panel and set appropriate internal pointers. All subsequent text operations will be preformed at this text panel. Parameters :
|
Requires |
Toshiba Glcd module needs to be initialized. See SPI_T6963C_Config routine. |
Example |
' set text panel 1 as current text panel. SPI_T6963C_SetTxtPanel(1) |
SPI_T6963C_PanelFill
Prototype |
sub procedure SPI_T6963C_PanelFill(dim v as byte) |
---|---|
Returns |
Nothing. |
Description |
Fill current panel in full (graphic+text) with appropriate value (0 to clear). Parameters :
|
Requires |
Toshiba Glcd module needs to be initialized. See SPI_T6963C_Config routine. |
Example |
clear current panel SPI_T6963C_PanelFill(0) |
SPI_T6963C_GrFill
Prototype |
sub procedure SPI_T6963C_GrFill(dim v as byte) |
---|---|
Returns |
Nothing. |
Description |
Fill current graphic panel with appropriate value (0 to clear). Parameters :
|
Requires |
Toshiba Glcd module needs to be initialized. See SPI_T6963C_Config routine. |
Example |
' clear current graphic panel SPI_T6963C_GrFill(0) |
SPI_T6963C_TxtFill
Prototype |
sub procedure SPI_T6963C_TxtFill(dim v as byte) |
---|---|
Returns |
Nothing. |
Description |
Fill current text panel with appropriate value (0 to clear). Parameters :
|
Requires |
Toshiba Glcd module needs to be initialized. See SPI_T6963C_Config routine. |
Example |
' clear current text panel SPI_T6963C_TxtFill(0) |
SPI_T6963C_Cursor_Height
Prototype |
sub procedure SPI_T6963C_Cursor_Height(dim n as byte) |
---|---|
Returns |
Nothing. |
Description |
Set cursor size. Parameters :
|
Requires |
Toshiba Glcd module needs to be initialized. See SPI_T6963C_Config routine. |
Example |
SPI_T6963C_Cursor_Height(7) |
SPI_T6963C_Graphics
Prototype |
sub procedure SPI_T6963C_Graphics(dim n as byte) |
---|---|
Returns |
Nothing. |
Description |
Enable/disable graphic displaying. Parameters :
|
Requires |
Toshiba Glcd module needs to be initialized. See SPI_T6963C_Config routine. |
Example |
' enable graphic displaying SPI_T6963C_Graphics(1) |
SPI_T6963C_Text
Prototype |
sub procedure SPI_T6963C_Text(dim n as byte) |
---|---|
Returns |
Nothing. |
Description |
Enable/disable text displaying. Parameters :
|
Requires |
Toshiba Glcd module needs to be initialized. See SPI_T6963C_Config routine. |
Example |
' enable text displaying SPI_T6963C_Text(1) |
SPI_T6963C_Cursor
Prototype |
sub procedure SPI_T6963C_Cursor(dim n as byte) |
---|---|
Returns |
Nothing. |
Description |
Set cursor on/off. Parameters :
|
Requires |
Toshiba Glcd module needs to be initialized. See SPI_T6963C_Config routine. |
Example |
' set cursor on SPI_T6963C_Cursor(1) |
SPI_T6963C_Cursor_Blink
Prototype |
sub procedure SPI_T6963C_Cursor_Blink(dim n as byte) |
---|---|
Returns |
Nothing. |
Description |
Enable/disable cursor blinking. Parameters :
|
Requires |
Toshiba Glcd module needs to be initialized. See SPI_T6963C_Config routine. |
Example |
' enable cursor blinking SPI_T6963C_Cursor_Blink(1) |
Library Example
The following drawing demo tests advanced routines of the SPI T6963C Glcd library. Hardware configurations in this example are made for the T6963C 240x128 display, Easy8051B board and AT89S8253.
program SPI_T6963C_240x128 include __Lib_SPIT6963C_Const ' Port Expander module connections dim SPExpanderRST as sbit at P1_0_bit SPExpanderCS as sbit at P1_1_bit ' End Port Expander module connections dim panel as byte ' current panel i as word ' general purpose register curs as byte ' cursor visibility cposx, cposy as word ' cursor x-y position txt, txt1 as string[29] idata '#DEFINE COMPLETE_EXAMPLE ' comment this line to make simpler/smaller example main: txt1 = " EINSTEIN WOULD HAVE LIKED mE" txt = " GLCD LIBRARY DEMO, WELCOME !" ' If SPI_T6963C Library uses SPI1 module SPI1_Init_Advanced(_SPI_FCY_DIV4 or _SPI_CLK_IDLE_LO or _SPI_CLK_IDLE_2_ACTIVE) ' Initialize SPI module ' ' If SPI_T6963C Library uses SPI2 module ' SPI2_Init_Advanced(_SPI_FCY_DIV4 or _SPI_CLK_IDLE_LO or _SPI_CLK_IDLE_2_ACTIVE) ' Initialize SPI module ' ' init display for 240 pixel width and 128 pixel height ' 8 bits character width ' data bus on MCP23S17 portB ' control bus on MCP23S17 portA ' bit 2 is !WR ' bit 1 is !RD ' bit 0 is !CD ' bit 4 is RST ' chip enable, reverse on, 8x8 font internaly set in library ' SPI_T6963C_Config(240, 128, 8, 0, 2, 1, 0, 4) Delay_ms(1000) ' ' Enable both graphics and text display at the same time ' SPI_T6963C_graphics(1) SPI_T6963C_text(1) panel = 0 i = 0 curs = 0 cposy = 0 cposx = 0 ' ' Text messages ' SPI_T6963C_write_text(txt, 0, 0, SPI_T6963C_ROM_MODE_XOR) SPI_T6963C_write_text(txt1, 0, 15, SPI_T6963C_ROM_MODE_XOR) ' ' Cursor ' SPI_T6963C_cursor_height(8) ' 8 pixel height SPI_T6963C_set_cursor(0, 0) ' move cursor to top left SPI_T6963C_cursor(0) ' cursor off '#IFDEF COMPLETE_EXAMPLE ' ' Draw rectangles ' SPI_T6963C_rectangle(0, 0, 239, 127, SPI_T6963C_WHITE) SPI_T6963C_rectangle(20, 20, 219, 107, SPI_T6963C_WHITE) SPI_T6963C_rectangle(40, 40, 199, 87, SPI_T6963C_WHITE) SPI_T6963C_rectangle(60, 60, 179, 67, SPI_T6963C_WHITE) ' ' Draw a cross ' SPI_T6963C_line(0, 0, 239, 127, SPI_T6963C_WHITE) SPI_T6963C_line(0, 127, 239, 0, SPI_T6963C_WHITE) ' ' Draw solid boxes ' SPI_T6963C_box(0, 0, 239, 8, SPI_T6963C_WHITE) SPI_T6963C_box(0, 119, 239, 127, SPI_T6963C_WHITE) ' ' Draw circles ' SPI_T6963C_circle(120, 64, 10, SPI_T6963C_WHITE) SPI_T6963C_circle(120, 64, 30, SPI_T6963C_WHITE) SPI_T6963C_circle(120, 64, 50, SPI_T6963C_WHITE) SPI_T6963C_circle(120, 64, 70, SPI_T6963C_WHITE) SPI_T6963C_circle(120, 64, 90, SPI_T6963C_WHITE) SPI_T6963C_circle(120, 64, 110, SPI_T6963C_WHITE) SPI_T6963C_circle(120, 64, 130, SPI_T6963C_WHITE) SPI_T6963C_sprite(76, 4, @einstein, 88, 119) ' Draw a sprite SPI_T6963C_setGrPanel(1) ' Select other graphic panel SPI_T6963C_image(@mikroE_240x128_bmp) ' Fill the graphic screen with a picture '#ENDIF while TRUE ' Endless loop ' ' If P0_0 is pressed, toggle the display between graphic panel 0 and graphic 1 ' if ( P0_0_bit = 0) then SPI_T6963C_graphics(1) SPI_T6963C_text(0) Delay_ms(300) '#IFDEF COMPLETE_EXAMPLE ' ' If P0_1 is pressed, display only graphic panel ' else if ( P0_1_bit = 0) then Inc(panel) panel = panel and 1 SPI_T6963C_displayGrPanel(panel) Delay_ms(300) '#ENDIF ' ' If P0_2 is pressed, display only text panel ' else if ( P0_2_bit = 0) then SPI_T6963C_graphics(0) SPI_T6963C_text(1) Delay_ms(300) ' ' If P0_3 is pressed, display text and graphic panels ' else if( P0_3_bit = 0) then SPI_T6963C_graphics(1) SPI_T6963C_text(1) Delay_ms(300) ' ' If P0_4 is pressed, change cursor ' else if ( P0_4_bit = 0) then Inc(curs) if (curs = 3) then curs = 0 end if select case curs case 0 ' No cursor SPI_T6963C_cursor(0) case 1 ' Blinking cursor SPI_T6963C_cursor(1) SPI_T6963C_cursor_blink(1) case 2 ' Non blinking cursor SPI_T6963C_cursor(1) SPI_T6963C_cursor_blink(0) end select Delay_ms(300) end if end if end if end if end if ' ' Move cursor, even if not visible ' Inc(cposx) if(cposx = SPI_T6963C_txtCols) then cposx = 0 cposy = cposy + 1 if(cposy = (128 div SPI_T6963C_CHARACTER_HEIGHT)) then ' if y end cposy = 0 ' grafic height (128) div character height end if SPI_T6963C_set_cursor(cposx, cposy) Delay_ms(100) end if wend end.
HW Connection
SPI T6963C Glcd HW connection
What do you think about this topic ? Send us feedback!