Box
Syntax
Box Pixel Colour, Xpos Start, Ypos Start, Size
Overview
Draw a square on a graphic LCD.
Parameters
Pixel Colour may be a constant or variable that determines if the square will set or clear the pixels. A value of 1 will set the pixels and draw a square, while a value of 0 will clear any pixels and erase a square. If using a colour graphic LCD, this parameter holds the 16-bit colour of the pixel. Xpos Start may be a constant or variable that holds the X position for the centre of the square. Can be a value from 0 to 65535. Ypos Start may be a constant or variable that holds the Y position for the centre of the square. Can be a value from 0 to 65535. Size may be a constant or variable that holds the size of the square (in pixels). Can be a value from 0 to 65535.
KS0108 graphic LCD example
' Draw a square at position 63,32 with a size of 20 pixels
' on a KS0108 graphic LCD
Device = 24FJ64GA002 ' Select the device to compile for
Declare Xtal = 32
Declare LCD_Type = KS0108 ' Setup for a KS0108 graphic LCD
Declare LCD_DTPort = PORTB.Byte0 ' Use the first 8-bits of PORTB
Declare LCD_CS1Pin = PORTB.8
Declare LCD_CS2Pin = PORTB.9
Declare LCD_ENPin = PORTB.10
Declare LCD_RSPin = PORTB.11
Declare LCD_RWPin = PORTB.12
Dim Xpos as Byte
Dim Ypos as Byte
Dim Size as Byte
Dim SetClr as Byte
CLKDIV = 0 ' CPU peripheral clock ratio set to 1:1
Write_OSCCONH(%00010000) ' Enable PLL
DelayMs 100 ' Wait for things to stabilise
Cls ' Clear the LCD
Xpos = 63
Ypos = 32
Size = 20
SetClr = 1
Box SetClr, Xpos, Ypos, Radius
'
' Config fuses for internal oscillator with PLL
'
Config Config1 = JTAGEN_OFF, GCP_OFF, GWRP_OFF, BKBUG_OFF, COE_OFF,_
ICS_PGx1, FWDTEN_OFF, WINDIS_OFF, FWPSA_PR128, WDTPOST_PS256
Config Config2 = IOL1WAY_OFF, COE_OFF, IESO_OFF, FNOSC_FRCPLL,_
FCKSM_CSDCMD, OSCIOFNC_ON, POSCMOD_NONE
ILI9320 colour graphic LCD example
' Demonstrate the box command with a colour 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
Dim wRadius As Word ' Create a variable for the circle's radius
'--------------------------------------------------------------------------
Main:
' Configure the internal Oscillator to operate the device at 140.03MHz
'
PLL_Setup(76, 2, 2, $0300)
Cls clYellow ' Clear the LCD with the colour yellow
For wRadius = 0 To 319
Box clBrightCyan, 120, 160, wRadius ' Draw a series of squares
Next
'--------------------------------------------------------------------------
' 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
Notes.
Because of the aspect ratio of the pixels on the KS0108 graphic LCD (approx 1.5 times higher than wide) the circle will appear elongated.
With an ILI9320 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 green content, and

Text in this figure or table
| High Byte | Low Byte | |||
| 15 | 11 10 | 5 | 4 | 0 |
| Red value | Green value | Red value |
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.


