Hi,
I wonder if there is a library for GLCD's monochrome resolution 128x64 pixel.
Like the one in SWORDFISH?
I would like to modify it for some OLED displays...
' mikroElectronika LV24-33 v6
device = 24FJ128GA010
clock = 32
config CONFIG2 = {POSCMOD_HS, OSCIOFNC_OFF, FCKSM_CSECMD, FNOSC_PRIPLL, IESO_OFF}
config CONFIG1 = {FWDTEN_OFF, BKBUG_OFF, JTAGEN_OFF}
#option _build = edit
#option GLCD_DATA = PORTD ' data port
#option GLCD_RS = PORTB.4 ' RS pin
#option GLCD_EN = PORTB.6 ' EN pin
#option GLCD_RW = PORTB.5 ' RW pin
#option GLCD_CS1 = PORTB.2 ' chip select
#option GLCD_CS2 = PORTB.3 ' chip select
#option GLCD_RST = PORTB.7 ' RST pin
imports GLCD
imports FixedFont
imports ArialFont
imports CalibriFont
sub Main()
Glcd.Clear
Glcd.SetFont(Fixed)
Glcd.WriteAt(4,2,"Fixed Font")
Glcd.SetFont(ArialBold)
Glcd.WriteAt(4,10,"Arial Bold 8pt")
Glcd.SetFont(CalibriBold)
Glcd.WriteAt(4,20,"Calibri 14pt")
end subPORTB.Byte1 = valuePORTB = (PORTB and &H00FF) or (value << 8) dEVICE = 24HJ128GP504
clock = 80
#option GLCD_RST = PORTC.7 ' RST pin
#option GLCD_MODEL = IST3020
imports GLCD
imports FixedFont
dim backlight as PORTC.8
dim buzzer as PORTB.11
dim i as byte
Sub Main()
OSCCON = $1100
CLKDIV = $0000
PLLFBD =$0029
CNPU1=$0700 'Enable pull-ups
CNPU2=$1604
output(backlight):high (backlight)
output(buzzer)
Glcd.Clear
Glcd.SetFont(fixed) 'THE MCU RESTARTS HERE !!!!!!!!!
'Glcd.WriteAt(4,2,"Test")
glcd.line(0,0,20,40)
glcd.square(20,40,20)
glcd.line(0,0,160,31)
glcd.circle(160,31,31)
beeps()
while true
delayms(1000)
end while
end sub
Sub beeps()
For i =1 To 75:High (buzzer):DelayUS(160):Low (buzzer):DelayUS(160):Next
End Sub '*****************************************************************************
'* Name : IST3020 Library *
'* Author : Simeon Kartalov *
'* Notice : Copyright (c) 2012 Mecanique *
'* : All Rights Reserved *
'* Date : 11/07/2014 *
'* Version : 1.0 *
'* Notes : *
'* : *
'*****************************************************************************
' import the graphics module...
#define GLCD_PIXEL_01
#define GLCD_COLOR_01
#define GLCD_XY_08
Module IST3020
imports GlcdGraphics
' default module options - user options can override these values...
#option GLCD_DATA = PORTB ' data port
#option GLCD_RS = PORTB.14 ' RS pin
#option GLCD_EN = PORTB.12 ' EN pin
#option GLCD_RW = PORTB.13 ' RW pin
#option GLCD_CS = PORTB.15 ' chip select
#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)
#option GLCD_INVERT_CS = false ' invert CS lines...
' 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 RS pin...
#if IsOption(GLCD_RS) And Not IsValidPortPin(GLCD_RS)
#error GLCD_RS, "Invalid option. RS must be a valid port pin."
#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 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 CS pin...
#if IsOption(GLCD_CS) And Not IsValidPortPin(GLCD_CS)
#error GLCD_CS, "Invalid option. CS 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
' validate invert CS...
#if IsOption(GLCD_INVERT_CS)
#if Not (GLCD_INVERT_CS in (true, false))
#error GLCD_INVERT_CS, "Invalid option. GLCD invert CS must be true or false."
#endif
#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
' now create Data TRIS...
#option _GLCD_DATA_TRIS = GetTRIS(GLCD_DATA)
' GLCD width and height...
public const Width = 192
public const Height = 64
' x, y position...
Public Pos As GraphicPosition
' IST3020 commands...
private Const _commandOn = &HAF
private Const _commandOff = &HAE
private Const _commandPage = &HB0
private Const _commandColumnMSB = &H10
private Const _commandColumnLSB = &H00
private Const _commandRam = &H40
private Const _glcdDelayMS = GLCD_INIT_DELAY
' port and pin settings, these are brought into
' the program by using the above options...
private _data As GLCD_DATA ' data in (PORT)
private _trisData As _GLCD_DATA_TRIS ' data TRIS
private _rs As GLCD_RS.GLCD_RS@ ' _rs pin (instruction or data)
private _en As GLCD_EN.GLCD_EN@ ' _en pin
private _rw As GLCD_RW.GLCD_RW@ ' _rw pin (read or write)
private _cs As GLCD_CS.GLCD_CS@ ' chip select
#if IsOption(GLCD_RST)
private _rst As GLCD_RST.GLCD_RST@ ' _rst pin
#endif
'*****************************************************************************
'* Name : StrobeEN *
'* Purpose : Strobe the GLCD enable pin *
'*****************************************************************************
private Inline Sub StrobeEN()
_en = 1
Delayus(1)
_en = 0
End Sub
'*****************************************************************************
'* Name : GLCDData *
'* Purpose : Switch to GLCD data mode *
'*****************************************************************************
private Inline Sub GlcdData()
_rs = 1
End Sub
'*****************************************************************************
'* Name : GLCDInst *
'* Purpose : Switch to GLCD instruction mode *
'*****************************************************************************
private Inline Sub GlcdInstruction()
_rs = 0
End Sub
'*****************************************************************************
'* Name : GLCDRead *
'* Purpose : Set GLCD to read mode *
'*****************************************************************************
private Inline Sub GlcdRead()
_rw = 1
End Sub
'*****************************************************************************
'* Name : GLCDWrite *
'* Purpose : Set GLCD to write mode *
'*****************************************************************************
private Inline Sub GlcdWrite()
_rw = 0
End Sub
'*****************************************************************************
'* Name : WaitForIdle *
'* Purpose : Block further GLCD access until signalled ready. *
'*****************************************************************************
private Sub WaitForIdle()
Dim Timeout As Byte = &HFF
GlcdInstruction ' instruction data
GlcdRead ' read mode
_trisData = _trisData or &H00FF ' set data bus to input
do
Timeout = Timeout - 1
ClearWDT
StrobeEN
loop Until (_data.7 = 0) Or (Timeout = 0)
End Sub
private sub waitforidle_alt()
delayms(10)
end sub
'*****************************************************************************
'* Name : SetData *
'* Purpose : Write a data byte to GLCD *
'*****************************************************************************
private Sub SetData(value As byte)
_cs=0
WaitForIdle ' block until not busy
GlcdData ' access display RAM data
GlcdWrite ' write mode
_trisData = _trisData and &HFF00 ' set data bus to output
_data = _data and &HFF00 or value ' write to the bus
StrobeEN ' write to GLCD
_cs=1
End Sub
'*****************************************************************************
'* Name : GetData *
'* Purpose : Read byte from GLCD *
'*****************************************************************************
private Function GetData() As byte
dim temp as ushort
_cs=0
WaitForIdle ' block until not busy
_trisData = _trisData or &H00FF ' set data bus to input
GlcdData ' access display RAM data
GlcdRead ' read mode
StrobeEN ' latch data
temp = _data and &H00FF ' get the data
GetData = temp.byte0
_cs=1
End Function
'*****************************************************************************
'* Name : Command *
'* Purpose : Write a command byte to GLCD *
'*****************************************************************************
private Sub Command(command As byte)
_cs=0
WaitForIdle ' block until not busy
GlcdInstruction ' instruction mode
GlcdWrite ' write mode
_trisData = &H0000 ' set data bus to output
_data = (_data and &HFF00) or command ' write to the bus
StrobeEN ' write to GLCD
_cs=1
End Sub
'*****************************************************************************
'* Name : SetPosition *
'* Purpose : Set GLCD x and y positions *
'*****************************************************************************
private Sub SetPosition()
Command(_commandPage Or Pos.y) ' set y position
Command(_commandColumnMSB Or pos.x >> 4) ' set x position MSB
Command(_commandColumnLSB Or (Pos.x and &H0F)) ' set x position LSB
End Sub
'*****************************************************************************
'* Name : WriteByte *
'* Purpose : Write a byte at x, page *
'*****************************************************************************
public Sub WriteByte(value As Byte)
SetPosition
SetData(value)
End Sub
'*****************************************************************************
'* Name : ReadByte *
'* Purpose : Read a byte at x, page *
'*****************************************************************************
Public Function ReadByte() As Byte
SetPosition
GetData
ReadByte = GetData
End Function
'*****************************************************************************
'* Name : SetPixel *
'* Purpose : Set pixel at pixel location x,y *
'*****************************************************************************
Public Sub SetPixel(x as byte, y As Byte)
Dim YBit As Byte
Dim Pixel As Byte
If (x < Width) And (y < Height) Then
YBit = 1 << (y Mod 8)
Pos.y = y / 8
Pos.x = x
SetPosition
GetData
Pixel = GetData
' pen is white...
If Pen.Color = 0 Then
If Pen.Mode = PenMode.IsCopy Then
yBit = Not yBit
Pixel = Pixel And YBit
end if
' pen is black...
Else
' pen copy or merge...
If Pen.Mode <> PenMode.IsXOR Then
Pixel = Pixel Or yBit
' pen XOR
Else
If (Pixel And YBit) = 0 Then
Pixel = Pixel Or yBit
Else
yBit = Not yBit
Pixel = Pixel And YBit
end if
end if
end if
SetPosition
SetData(Pixel)
end if
End Sub
'*****************************************************************************
'* Name : GetPixel *
'* Purpose : Return pixel colour at pixel position x, y *
'*****************************************************************************
Public Function GetPixel(x as byte, y As Byte) As GraphicColor
Dim Pixel As Byte
Pos.y = y / 8
Pos.x = x
SetPosition
GetData
Pixel = GetData >> (y Mod 8)
GetPixel = Pixel.0
End Function
'*****************************************************************************
'* Name : Clear *
'* Purpose : Clear the GLCD screen *
'*****************************************************************************
Public Sub Clear()
Dim y As Byte
dim xx as ushort
_cs=0
'Command(_commandOff)
for y=0 to 7
Command(_commandPage or y)
command(_commandColumnMSB)
command(_commandColumnLSB)
for xx=0 to width-1
setdata($00)
next
next
'Command(_commandOn)
_cs=1
End Sub
'*****************************************************************************
'* Name : Initialize *
'* Purpose : Configure the GLCD before use *
'*****************************************************************************
private Sub Main()
#if IsOption(GLCD_RST)
Output(_rst)
_rst = 1
#endif
Output(_en) ' enable is low
Output(_rs) ' data or instruction is low (command mode)
Output(_rw) ' read/write is low
Output(_cs)
_rst=1
_rst=0
delayms(10)
_rst=1
delayms(100)
Pos.x = 0
Pos.y = 0
DelayMS(_glcdDelayMS) ' start up delay, allow GLCD to settle
Command($ab) 'Build in osscilator: ON
delayms(100)
Command($a0) 'ADC=0 (normal direction)
Command($c8) 'SHL=1 (reverse direction)
Command($a2) 'LCD BIAS: 1/9
Command($2c) 'VC
delayms(10)
Command($2e) 'VR
delayms(10)
Command($2f) 'VF
delayms(10)
Command($20) 'Regulator resistor: R1
Command($81) 'Set reference voltage mode
command(40) '=32 (defauls)
command($40) 'SET START LINE
Command($af) 'Display ON
command($91) 'contrast
command($00)
'command($a5)
End Sub
end moduleReturn to Development Environment
Users browsing this forum: No registered users and 1 guest