KS0108 Controllers

This section covers GLCD devices that use the KS0108 graphics controller.

The KS0108 is an LCD is driven by on-board 5V parallel interface chipset KS0108 and KS0107. They are extremely common and well documented

The Great Cow BASIC constants shown below control the configuration of the KS0108 controller.    The only connectivity option is the 8-bit mode where 8 connections (for the data) are required between the microcontroller and the GLCD to control the data bus.

The SH1106 is a monochrome device.

To use the KS0108 driver simply include the following in your user code. This will initialise the driver.

    #include <glcd.h>
    #DEFINE GLCD_TYPE GLCD_TYPE_KS0108


    #define GLCD_RW       PORTB.1            'chip specific configuration
    #define GLCD_RESET    PORTB.5            'chip specific configuration
    #define GLCD_CS1      PORTB.3            'chip specific configuration
    #define GLCD_CS2      PORTB.4            'chip specific configuration
    #define GLCD_RS       PORTB.0            'chip specific configuration
    #define GLCD_ENABLE   PORTB.2            'chip specific configuration
    #define GLCD_DB0      PORTC.7            'chip specific configuration
    #define GLCD_DB1      PORTC.6            'chip specific configuration
    #define GLCD_DB2      PORTC.5            'chip specific configuration
    #define GLCD_DB3      PORTC.4            'chip specific configuration
    #define GLCD_DB4      PORTC.3            'chip specific configuration
    #define GLCD_DB5      PORTC.2            'chip specific configuration
    #define GLCD_DB6      PORTC.1            'chip specific configuration
    #define GLCD_DB7      PORTC.0            'chip specific configuration

The Great Cow BASIC constants for the interface to the controller are shown in the table below.

Constants Controls Options

GLCD_TYPE

GLCD_TYPE_KS0108

 

GLCD_RS

Specifies the output pin that is connected to Register Select on the GLCD.

Required

GLCD_RW

Specifies the output pin that is connected to Read/Write on the GLCD. The R/W pin can be disabled.

Must be defined (unless R/W is disabled)
see
GLCD_NO_RW

GLCD_CS1

Specifies the output pin that is connected to CS1 on the GLCD.

Required

GLCD_CS2

Specifies the output pin that is connected to CS2 on the GLCD.

Required

GLCD_ENABLE

Specifies the output pin that is connected to Enable on the GLCD.

Required

GLCD_DB0

Specifies the output pin that is connected to DB0 on the GLCD.

Required

GLCD_DB1

Specifies the output pin that is connected to DB1 on the GLCD.

Required

GLCD_DB2

Specifies the output pin that is connected to DB2 on the GLCD.

Required

GLCD_DB3

Specifies the output pin that is connected to DB3 on the GLCD.

Required

GLCD_DB4

Specifies the output pin that is connected to DB4 on the GLCD.

Required

GLCD_DB5

Specifies the output pin that is connected to DB5 on the GLCD.

Required

GLCD_DB6

Specifies the output pin that is connected to DB6 on the GLCD.

Required

GLCD_DB7

Specifies the output pin that is connected to DB7 on the GLCD.

Required

GLCD_NO_RW

Disables read/write inspection of the device during read/write operations

Optional, but recommend NOT to set. The R/W pin can be disabled by setting the GLCD_NO_RW constant. If this is done, there is no need for the R/W to be connected to the chip, and no need for the LCD_RW constant to be set. Ensure that the R/W line on the LCD is connected to ground if not used.

GLCD_DATA_PORT

Not Available for this controller.

Not applicable.

The Great Cow BASIC constants defined for the controller type are shown in the table below.

Constants Controls Default

GLCD_WIDTH

The width parameter of the GLCD

128 This constant cannot be changed

GLCD_HEIGHT

The height parameter of the GLCD

64 This constant cannot be changed

GLCDDirection

Defining this will invert the Y Axis

Not defined

KS0108ReadDelay

Read delay

Default is 9

Can be set to improve overall performance.

KS0108WriteDelay

Write delay

Default is 1

Can be set to improve performance.

KS0108ClockDelay

Clock Delay

Default is 1

Can be set to improve performance.

The Great Cow BASIC constants for control display characteristics are shown in the table below.

Variables Controls Default

GLCDFontWidth

Width of the current GLCD font.

Default is 6 pixels.

GLCDfntDefault

Size of the current GLCD font.

Default is 0.

This equates to the standard GCB font set.

GLCDfntDefaultsize

Size of the current GLCD font.

Default is 1.

This equates to the 8 pixel high.

The Great Cow BASIC commands supported for this GLCD are shown in the table below.

Command Purpose Example

GLCDCLS

Clear screen of GLCD

GLCDCLS

GLCDPrint

Print string of characters on GLCD using GCB font set

GLCDPrint( Xposition, Yposition, Stringvariable )

GLCDDrawChar

Print character on GLCD using GCB font set

GLCDDrawChar( Xposition, Yposition, CharCode )

GLCDDrawString

Print characters on GLCD using GCB font set

GLCDDrawString( Xposition, Yposition, Stringvariable )

Box

Draw a box on the GLCD to a specific size

Box ( Xposition1, Yposition1, Xposition2, Yposition2, [Optional In LineColour as 0 or 1] )

FilledBox

Draw a box on the GLCD to a specific size that is filled with the foreground colour.

FilledBox (Xposition1, Yposition1, Xposition2, Yposition2, [Optional In LineColour 0 or 1] )

Line

Draw a line on the GLCD to a specific length that is filled with the specific attribute.

Line ( Xposition1, Yposition1, Xposition2, Yposition2, [Optional In LineColour 0 or 1] )

PSet

Set a pixel on the GLCD at a specific position that is set with the specific attribute.

PSet(Xposition, Yposition, Pixel Colour 0 or 1)

GLCDWriteByte

Set a byte value to the controller, see the datasheet for usage.

GLCDWriteByte ( LCDByte)

GLCDReadByte

Read a byte value from the controller, see the datasheet for usage.

bytevariable = GLCDReadByte

For a KS0108 datasheet, please refer here.

This example shows how to drive a KS0108 based Graphic LCD module with the built in commands of Great Cow BASIC. See Graphic LCD for details, this is an external web site.

    ;Chip Settings
    #chip 16F886,16
    '#config MCLRE = on 'enable reset switch on CHIPINO
    #include <GLCD.h>

    ;Defines (Constants)
    #define GLCD_RW PORTB.1  'D9 to pin 5 of LCD
    #define GLCD_RESET PORTB.5 'D13 to pin 17 of LCD
    #define GLCD_CS1 PORTB.3 'D12 to actually since CS1, CS2 can be reversed on some devices
    #define GLCD_CS2 PORTB.4 'D11 to actually since CS1, CS2 can be reversed on some devices
    #define GLCD_RS PORTB.0  'D8 to pin 4 D/I pin on LCD
    #define GLCD_ENABLE PORTB.2 'D10 to Pin 6 on LCD
    #define GLCD_DB0 PORTC.7 'D0 to pin 7 on LCD
    #define GLCD_DB1 PORTC.6 'D1 to pin 8 on LCD
    #define GLCD_DB2 PORTC.5 'D2 to pin 9 on LCD
    #define GLCD_DB3 PORTC.4 'D3 to pin 10 on LCD
    #define GLCD_DB4 PORTC.3 'D4 to pin 11 on LCD
    #define GLCD_DB5 PORTC.2 'D5 to pin 12 on LCD
    #define GLCD_DB6 PORTC.1 'D6 to pin 13 on LCD
    #define GLCD_DB7 PORTC.0 'D7 to pin 14 on LCD

    Do forever
        GLCDCLS
        GLCDPrint 0,10,"Hello" 'Print Hello
        wait 5 s
        GLCDPrint 0,10, "ASCII #:" 'Print ASCII #:
        Box 18,30,28,40                    'Draw Box Around ASCII Character
        for char = 15 to 129            'Print 0 through 9
          GLCDPrint 17, 20 , Str(char)+"  "
          GLCDdrawCHAR 20,30, char
          wait 125 ms
        next
        line 0,50,127,50                'Draw Line using line command
        for xvar = 0 to 80            'draw line using Pset command
            pset xvar,63,on                    '
        next                                        '
        Wait 1 s
        GLCDPrint 0,10,"End  " 'Print Hello
        wait 1 s
    Loop

For more help, see GLCDCLS, GLCDDrawChar, GLCDPrint, GLCDReadByte, GLCDWriteByte or Pset

Supported in <GLCD.H>