Positron Compiler Documentation

Using an ILI9320 320x240 pixel Colour Graphic LCD

Positron16 · Revision 1.1.3.5 · PDF pages 286–289

Once a colour graphic LCD has been chosen using the Declare LCD_Type directive, all Print outputs will be directed to that LCD.

The standard modifiers used by an alphanumeric LCD may also be used with the graphics LCD. Most of the previous modifiers still work in the expected manner, however, the At modifier now starts at Ypos 0 and Xpos 0, where values 0,0 will be the top left corner of the LCD. And each cursor position is pixel based. The Inverse, Xor, and Or modifiers are not available for a colour LCD.

There are two new modifiers specifically for a colour LCD. These are: -

Ink 0 to 65535Choose the colour of the pixel used for a character
Paper 0 to 65535Choose the colour of the background under a character

Once one of the new modifiers has been enabled, all future Print commands will use that particular feature until the modifier is altered, or the Ink or Paper colour is chosen by the GLCD_Ink or GLCD_Paper commands. For example: -

' Enable red characters from this point
  Print At 0, 0, Ink cBrightRed, "Hello World"
  Print At 30, 0, "Still Red"
' Now use black characters
  Print At 60, 0, Ink cBlack, "Black Characters"

If no modifiers are present, then the character's ASCII representation will be displayed: -

' Print characters A and B
  Print At 0, 0, 65, 66

The routines for the ILI9320 colour graphic LCD must be included into the program before they are used, and the declares, listed later, must be placed. The LCD routines themselves are written in Positron16 BASIC so their operation may be readily changed.

' Demonstrate the Print command with an ILI9320 colour graphic LCD
'
  Device = 24EP128MC202             ' Select the device to compile for
  Declare Xtal = 140.03
'
' Setup the Pins used by the ILI9320 graphic LCD
'
  Declare LCD_DTPort = PORTB.Byte0  ' Use the first 8-bits of PORTB
  Declare LCD_CSPin = PORTB.8       ' Connect to the LCD's CS pin
  Declare LCD_RDPin = PORTB.9       ' Connect to the LCD's RD pin
  Declare LCD_RSPin = PORTB.10      ' Connect to the LCD's RS pin
  Declare LCD_WRPin = PORTA.3       ' Connect to the LCD's WR pin

  Include "ILI9320.inc"            ' Load the ILI9320 routines into the program
'--------------------------------------------------------
Main:
' Configure the internal oscillator to operate the device at 140.03MHz
  PLL_Setup(76, 2, 2, $0300)

  Cls clWhite                       ' Clear the LCD with the colour white
View original PDF page 286Open page in PDFOriginal PDF page 286
  GLCD_SetFont(CourierNew_20)       ' Choose the font to use
  Print At 0,0, Ink clBrightBlue, "Hello World"

'--------------------------------------------------------
' Load the font required
  Include "CourierNew_20.inc"
'
' Configure for internal 7.37MHz oscillator with PLL
' OSC pins are general purpose I/O
'
  Config FGS = GWRP_OFF, GCP_OFF
  Config FOSCSEL = FNOSC_FRCPLL, IESO_ON, PWMLOCK_OFF
  Config FOSC = POSCMD_NONE, OSCIOFNC_ON, IOL1WAY_OFF, FCKSM_CSDCMD
  Config FWDT = WDTPOST_PS256, WINDIS_OFF, PLLKEN_ON, FWDTEN_OFF
  Config FPOR = ALTI2C1_ON, ALTI2C2_OFF
  Config FICD = ICS_PGD1, JTAGEN_OFF

Fonts can be created using the supplied program named FontCreator.exe, and can be found in the IDE's plugins folder.

With an ILI9320 320x240 pixel colour graphic LCD, the colour is a 16-bit value formatted in RGB565, where the upper 5-bits represent the red content, the middle 6-bits represent the

Original diagram or table from Positron16, PDF page 287
Original figure / layout · PDF page 287
Text in this figure or table
High ByteLow Byte
1511 10540
Red valueGreen valueRed value

green content, and the lower 5-bits represent the blue content. As illustrated below:

For convenience, there are several colours defined within the ILI9320.inc file. These are:

clBlack
clBrightBlue
clBrightGreen
clBrightCyan
clBrightRed
clBrightMagenta
clBrightYellow
clBlue
clGreen
clCyan
clRed
clMagenta
clBrown
clLightGray
clDarkGray
clLightBlue
clLightGreen
clLightCyan
clLightRed
clLightMagenta
clYellow
clWhite

More constant values for colours can be added by the user if required.

View original PDF page 287Open page in PDFOriginal PDF page 287
Original diagram or table from Positron16, PDF page 288
Original figure / layout · PDF page 288
Text in this figure or table

A suitable circuit for the Ampire AM240320D4T0QWT00H(R) module is shown below: LCD Backlight Boost

10uH MBRS130T3

1Schottky
GNDRF filter
215
LEDs AnodeSWVin
33+5v
LEDs CathodeFB
4TPS61040
GND10KΩ

5

VCC(3v3)+3v31uF/50v100Ω41uF/10v
GNDEN

6

VCC(3v3) ceramic ceramic

2 7 ENABLE 8 DOTCLK 9

HSYNC +3v3

10 VSYNC 11

RD RB9

12

SCL/WR RA3 10kΩ

13

RS RB10

14 RESET

Ampire15
CSRB8

100nF

AM240320D4T0QWT00H(R) 16

D0 17 D1 18 D2

ILI9320 19

D3

320x240 20

D4 21

Colour Graphic LCD D5

22

with Touch Screen D6

23 D7 24 D8 25 D9 26

D10 RB0

27

D11 RB1

28

D12 RB2

29

D13 RB3

30

D14 RB4

31

D15 RB5

32

D16 RB6

33

D17 RB7

34 SDI 35 NC 36 SDO 37 IM3 38 IM1

39 +3v3

ID/IM0 40 GND 41

YUTo ADS7846 Y-
42Resistive touch
YDTo ADS7846 Y+

43

XRTo ADS7846 X+
44screen interface
XLTo ADS7846 X-

45 GND

ILI9320 Colour LCD

ILI9320 colour graphic LCD Declares

There are several declares associated with an ILI9320 colour graphic LCD.

Declare LCD_DTPort Port Assign the port that will output the 8-bit data to the graphic LCD.

There is no default setting for this Declare and it must be used within the BASIC program.

Declare LCD_WRPin Port.Pin Assigns the Port and Pin that the graphic LCD's WR line will attach to.

There is no default setting for this Declare and it must be used within the BASIC program.

Declare LCD_RDPin Port.Pin Assigns the Port and Pin that the graphic LCD's RD line will attach to.

There is no default setting for this Declare and it must be used within the BASIC program.

Declare LCD_CSPin Port.Pin Assigns the Port and Pin that the graphic LCD's CS line will attach to.

There is no default setting for this Declare and it must be used within the BASIC program.

View original PDF page 288Open page in PDFOriginal PDF page 288

Declare LCD_RSPin Port.Pin Assigns the Port and Pins that the graphic LCD's RS line will attach to.

There is no default setting for this Declare and it must be used within the BASIC program.

Declare LCD_RSTPin Port.Pin Assigns the Port and Pin that the graphic LCD's RST line will attach to.

The LCD’s RST (Reset) Declare is optional and if omitted from the BASIC code the compiler will not manipulate it. However, if not used as part of the interface, you must set the LCD’s RST pin high for normal operation.

The ILI9320 graphic LCD is a “non-intelligent” type, therefore, a separate character set is required. This is held internally in code memory and is chosen by issuing the GLCD_SetFont(pFont) command.

View original PDF page 289Open page in PDFOriginal PDF page 289