T6963c

Hello, this is a pre-version of a Toshiba T6963c GLCD driver module.

What's not handled:

- Text mode of the T6963c hardware driver is not handled (in this preversion) - this module does not take advantage of the large external RAM associated with T6963c chip to provide multipaging (full version provide this).

All these points are already implemented and will be provided in the full version (under test and will replace this one soon).

With actual pre-version, all Swordfish GLCD graphics primitives and fonts are rendered correctly.

I hope you can find this helpfull.

For any comment, or feedback (or bug report), please post to Swordfish Forum.

VERY IMPORTANT NOTICE concerning Swordfish GLCD module:

In order to integrate the T6963c module in Swordfish Basic GLCD library, the GLCD.BAS file (\Library\GLCD\glcd.bas) has been modified. This modification is mandatory to register the T6963c driver.

The modified version of the GLCD.BAS module is also published at the END of this article.

Example program

{
*************************************************************************
*  Name    : Test_T6963c.BAS                                            *
*  Author  : Ahmed Lazreg  ([email protected])                         *
*            http://www.pocketmt.com                                    *
*  Notice  : Copyright (c) 2006 Pocket MicroTechnics                    *
*          : All Rights Reserved                                        *
*  Date    : 01/03/2008                                                 *
*  Version : 1.0                                                        *
*  Modified:                                                            *
*                                                                       *
*************************************************************************
}
Program Test_T6963c

Device = 18F452
Clock  = 20

#option GLCD_MODEL = T6963c   '<<<********* Select Toshiba driver

#option GLCD_DATA = PORTD        // data port
#option GLCD_CE  = PORTC.3        // chip Enable
#option GLCD_RD  = PORTC.5        // RD pin
#option GLCD_RW  = PORTC.4        // RW pin 
#option GLCD_CD  = PORTC.6        // Command/Data   High=Cmd , Low=Data
#option GLCD_RST = PORTC.7       // reset pin


Include "utils.bas"
Include "Graphics.bas"
Include "GLCD.bas"

Include "FixedFont.bas"
Include "Arial.bas"
Include "Garamond.bas"
Include "Tahoma.bas"
Include "Verdana.bas"
Include "Times.bas"
'Include "SimSunFont.bas"   '<*** Unicode Chinese font bloc 

SetAllDigital()

GLCD.Cls	

GLCD.WriteAt(4,5,"System Font")

GLCD.SetFont(ArialBold)
GLCD.WriteAt(4,11,"Arial Font")
GLCD.SetFont(GaramondBold)
GLCD.WriteAt(4,20,"Garamond Font")
GLCD.SetFont(TahomaBold)
GLCD.WriteAt(4,30,"Tahoma Font")
GLCD.SetFont(VerdanaBold)
GLCD.WriteAt(4,40,"Verdana Font")
GLCD.SetFont(TimesNewRomanBold)
GLCD.WriteAt(4,50,"Times New Roman")

GLCD.WriteAt(4,68,"Full UNICODE Support in")
GLCD.WriteAt(4,78,"SWordFish BASIC with")
GLCD.SetFont(TahomaBold)
GLCD.WriteAt(4,88,"GLCD Font Creator 2")

Line(160,1,200,40)
Circle(200,60,38)
Rectangle(160,10,220,80)

Module Code

Important Note:

The T6963c module contains a sub named xDelay().

Sub xDelay()
  'DelayUS(1)
  ASM
    Nop
    Nop
    Nop
  End ASM
End Sub

This sub introduces needed delays for the T6963c hardware driver. For my own hardware driver (display bought from MikroE shop), I needed for 1 NOP only at 20MHz clock. Feel free to add additional NOP if needed. For very slow displays, and high PIC clock frequencies, you can completely remove the NOP and replace it with DelayUS(nn) with needed nn delay value.

{
*************************************************************************
*  Name    : T6963c.BAS                                                 *
*  Author  : Ahmed Lazreg  ([email protected])                         *
*            http://www.pocketmt.com                                    *
*  Notice  : Copyright (c) 2006 Pocket MicroTechnics                    *
*          : All Rights Reserved                                        *
*  Date    : 01/03/2008                                                 *
*  Version : 1.0                                                        *
*  Modified:                                                            *
*  Notes   : This module handles Toshiba T6963c GLCD drivera            *
*                                                                       *
*************************************************************************
}

Module T6963c

#define GLCD_PIXEL_08
#define GLCD_COLOR_01
#define GLCD_XY_16

Include "Graphics.bas"   
Include "system.bas"
Include "utils.bas"

#option GLCD_DATA = PORTD        // data port
#option GLCD_CE  = PORTC.3        // chip Enable
#option GLCD_RD  = PORTC.5        // RD pin
#option GLCD_RW  = PORTC.4        // RW pin 
#option GLCD_CD  = PORTC.6        // Command/Data   High=Cmd , Low=Data
#option GLCD_RST = PORTC.7       // reset pin

#option GLCD_ASPECT_RATIO = 100  // aspect ratio, smaller number will squeeze y for GLCD circles and box
#option GLCD_INIT_DELAY = 100    // initialisation delay (ms)

// validate data port...
#if IsOption(GLCD_DATA) 
   #if Not IsValidPort(GLCD_DATA)
      #error GLCD_DATA, "Invalid option. DATA must be a valid port name."
   #endif
   #ifdef GLCD_DATA@ Then
      #error GLCD_DATA@, "Invalid option. DATA port cannot be a single bit value."
   #endif
#endif

// validate EN pin...
#if IsOption(GLCD_EN) And Not IsValidPortPin(GLCD_EN) 
   #error GLCD_EN, "Invalid option. EN must be a valid port pin."
#endif

// validate RD pin...
#if IsOption(GLCD_RD) And Not IsValidPortPin(GLCD_RD) 
   #error GLCD_RD, "Invalid option. RD must be a valid port pin."
#endif

// validate RW pin...
#if IsOption(GLCD_RW) And Not IsValidPortPin(GLCD_RW) 
   #error GLCD_RW, "Invalid option. RW must be a valid port pin."
#endif

// validate CD pin...
#if IsOption(GLCD_CD) And Not IsValidPortPin(GLCD_CD) 
   #error GLCD_CD, "Invalid option. CD must be a valid port pin."
#endif

// validate RST pin...
#if IsOption(GLCD_RST) And Not IsValidPortPin(GLCD_RST) 
   #error GLCD_RST, "Invalid option. RST must be a valid port pin."
#endif

// validate initialisation delay...
#if IsOption(GLCD_INIT_DELAY)
   #if Not (GLCD_INIT_DELAY in (0 to 1000))
      #error GLCD_INIT_DELAY, "Invalid option. GLCD initialize delay must be between 0 and 1000 (ms)."
   #endif
#endif 

// now create Data TRIS...
#option _GLCD_DATA_TRIS = GetTRIS(GLCD_DATA)

Public Const
   GLCDWidth = 240,
   GLCDHeight = 128

Const GLCD_NUMBER_OF_LINES = GLCDHeight
Const GLCD_PIXELS_PER_LINE= GLCDWidth
Const GLCD_FONT_WIDTH = 8

Const GLCD_GRAPHIC_AREA As Word=(GLCD_PIXELS_PER_LINE / GLCD_FONT_WIDTH)
Const GLCD_TEXT_AREA As Word = (GLCD_PIXELS_PER_LINE / GLCD_FONT_WIDTH)
Const GLCD_GRAPHIC_SIZE  As Word = (GLCD_GRAPHIC_AREA * GLCD_NUMBER_OF_LINES)
Const GLCD_TEXT_SIZE  As Word = (GLCD_TEXT_AREA * (GLCD_NUMBER_OF_LINES/8))


Const GLCD_TEXT_HOME As Word = 0
Const GLCD_GRAPHIC_HOME As Word = (GLCD_TEXT_HOME + GLCD_TEXT_SIZE)
Const GLCD_OFFSET_REGISTER = 2
Const GLCD_EXTERNAL_CG_HOME =(GLCD_OFFSET_REGISTER << 11)
Const GLCD_EXTERNAL_CG_SIZE = $FF


Const T6963_SET_CURSOR_POINTER = $21
Const T6963_SET_OFFSET_REGISTER = $22
Const T6963_SET_ADDRESS_POINTER = $24

Const T6963_SET_TEXT_HOME_ADDRESS = $40
Const T6963_SET_TEXT_AREA = $41
Const T6963_SET_GRAPHIC_HOME_ADDRESS =$42
Const T6963_SET_GRAPHIC_AREA  = $43

Const T6963_MODE_SET = $80


Const T6963_DISPLAY_MODE = $90
Const T6963_CURSOR_BLINK_ON = $01
Const T6963_CURSOR_DISPLAY_ON = $02
Const T6963_TEXT_DISPLAY_ON = $04
Const T6963_GRAPHIC_DISPLAY_ON = $08    

Const T6963_CURSOR_PATTERN_SELECT = $A0
Const T6963_CURSOR_1_LINE  = $00
Const T6963_CURSOR_2_LINE  = $01
Const T6963_CURSOR_3_LINE  = $02
Const T6963_CURSOR_4_LINE  = $03
Const T6963_CURSOR_5_LINE  = $04
Const T6963_CURSOR_6_LINE  = $05
Const T6963_CURSOR_7_LINE  = $06
Const T6963_CURSOR_8_LINE  = $07

Const T6963_SET_DATA_AUTO_WRITE = $B0
Const T6963_SET_DATA_AUTO_READ = $B1
Const T6963_AUTO_RESET   = $B2

Const T6963_DATA_WRITE_AND_INCREMENT = $C0
Const T6963_DATA_READ_AND_INCREMENT = $C1
Const T6963_DATA_WRITE_AND_DECREMENT = $C2
Const T6963_DATA_READ_AND_DECREMENT = $C3
Const T6963_DATA_WRITE_AND_NONVARIALBE = $C4
Const T6963_DATA_READ_AND_NONVARIABLE = $C5

Const T6963_SCREEN_PEEK = $E0
Const T6963_SCREEN_COPY = $E8

Const T6963_CD_COMMAND = 1,
      T6963_CD_Data    = 0  

// x, y position structure...   
Public Structure TPositionT6963
   x As TXY
   y As Byte
End Structure

// x, y position...
Public Dim
   Pos As TPositionT6963

Structure T6963Status_Struct
  STATUS As Byte
  blink As STATUS.7
  error As STATUS.6
  clr As STATUS.5
  dummyFiller As STATUS.4
  dawrdy As STATUS.3
  darrdy As STATUS.2
  busy2 As STATUS.1
  busy1 As STATUS.0
End Structure

Dim        
   Data As GLCD_DATA,           // data in (PORT) 
   TRISData As _GLCD_DATA_TRIS, // data TRIS
   CE As GLCD_CE.GLCD_CE@,      // EN pin - enable (serves as a strobe) - 6800 mode
   RD As GLCD_RD.GLCD_RD@,      // RD pin - read when L - 8080 mode
   RW As GLCD_RW.GLCD_RW@,      // RW pin - read or write (0 = write, 1 = read) - 6800 mode
   CD As GLCD_CD.GLCD_CD@,      // CD pin - write when L - 8080 mode
   RST As GLCD_RST.GLCD_RST@    // RES pin - normally RES = 1 but pull to 0 for initialization

{Sub xDelay()
Dim i As Byte
For i = 1 To 4
  ASM nop End ASM
Next}
inline Sub xDelay()
  'DelayUS(1)
  ASM
    Nop
    Nop
    Nop
  End ASM
End Sub

Sub WaitForIdle()
   Dim Timeout As Byte
   Dim tmp As Byte
   Timeout = $FF 
   TRISData = $FF     // set data bus to input
   CD = 1 
   Repeat
      ClrWDT
      RD = 0
      CE = 0
      xDelay()
      ClrWDT     
      tmp = Data
      xDelay()
      CE = 1
      RD = 1
      Dec(Timeout)      
   Until ((tmp And $03)= $03) Or (Timeout = 0)
End Sub 

Sub WriteByte(pDataByte As Byte, pCD As Byte)
    WaitForIdle()
    TRISData = $00
    CD = pCD
    RD = 1
    Data = pDataByte
    xDelay()
    RW = 0
    CE = 0
    xDelay()
    CE = 1
    RW = 1    
End Sub

Sub SetData(pData As Byte)
  WriteByte(pData, T6963_CD_Data)
End Sub

Function ReadData() As Byte
    Dim tmp As Byte
    WaitForIdle()
    TRISData = $FF
    CD = 0
    RD = 0    
    CE = 0
    xDelay()
    result = Data
    xDelay()
    CE = 1
    RD = 1
    CD = 1
End Function

Sub Command(pCmd As Byte)
  WriteByte(pCmd, T6963_CD_COMMAND)
End Sub

Sub CommandBParam(pCmd As Byte, pParam As Byte)
  SetData(pParam)
  Command(pCmd)
End Sub

Sub CommandWParam(pCmd As Byte, pParam As Word)
  SetData(pParam.Byte0)
  SetData(pParam.Byte1)
  Command(pCmd)
End Sub

Sub FillMemRegion(pBaseAddr As Word, pSize As Word, pData As Byte = $00)
    Dim i As Word
    CommandWParam(T6963_SET_ADDRESS_POINTER, pBaseAddr)
    For i = 0 To pSize-1 
      CommandBParam(T6963_DATA_WRITE_AND_INCREMENT, pData)
    Next
End Sub

Public Sub ClearGraphic(pBytePattern As Byte = $00)
    FillMemRegion(GLCD_GRAPHIC_HOME, GLCD_GRAPHIC_SIZE, pBytePattern)
End Sub

Public Sub ClearText(pChar As Byte = $00)
    FillMemRegion(GLCD_TEXT_HOME, GLCD_TEXT_SIZE, pChar)
End Sub

Sub ClearCG(pChar As Byte = $00)
    FillMemRegion(GLCD_EXTERNAL_CG_HOME, GLCD_EXTERNAL_CG_SIZE, pChar)
End Sub

Public Sub T6963WriteChar(pChar As Byte)
    CommandBParam(T6963_DATA_WRITE_AND_INCREMENT, pChar-32)
End Sub

Public Sub T6963WriteStr(pStr As String)
   FSR0 = @pStr
   While INDF0 <> 0
      T6963WriteChar(POSTINC0)
   Wend
End Sub

Public Sub GoToXY(pX As Byte, pY As Byte)
  Dim addr As Word
  addr = GLCD_TEXT_HOME +  pX + (GLCD_TEXT_AREA * pY)
  CommandWParam(T6963_SET_ADDRESS_POINTER, addr)
End Sub

Public Sub Cls()
  ClearGraphic()
  ClearText()
End Sub

Public Sub SetPixel(pX, pY As TXY)
  Dim tmp As Byte
  Dim addr As Word

  addr = GLCD_GRAPHIC_HOME + (pX / GLCD_FONT_WIDTH) + (GLCD_GRAPHIC_AREA * pY)
  CommandWParam(T6963_SET_ADDRESS_POINTER, addr)

  Command(T6963_DATA_READ_AND_NONVARIABLE)

  tmp = ReadData()

  If Pen.Color = 0 Then
    tmp = tmp And (Not (1 <<  (GLCD_FONT_WIDTH - 1 - (pX Mod GLCD_FONT_WIDTH))))
  Else
    tmp = tmp Or (1 <<  (GLCD_FONT_WIDTH - 1 - (pX Mod GLCD_FONT_WIDTH)))
  EndIf

  CommandBParam(T6963_DATA_WRITE_AND_INCREMENT, tmp)
End Sub

Public Sub Initialize()
 Dim i As Word

 Output(RD)
 Output(RW)
 Output(CD)
 Output(CE)

 RD = 1
 RW = 1
 CD = 1
 CE = 1
 RST = 1

 TRISData = $00
 Data = $00

#if IsOption(GLCD_RST) 
  Output(RST)
  RST = 0
  DelayMS(100)
  RST = 1
#endif

  Pos.x = 0
  Pos.y = 0  

  CommandWParam(T6963_SET_GRAPHIC_HOME_ADDRESS, GLCD_GRAPHIC_HOME)
  CommandWParam(T6963_SET_GRAPHIC_AREA, GLCD_GRAPHIC_AREA)

  CommandWParam(T6963_SET_TEXT_HOME_ADDRESS, GLCD_TEXT_HOME)
  CommandWParam(T6963_SET_TEXT_AREA, GLCD_TEXT_AREA)

  CommandWParam(T6963_SET_OFFSET_REGISTER, GLCD_OFFSET_REGISTER)

  CommandWParam(T6963_SET_ADDRESS_POINTER, $00)

  Command(T6963_DISPLAY_MODE  Or T6963_GRAPHIC_DISPLAY_ON  Or T6963_TEXT_DISPLAY_ON)
//   Or T6963_CURSOR_DISPLAY_ON Or T6963_CURSOR_BLINK_ON
  'Command(T6963_DISPLAY_MODE  Or T6963_GRAPHIC_DISPLAY_ON ) 
  Command(T6963_MODE_SET Or 0)
  ClearGraphic()
  ClearText()
End Sub

Initialize()

Modified GLCD.BAS Module Code

This modified module is to be copied in the \UserLibrary\ sub folder to avoid any modification on original Swordfish module.

Sorry for code. each time I want to post it I got an error from the Wiki server. You can download the module code directly from this link http://www.pocketmt.com/tutors/glcd.zip