Here you can find the code to drive an ILI9325 8bit displaycontroller in Bascom-AVR

 

Step 1. The hardware...

 

2.4" TFT LCD Screen Module: ITDB02-2.4
from www.arduinosolutions.com

With on the back a SD-card

ITDB02 Arduino Mega Shield v1.1
from www.arduinosolutions.com


 
Arduino Mega 1280
From www.dfrobot.com


This is the way I got hold of the fusebits, putting an AVRISP cable on the ISP connector of the Arduino Mega. I used a 6-to-10 converter from Sparkfun.
 

 

New, from Bascom 2.0.5.0 and up, the selection ARDUINO

 

BTW: A good choice, the Arduino Mega as base-board for this shield.

 

Arduino Mega pin-configuration



Source: Forum www.arduino.cc

 

 

 


x.bas
y.hex

 

Start programma with type of microcontroller, speed, stacksettings and baudrate
 

$regfile = "M1280def.dat"
$crystal = 16000000
$hwstack = 512
$swstack = 512
$framesize = 512
$baud = 57600

 

Lots of constants
 

Const Driver_code_read = $00
Const Start_oscillation = $00
Const Driver_output_control = $01
Const Lcd_driving_control = $02
Const Entry_mode = $03
Const Resize_control = $04
Const Display_control_1 = $07
Const Display_control_2 = $08
Const Display_control_3 = $09
Const Display_control_4 = $0a
Const Rgb_display_interface_control_1 = $0c
Const Frame_maker_position = $0d
Const Rgb_display_interface_control_2 = $0f
Const Power_control_1 = $10
Const Power_control_2 = $11
Const Power_control_3 = $12
Const Power_control_4 = $13
Const Horizontal_gram_address = $20
Const Vertical_gram_address = $21
Const Write_data_to_gram = $22
Const Power_control_7 = $29
Const Frame_rate_and_color_control = $2b
Const Gamma_control_1 = $30
Const Gamma_control_2 = $31
Const Gamma_control_3 = $32
Const Gamma_control_4 = $35
Const Gamma_control_5 = $36
Const Gamma_control_6 = $37
Const Gamma_control_7 = $38
Const Gamma_control_8 = $39
Const Gamma_control_9 = $3c
Const Gamma_control_10 = $3d
Const Horizontal_add_start_position = $50
Const Horizontal_add_end_position = $51
Const Vertical_add_start_position = $52
Const Vertical_add_end_position = $53
Const Driver_output_control_2 = $60
Const Base_image_display_control = $61
Const Vertical_scroll_control = $6a
Const Partial_image_1_display_position = $80
Const Partial_image_1_area_start_line = $81
Const Partial_image_1_area_end_line = $82
Const Partial_image_2_display_position = $83
Const Partial_image_2_area_start_line = $84
Const Partial_image_2_area_end_line = $85
Const Panel_interface_control_1 = $90
Const Panel_interface_control_2 = $92
Const Panel_interface_control_3 = $93
Const Panel_interface_control_4 = $95
Const Panel_interface_control_5 = $97
Const Panel_interface_control_6 = $98
Const Pi = 3.14159265358979

'-------------------------------------------------------------------------------
'pre define Colors
'-------------------------------------------------------------------------------

Const Red = &HF800
Const Green = &H07E0
Const Blue = &H001F
Const White = &HFFFF
Const Black = &H0000
Const Yellow = &HFFE0
Const Cyan = &H0410
Const Magenta = &H8010
Const Brown = &HFC00
Const Olive = &H8400
Const Bright_red = &HF800
Const Bright_green = &H07E0
Const Bright_blue = &H001F
Const Bright_yellow = &HFFE0
Const Bright_cyan = &H07FF
Const Bright_magenta = &HF81F
Const Light_gray = &H8410
Const Dark_gray = &H4208
Const Light_blue = &H841F
Const Light_green = &H87F0
Const Light_cyan = &H87FF
Const Light_red = &HFC10
Const Gray1 = &HC618
Const Gray2 = &HA514
Const Gray3 = &H630C
Const Gray4 = &H4208
Const Gray5 = &H2104
Const Gray6 = &H3186
Const Blue0 = &H1086
Const Blue1 = &H3188
Const Blue2 = &H4314
Const Blue3 = &H861C
Const Cyan0 = &H3D34
Const Cyan1 = &H1DF7
Const Green0 = &H0200
Const Green1 = &H0208

 

Configuring the hardware ports
 

Data_disp Alias Porta
Rs_disp Alias Portd.7
Wr_disp Alias Portg.2
_wr_disp Alias 2
Cs_disp Alias Portg.1
Res_disp Alias Portg.0

Config Rs_disp = Output
Config Cs_disp = Output
Config Wr_disp = Output
Config Res_disp = Output
Config Data_disp = Output

\C7onfigure clock for AVR-DOS
Config Clock = Soft
Enable Interrupts
Config Date = Mdy , Separator = .

 

Declaring the subroutines
 

Declare Sub Ili9325_init(byval Modus As Byte , Byval Direction As Word)
Declare Sub Ili9325_write_reg(byval Index As Byte , Byval Daten As Word)
Declare Sub Ili9325_write_data(byval Daten As Word) 'was byref
Declare Sub Ili9325_select_reg(byval Index As Byte )
Declare Sub Ili9325_exit_sleep()
Declare Sub Ili9325_enter_sleep()
Declare Sub Ili9325_scroll(byval Lines As Word )
Declare Sub Ili9325_set_window(byval Xpos As Word , Byval Ypos As Word , Byval Xsize As Word , Byval Ysize As Word)
Declare Sub Ili9325_negate(byval Art As Word )
Declare Sub Ili9325_set_pixel(byval X1 As Word , Byval Y1 As Word , Byval Color As Word)
Declare Sub Ili9325_set_cursor(byval X As Word , Y As Word )
Declare Sub Ili9325_text(byval Lcd_text As String , Byval Lcd_posx As Word , Byval Lcd_posy As Word , Byval Fontset As Byte , Byval Forecolor As Word , Byval Backcolor As Word)
Declare Sub Ili9325_line(byval X1 As Word , Byval Y1 As Word , Byval X2 As Word , Byval Y2 As Word , Byval Pen_width As Byte , Byval Color As Word)
Declare Sub Ili9325_box(byval X1 As Word , Byval Y1 As Word , Byval X2 As Word , Byval Y2 As Word , Byval Fill_color As Word , Byval Border_color As Word , Byval Fill As Byte , Byval Show_border As Byte)
Declare Sub Ili9325_lineto(byval X As Word , Byval Y As Word , Byval Pen_width As Byte , Byval Color As Word)
Declare Sub Ili9325_moveto(byval X As Word , Byval Y As Word)
Declare Sub Ili9325_drawcircle(byval Centerx As Word , Byval Centery As Word , Byval Radius As Word , Byval Sides As Word , Byval Pen_width As Byte , Byval Color As Word)
Declare Sub Ili9325_drawarc(byval Centerx As Word , Byval Centery As Word , Byval Radius As Word , Byval Startangle As Word , Byval Arcangle As Word , Byval Steps As Word , Byval Pen_width As Byte , Byval Color As Word)
Declare Sub Ili9325_drawrect(byval X1 As Word , Byval Y1 As Word , Byval X2 As Word , Byval Y2 As Word , Byval Pen_width As Byte , Byval Color As Word)
Declare Sub Ili9325_showpicture(byval Xoffset As Word , Byval Yoffset As Word) 'Draw an Bascom BGC image on the lcd
Declare Sub Ili9325_clear(byval Color As Word , Byval Direction As Word)
Declare Sub Ili9325_draw_bmp(byval Filename As String , Byval Xpos As Word , Byval Ypos As Word)

 

Declaring the functions
 

Declare Function Ili9325_trigfunctionx(byval Pointratio As Single) As Single
Declare Function Ili9325_trigfunctiony(byval Pointratio As Single) As Single
Declare Function Ili9325_get_color(byval R As Byte , Byval G As Byte , Byval B As Byte) As Word
Declare Function Ili9325_rgb16(byval Rgb8 As Byte) As Word
'Convert the 8bit RRRGGGBB bgc data to 16 bit RRRRRGGGGGGBBBBB

 

Dimensioning the variables
 

Dim Color_array(10) As Word
Color_array(1) = Red
Color_array(2) = Green
Color_array(3) = Blue
Color_array(4) = White
Color_array(5) = Bright_yellow
Color_array(6) = Yellow
Color_array(7) = Cyan
Color_array(8) = Magenta
Color_array(9) = Brown
Color_array(10) = Olive

Dim X_pixel As Word , Y_pixel As Word
Dim Move_x As Word , Move_y As Word
Dim Display_modus As Byte
Dim Out_of_range As Byte
Dim Xx1 As Word , Xx2 As Word , Yy1 As Word , Yy2 As Word , Kleur As Word
Dim Penwidth As Byte , Radius As Word
Dim Modus As Byte
Dim Direction As Word
Dim Hulpstring As String * 30
Dim Rgb16 As Word
Dim Rgb16_l As Byte At Rgb16 Overlay
Dim Rgb16_h As Byte At Rgb16 + 1 Overlay
Dim Wtemp1 As Word , Wtemp2 As Word
Dim Btemp1 As Byte
Dim Lcd_text As String * 30

 

'for BMP-routine
Dim Line_len As Word
Dim Line_byte As Word
Dim Bmp_read_pos As Long
Dim Biwidth As Word 'normaly long, but we can't handle bigger bmp's!
Dim Biheight As Word 'normaly long, but we can't handle bigger bmp's!
 

'for AVR-DOS
Dim Gbdriveerror As Byte ' General Driver Error register
Dim Gbdriveerrorreg As Byte ' Driver load Error-Register of HD in case of error
Dim Gbdrivestatusreg As Byte ' Driver load Status-Register of HD on case of error
Dim Gbdrivedebug As Byte

 

AVR-DOS SPI Settings
 

' Chip Select Pin => Pin 1 of MMC/SD
Config Pinb.0 = Output
Mmc_cs Alias Portb.0
Set Mmc_cs

 

' MOSI - Pin => Pin 2 of MMC/SD
Config Pinb.2 = Output
Set Portb.2
Mmc_portmosi Alias Portb
Bmmc_mosi Alias 2

 

' MISO - Pin => Pin 7 of MMC/SD
Config Pinb.3 = Input
Mmc_portmiso Alias Pinb
Bmmc_miso Alias 3

 

' SCK - Pin => Pin 5 of MMC/SD
Config Pinb.1 = Output
Set Portb.1
Mmc_portsck Alias Portb
Bmmc_sck Alias 1

' Error
Const Cperrdrivereset = 225 ' Error response Byte at Reset command
Const Cperrdriveinit = 226 ' Error response Byte at Init Command
Const Cperrdrivereadcommand = 227 ' Error response Byte at Read Command
Const Cperrdrivewritecommand = 228 ' Error response Byte at Write Command
Const Cperrdrivereadresponse = 229 ' No Data response Byte from MMC at Read
Const Cperrdrivewriteresponse = 230 ' No Data response Byte from MMC at Write
Const Cperrdrive = 231
Const Cperrdrivenotsupported = 232 ' return code for DriveGetIdentity, not supported yet
Waitms 1 ' Wait some time before initialising MMC/SD

$lib "MMC.LIB" ' link driver library
$external _mmc

Gbdriveerror = Driveinit()
If Gbdriveerror = 0 Then

 

' Include AVR-DOS Configuration and library
$include "Config_AVR-DOS.BAS"

 

Demo code

 

Call Ili9325_init(2 , 2)
'clear screen
Call Ili9325_clear(white , 0)
'tekst plaatsen
Call Ili9325_text( "AVR-DOS" , 5 , 20 , 2 , Black , White)

Wait 5

Call Ili9325_text( "Init File System..." , 5 , 60 , 1 , Black , White)
Btemp1 = Initfilesystem(1) ' Partition 1
' use 0 for drive without Master boot record
If Btemp1 <> 0 Then
Call Ili9325_text( "Error:" , 5 , 80 , 1 , Black , White)
Hulpstring = Str(btemp1)
Call Ili9325_text(hulpstring , 40 , 80 , 1 , Black , White)
Call Ili9325_text( "at Init file system" , 60 , 80 , 1 , Black , White)
Else
Call Ili9325_text( "OK" , 5 , 80 , 1 , Black , White)
Call Ili9325_text( "Filesystem: " , 5 , 100 , 1 , Black , White)
Hulpstring = Str(gbfilesystem)
Call Ili9325_text(hulpstring , 170 , 100 , 1 , Black , White)
Call Ili9325_text( "FAT Start Sector:" , 5 , 120 , 1 , Black , White)
Hulpstring = Str(glfatfirstsector)
Call Ili9325_text(hulpstring , 170 , 100 , 1 , Red , White)
Call Ili9325_text( "Root Start Sector:" , 5 , 120 , 1 , Black , White)
Hulpstring = Str(glrootfirstsector)
Call Ili9325_text(hulpstring , 170 , 120 , 1 , Red , White)
Call Ili9325_text( "Data First Sector:" , 5 , 140 , 1 , Black , White)
Hulpstring = Str(gldatafirstsector)
Call Ili9325_text(hulpstring , 170 , 140 , 1 , Red , White)
Call Ili9325_text( "Max. Cluster Number:" , 5 , 160 , 1 , Black , White)
Hulpstring = Str(glmaxclusternumber)
Call Ili9325_text(hulpstring , 170 , 160 , 1 , Red , White)
Call Ili9325_text( "Sectors per Cluster:" , 5 , 180 , 1 , Black , White)
Hulpstring = Str(gbsectorspercluster)
Call Ili9325_text(hulpstring , 170 , 180 , 1 , Red , White)
Call Ili9325_text( "Root Entries:" , 5 , 200 , 1 , Black , White)
Hulpstring = Str(gwrootentries)
Call Ili9325_text(hulpstring , 170 , 200 , 1 , Red , White)
Call Ili9325_text( "Sectors per FAT:" , 5 , 220 , 1 , Black , White)
Hulpstring = Str(glsectorsperfat)
Call Ili9325_text(hulpstring , 170 , 220 , 1 , Red , White)
Call Ili9325_text( "Number of FAT:" , 5 , 240 , 1 , Black , White)
Hulpstring = Str(gbnumberoffats)
Call Ili9325_text(hulpstring , 170 , 240 , 1 , Red , White)
End If
Else
' Print #1 , "Error during Drive Init: " ; Gbdriveerror
End If

 

' If you want to test with File-System Interpreter uncomment next line
'$include "FS_Interpreter.bas"
 

Wait 10
 

Do
'clear screen white
Call Ili9325_clear(white , 0)
'
place text
Call Ili9325_text( " 8-bit " , 5 , 30 , 2 , Black , White)
Call Ili9325_text( " Demo
of a " , 5 , 65 , 2 , Black , White)
Call Ili9325_text( " 240x320 display " , 5 , 100 , 2 , Red , White)

 

Wait 2

Call Ili9325_clear(black , 0)
Call Ili9325_draw_bmp( "demo.bmp" , 1 , 1) 'Shows 24bit windows BMP

 

Wait 10

Call Ili9325_clear(black , 0)
Restore Aandelen
Call Ili9325_showpicture(10 , 5)

Restore Agenda
Call Ili9325_showpicture(85 , 5)

Restore Bascom
Call Ili9325_showpicture(160 , 5)

Restore Calculator
Call Ili9325_showpicture(10 , 85)

Restore Bens
Call Ili9325_showpicture(85 , 85)

Restore Contacten
Call Ili9325_showpicture(160 , 85)

Restore Fotos
Call Ili9325_showpicture(10 , 164)

Restore Pa0kn
Call Ili9325_showpicture(85 , 164)

Restore Kaarten
Call Ili9325_showpicture(160 , 164)

Restore Klok
Call Ili9325_showpicture(10 , 240)

Restore Sms
Call Ili9325_showpicture(85 , 240)

Restore Weer
Call Ili9325_showpicture(160 , 240)

Wait 10

'scroll in two speeds
For Wtemp1 = 1 To 320
Call Ili9325_scroll(wtemp1)
If Wtemp1 < 50 Then Waitms 100
If Wtemp1 > 50 Then Waitms 5
Next Wtemp1

Wait 2

'
'composi
te screen
Call Ili9325_negate(0)
Wait 1
Call Ili9325_negate(1)
Wait 1
Call Ili9325_negate(0)
Wait 1
Call Ili9325_negate(1)
'

Call Ili9325_clear(red , 0)
Wait 2

Call Ili9325_text( "Functions(1):" , 10 , 10 , 2 , White , Red)
Call Ili9325_text( "Ili9325_init" , 10 , 35 , 2 , White , Red)
Call Ili9325_text( "Ili9325_scroll" , 10 , 60 , 2 , White , Red)
Call Ili9325_text( "Ili9325_text" , 10 , 85 , 2 , White , Red)
Call Ili9325_text( "Ili9325_clear" , 10 , 110 , 2 , White , Red)
Call Ili9325_text( "Ili9325_moveto" , 10 , 135 , 2 , White , Red)
Call Ili9325_text( "Ili9325_lineto" , 10 , 160 , 2 , White , Red)
Call Ili9325_text( "Ili9325_negate" , 10 , 185 , 2 , White , Red)
Call Ili9325_text( "Ili9325_set_cursor" , 10 , 210 , 2 , White , Red)
Call Ili9325_text( "Ili9325_set_pixel" , 10 , 235 , 2 , White , Red)
Call Ili9325_text( "Ili9325_set_window" , 10 , 260 , 2 , White , Red)
Call Ili9325_text( "Ili9325_get_color" , 10 , 285 , 2 , White , Red)

Wait 5

'scroll
For Wtemp1 = 1 To 320
Call Ili9325_scroll(wtemp1)
If Wtemp1 < 50 Then Waitms 100
If Wtemp1 > 50 Then Waitms 1
Next Wtemp1

Wait 1

For Wtemp1 = 320 To 1 Step -1
Call Ili9325_scroll(wtemp1)
If Wtemp1 < 50 Then Waitms 100
If Wtemp1 > 50 Then Waitms 1
Next Wtemp1
Call Ili9325_scroll(0)
Call Ili9325_clear(red , 0)

Wait 2

Call Ili9325_text( "Functions(2):" , 10 , 10 , 2 , White , Red)
Call Ili9325_text( "Ili9325_line" , 10 , 35 , 2 , White , Red)
Call Ili9325_text( "Ili9325_box" , 10 , 60 , 2 , White , Red)
Call Ili9325_text( "Ili9325_drawcircle" , 10 , 85 , 2 , White , Red)
Call Ili9325_text( "Ili9325_drawarc" , 10 , 110 , 2 , White , Red)
Call Ili9325_text( "Ili9325_drawrect" , 10 , 135 , 2 , White , Red)
Call Ili9325_text( "Ili9325_showpicture" , 10 , 160 , 2 , White , Red)
Call Ili9325_text( "Ili9325_..." , 10 , 185 , 2 , White , Red)
Call Ili9325_text( "Ili9325_..." , 10 , 210 , 2 , White , Red)
Call Ili9325_text( "Ili9325_..." , 10 , 235 , 2 , White , Red)
Call Ili9325_text( "Ili9325_..." , 10 , 260 , 2 , White , Red)
Call Ili9325_text( "Ili9325_..." , 10 , 285 , 2 , White , Red)

 

Wait 5

'scroll
For Wtemp1 = 1 To 320
Call Ili9325_scroll(wtemp1)
If Wtemp1 < 50 Then Waitms 100
If Wtemp1 > 50 Then Waitms 1
Next Wtemp1

Wait 1

For Wtemp1 = 320 To 1 Step -1
Call Ili9325_scroll(wtemp1)
If Wtemp1 < 50 Then Waitms 100
If Wtemp1 > 50 Then Waitms 1
Next Wtemp1

Call Ili9325_scroll(0)

Wait 4

Call Ili9325_clear(blue , 0)
Call Ili9325_text( "ili9325_moveto" , 10 , 10 , 2 , White , Blue)
Call Ili9325_text( "ili9325_lineto" , 10 , 35 , 2 , White , Blue)
Call Ili9325_set_window(1 , 1 , 240 , 320)
For Wtemp1 = 1 To 320 Step 3
Call Ili9325_moveto(10 , Wtemp1)
Call Ili9325_lineto(240 , Wtemp1 , 1 , White)
Next Wtemp1

Wait 5

'spagetti
Call Ili9325_clear(white , 0)
Call Ili9325_text( "ili9325_line" , 10 , 10 , 2 , Black , White)
Call Ili9325_text( "Mikado" , 10 , 35 , 2 , Black , White)
Call Ili9325_set_window(1 , 1 , 240 , 320)
For Wtemp1 = 1 To 100
Kleur = Rnd(10)
Xx1 = Rnd(240)
Xx2 = Rnd(240)
Yy1 = 50 + Rnd(270)
Yy2 = 50 + Rnd(270)
Penwidth = Rnd(4)
Call Ili9325_line(xx1 , Yy1 , Xx2 , Yy2 , Penwidth , Color_array(kleur))
Next Wtemp1

Wait 5

Call Ili9325_clear(white , 0)
Call Ili9325_set_window(1 , 1 , 240 , 320)
For Wtemp1 = 1 To 65535
Call Ili9325_write_reg(write_data_to_gram , Wtemp1)
Next Wtemp1

For Wtemp1 = 1 To 65535 Step 10000
Wtemp2 = 65535 - Wtemp1
Call Ili9325_text( " Kleurtje.." , 50 , 20 , 2 , Wtemp1 , Wtemp2)
Next Wtemp1

For Wtemp1 = 1 To 320
Call Ili9325_scroll(wtemp1)
If Wtemp1 < 50 Then Waitms 100
If Wtemp1 > 50 Then Waitms 1
Next Wtemp1

Wait 1

For Wtemp1 = 320 To 1 Step -25
Call Ili9325_scroll(wtemp1)
If Wtemp1 > 50 Then Wait 1
Next Wtemp1

Wait 1

Call Ili9325_scroll(0)

 

Wait 5

' *** partial Image ***
Call Ili9325_clear(black , 0)
Call Ili9325_text( "Graphic Sample" , 10 , 10 , 2 , Yellow , Black)
Call Ili9325_text( "by six1" , 120 , 30 , 2 , Yellow , Black)
Call Ili9325_text( "Partial Images" , 1 , 60 , 2 , White , Black)
Wait 2
Call Ili9325_clear(white , 0)

Call Ili9325_write_reg(display_control_1 , &B001_0000_0111_0011)
Call Ili9325_write_reg(partial_image_1_area_start_line , 0)
Call Ili9325_write_reg(partial_image_1_area_end_line , 40)
Call Ili9325_write_reg(partial_image_1_display_position , 319)
Call Ili9325_text( "Dit is nog een scroll-test" , 10 , 280 , 1 , Black , White )
Call Ili9325_text( "om te laten zien dat de" , 10 , 290 , 1 , Black , White )
Call Ili9325_text( "ILI9325 ook bij scrollen" , 10 , 300 , 1 , Black , White )
Call Ili9325_text( "tempo kan maken..." , 10 , 310 , 1 , Black , White )
For Wtemp1 = 319 To 0 Step -1
Call Ili9325_write_reg(partial_image_1_display_position , Wtemp1)
Waitms 20
Next Wtemp1

Call Ili9325_clear(white , 0)
Call Ili9325_write_reg(display_control_1 , &B000_0001_0111_0011)
Call Ili9325_text( "...slaapverwekkend" , 10 , 50 , 2 , Red , White)
Wait 1
Call Ili9325_text( "dan maken we een" , 10 , 70 , 2 , Red , White)
Call Ili9325_text( " beetje tempo" , 10 , 90 , 2 , Red , White)
Wait 1

Call Ili9325_write_reg(display_control_1 , &B001_0000_0111_0011)
Call Ili9325_write_reg(partial_image_1_area_start_line , 0)

Call Ili9325_write_reg(partial_image_1_area_end_line , 40)
Call Ili9325_write_reg(partial_image_1_display_position , 319)
Call Ili9325_text( "Dit is nog een scroll-testt" , 10 , 280 , 1 , Black , White )
Call Ili9325_text( "om te laten zien dat de" , 10 , 290 , 1 , Black , White )
Call Ili9325_text( "ILI9325 ook bij scrollen" , 10 , 300 , 1 , Black , White )
Call Ili9325_text( "tempo kan maken..." , 10 , 310 , 1 , Black , White )
For Wtemp1 = 319 To 0 Step -1
Call Ili9325_write_reg(partial_image_1_display_position , Wtemp1)
Waitms 2
Next Wtemp1
For Wtemp1 = 0 To 319
Call Ili9325_write_reg(partial_image_1_display_position , Wtemp1)
Waitms 2
Next Wtemp1

Wait 5

Call Ili9325_init(2 , 2) '2 = beneden naar boven
Call Ili9325_clear(white , 0)
Call Ili9325_text( "ili9325_drawrect" , 10 , 10 , 2 , Black , White)
Call Ili9325_set_window(1 , 1 , 240 , 320)
For Wtemp1 = 1 To 100
Kleur = Rnd(10)
Xx1 = Rnd(240)
Xx2 = Rnd(240)
Yy1 = 50 + Rnd(240)
Yy2 = 50 + Rnd(240)
Penwidth = Rnd(4)
Penwidth = Rnd(4)
Waitms 150
Call Ili9325_drawrect(xx1 , Yy1 , Xx2 , Yy2 , Penwidth , Color_array(kleur))
Next Wtemp1
Wait 5

Call Ili9325_clear(white , 0)
Call Ili9325_text( "ili9325_showpicture" , 5 , 10 , 2 , Black , White)
Call Ili9325_set_window(1 , 1 , 240 , 320)

Restore Plaatje
Call Ili9325_showpicture(50 , 50)
Wait 5

Call Ili9325_draw_bmp( "babe.bmp" , 20 , 100) 'Shows 24bit windows BMP
Wait 25

Call Ili9325_clear(blue , 0)
Wait 2

Call Ili9325_clear(red , 1)
Wait 2

Call Ili9325_clear(green , 2)
Wait 2

Call Ili9325_clear(black , 3)
Wait 2

Call Ili9325_text( "That's all" , 60 , 210 , 2 , White , Black)
Call Ili9325_text( " folks!!" , 60 , 250 , 2 , White , Black)

Wait 5

Loop
End

 

Declare sub ili9325_init(byval Modus as Byte, Byval Direction as Word)
 

Sub Ili9325_init(byval Modus As Byte , Byval Direction As Word)
'reset
Res_disp = 1
Waitms 5
Res_disp = 0
Waitms 15
Res_disp = 1
Waitms 15

' Modus:
' 1 - Vertical
' 2 - Horizontal
' Direction : 0 -3

Display_modus = Modus
Call Ili9325_write_reg(start_oscillation , &B0000_0000_0000_0001)
Waitms 10
' the shift direction of outputs is from S1 to S720
Call Ili9325_write_reg(driver_output_control , &B0000_0000_0000_0000 )
' the shift direction of outputs is from S720 to S1
'Call Ili9325_write_reg(driver_output_control , &B0000_0001_0000_0000 )
Call Ili9325_write_reg(lcd_driving_control , &B0000_0111_0000_0000 )
Direction = Direction And 3
Shift Direction , Left , 4
'Horizontal left-upper to right-bottom
If Modus = 1 Then
Direction = Direction Or &B0001000000001000 '4104
Call Ili9325_write_reg(entry_mode , Direction )
X_pixel = 320
Y_pixel = 240
End If
'Vertical left-upper to right-bottom
If Modus = 2 Then
Direction = Direction Or &B0001000000_00_0_000 '4096 &B0001000000000000 ' I/D[1:0] AM richting schrijven...
Call Ili9325_write_reg(entry_mode , Direction)
X_pixel = 240
Y_pixel = 320
End If

Call Ili9325_write_reg(&He5 , &H7800) 'SRAM internal timing
Call Ili9325_write_reg(resize_control , &H0000) 'resize register
Call Ili9325_write_reg(display_control_2 , &H0207) 'set the back porch and the front porch
Call Ili9325_write_reg(display_control_3 , &H0000) 'set non-display area refresh cycle ISC[3:0]
Call Ili9325_write_reg(display_control_4 , &H0000) 'FMARK function
Call Ili9325_write_reg(rgb_display_interface_control_1 , &H0000) ' RGB interface settings
Call Ili9325_write_reg(frame_maker_position , &H0000) 'frame marker position
Call Ili9325_write_reg(rgb_display_interface_control_2 , &H0000) 'RGB interface polarity
Call Ili9325_write_reg(power_control_1 , &H0000) 'SAP, BT[3:0], AP, DSTB, SLP, STB
Call Ili9325_write_reg(power_control_2 , &H0007) 'DC1[2:0], DC0[2:0], VC[2:0]
Call Ili9325_write_reg(power_control_3 , &H0000) 'VREG1OUT voltage
Call Ili9325_write_reg(power_control_4 , &H0000) 'VDV[4:0] for VCOM amplitude
Call Ili9325_write_reg(display_control_1 , &H0001) 'discharge capacitor power voltage
Waitms 50
Call Ili9325_write_reg(power_control_1 , &H1090) '1490/SAP, BT[3:0], AP, DSTB, SLP, STB
Call Ili9325_write_reg(power_control_2 , &H0227) 'DC1[2:0], DC0[2:0], VC[2:0]
Waitms 50
Call Ili9325_write_reg(power_control_3 , &H001F) 'internal reference voltage
Waitms 50
Call Ili9325_write_reg(power_control_4 , &H1500)
Call Ili9325_write_reg(power_control_7 , &H0027)
Call Ili9325_write_reg(frame_rate_and_color_control , &H000D)
Waitms 50
Call Ili9325_write_reg(horizontal_gram_address , &H0000)
Call Ili9325_write_reg(vertical_gram_address , &H0000)
Call Ili9325_write_reg(gamma_control_1 , &H0000)
Call Ili9325_write_reg(gamma_control_2 , &H0707)
Call Ili9325_write_reg(gamma_control_3 , &H0307)
Call Ili9325_write_reg(gamma_control_4 , &H0200)
Call Ili9325_write_reg(gamma_control_5 , &H0008)
Call Ili9325_write_reg(gamma_control_6 , &H0004)
Call Ili9325_write_reg(gamma_control_7 , &H0000)
Call Ili9325_write_reg(gamma_control_8 , &H0707)
Call Ili9325_write_reg(gamma_control_9 , &H0002)
Call Ili9325_write_reg(gamma_control_10 , &H1D04)
Call Ili9325_write_reg(horizontal_add_start_position , &H0000)
Call Ili9325_write_reg(horizontal_add_end_position , &H00EF)
Call Ili9325_write_reg(vertical_add_start_position , &H0000)
Call Ili9325_write_reg(vertical_add_end_position , &H013F)
Call Ili9325_write_reg(driver_output_control_2 , &B0010_0111_0000_0000)
Call Ili9325_write_reg(base_image_display_control , &H0001)
Call Ili9325_write_reg(vertical_scroll_control , &H0000)
Call Ili9325_write_reg(partial_image_1_display_position , &H0000)
Call Ili9325_write_reg(partial_image_1_area_start_line , &H0000)
Call Ili9325_write_reg(partial_image_1_area_end_line , &H0000)
Call Ili9325_write_reg(partial_image_2_display_position , &H0000)
Call Ili9325_write_reg(partial_image_2_area_start_line , &H0000)
Call Ili9325_write_reg(partial_image_2_area_end_line , &H0000)
Call Ili9325_write_reg(panel_interface_control_1 , &H0013)
Call Ili9325_write_reg(panel_interface_control_2 , &H0000)
Call Ili9325_write_reg(panel_interface_control_3 , &H0003)
Call Ili9325_write_reg(panel_interface_control_4 , &H0110)
Call Ili9325_write_reg(panel_interface_control_5 , &H0000)
Call Ili9325_write_reg(panel_interface_control_6 , &H0000)

Call Ili9325_write_reg(display_control_1 , &B0000_0101_0011_0011)
Cs_disp = 0
Rs_disp = 0
End Sub

 

Declare sub ili9325_write_reg(byval Index as Byte, Byval Daten as Word)

 

'-------------------------------------------------------------------------------
' Ili9325_write_reg Write 16 Bit Data to Index Register
'-------------------------------------------------------------------------------
Sub Ili9325_write_reg(byval Index As Byte , Daten As Word)
Cs_disp = 0
Rs_disp = 0
Data_disp = &H0 'VH
NOP : NOP
Wr_disp = 0
NOP : NOP
Wr_disp = 1
Data_disp = Index 'VL
NOP : NOP
Wr_disp = 0
NOP : NOP
Wr_disp = 1
Rs_disp = 1
Data_disp = High(daten) 'VH
NOP : NOP
Wr_disp = 0
NOP : NOP
Wr_disp = 1
Data_disp = Low(daten) 'VL
NOP : NOP
Wr_disp = 0
NOP : NOP
Wr_disp = 1
Cs_disp = 1
End Sub

 

Declare sub ili9325_write_data(byval Daten as Word)
 

'-------------------------------------------------------------------------------
' Ili9320_write_data Write 16 Bit Data to Display
'-------------------------------------------------------------------------------
Sub Ili9325_write_data(byref Daten As Word)
Cs_disp = 0
Rs_disp = 1
Data_disp = High(daten)
NOP : NOP
Wr_disp = 0
NOP : NOP
Wr_disp = 1
Data_disp = Low(daten)
NOP : NOP
Wr_disp = 0
NOP : NOP
Wr_disp = 1
Cs_disp = 1
End Sub

 

Declare sub ili9325_select_reg(byval Index as Byte)

 

'-------------------------------------------------------------------------------
' ILI9320_select_reg Select an index register
'-------------------------------------------------------------------------------
Sub Ili9325_select_reg(byval Index As Byte )
Cs_disp = 0
Rs_disp = 0
Data_disp = 0
NOP : NOP
Wr_disp = 0
NOP : NOP
Wr_disp = 1
Data_disp = Index
NOP : NOP
Wr_disp = 0
NOP : NOP
Wr_disp = 1
Cs_disp = 1
End Sub

 

Declare sub ili9325_exit_sleep()

 

'-------------------------------------------------------------------------------
'Ili9325_exit_sleep Exit Sleep Mode
'-------------------------------------------------------------------------------
Sub Ili9325_exit_sleep()
'Power On sequence
Call Ili9325_write_reg(power_control_1 , &H0000)
Call Ili9325_write_reg(power_control_2 , &H0000)
Call Ili9325_write_reg(power_control_3 , &H0000)
Call Ili9325_write_reg(power_control_4 , &H0000)
Waitms 200
Call Ili9325_write_reg(power_control_1 , &H1590)
Call Ili9325_write_reg(power_control_2 , &H0007)
Waitms 50
Call Ili9325_write_reg(power_control_3 , &H013A)
Waitms 50
Call Ili9325_write_reg(power_control_4 , &H1500)
Call Ili9325_write_reg(power_control_7 , &H0000)
Waitms 50
Call Ili9325_write_reg(display_control_1 , &H0133)
End Sub

 

Declare sub ili9325_enter_sleep()
 

'-------------------------------------------------------------------------------
'Ili9320_enter_sleep Enter Sleep Mode
'-------------------------------------------------------------------------------
Sub Ili9325_enter_sleep()
'Power Off sequence
Call Ili9325_write_reg(display_control_1 , &H0000)
Call Ili9325_write_reg(power_control_1 , &H0000)
Call Ili9325_write_reg(power_control_2 , &H0000)
Call Ili9325_write_reg(power_control_3 , &H0000)
Call Ili9325_write_reg(power_control_4 , &H0000)
Waitms 200
Call Ili9325_write_reg(power_control_1 , &H0002)
End Sub

 

Declare sub ili9325_scroll(byval lines as word)

 

'-------------------------------------------------------------------------------
' Ili9325_scroll
'-------------------------------------------------------------------------------
Sub Ili9325_scroll(byval Lines As Word )
Call Ili9325_write_reg(base_image_display_control , &B0000_0000_0000_0011 )
Call Ili9325_write_reg(vertical_scroll_control , Lines)
End Sub

 

Declare sub ili9325_set_window(byval xpos as word, byval ypos as word, byval xsize as word, byval ysize as word)
 

'-------------------------------------------------------------------------------
' Ili9325_set_window Set Window Area to write
'-------------------------------------------------------------------------------
Sub Ili9325_set_window(byval Xpos As Word , Byval Ypos As Word , Byval Xsize As Word , Byval Ysize As Word)
Local X_add As Word , Y_add As Word

Y_add = Y_pixel - Ypos
Ypos = Y_add - Ysize

X_add = X_pixel - Xpos
Xpos = X_add - Xsize

Incr Xpos
Incr Ypos

Call Ili9325_write_reg(horizontal_add_start_position , Xpos)
' Horizontal GRAM Start Address-----HSA[7:0]
Call Ili9325_write_reg(horizontal_add_end_position , X_add)
' Horizontal GRAM End Address-----HEA[7:0]
Call Ili9325_write_reg(vertical_add_start_position , Ypos)
'Vertical GRAM Start Address-----VSA[8:0]
Call Ili9325_write_reg(vertical_add_end_position , Y_add)
'Vertical GRAM Start Address-----VEA[8:0]

Call Ili9325_write_reg(horizontal_gram_address , X_add)
Call Ili9325_write_reg(vertical_gram_address , Ypos)
Call Ili9325_select_reg(write_data_to_gram)
End Sub

 

Declare sub ili9325_negate(byval art as word)

 

'-------------------------------------------------------------------------------
' Ili9325_negate art=0 -> negative art=1 -> normal
'-------------------------------------------------------------------------------
Sub Ili9325_negate(byval Art As Word )
If Art = 1 Then
Art = 1
Else
Art = 0
End If
Call Ili9325_write_reg(base_image_display_control , Art )

End Sub

 

Declare sub ili9325_set_pixel(byval x1 as word, y1 as word, byval color as word)

 

'-------------------------------------------------------------------------------
' ILI9325_set_pixel Set one Pixel in given color
'-------------------------------------------------------------------------------
Sub Ili9325_set_pixel(byval X1 As Word , Y1 As Word , Color As Word)
Call Ili9325_set_cursor(x1 , Y1)
Call Ili9325_write_reg(write_data_to_gram , Color)
End Sub

 

Declare sub ili9325_set_cursor(byval x as word, byval y as word)
 

'-------------------------------------------------------------------------------
' ILI9325_Set_Cursor(X, Y) 1-240; 1-320
'-------------------------------------------------------------------------------
Sub Ili9325_set_cursor(byval X As Word , Y As Word )
If Display_modus = 1 Then
Swap X , Y
X = X_pixel - X
End If
If Display_modus = 2 Then
X = X_pixel - X
Y = Y_pixel - Y
End If
Call Ili9325_write_reg(horizontal_gram_address , X)
Call Ili9325_write_reg(vertical_gram_address , Y)
End Sub

 

Declare sub ili9325_text(byval lcd_text as string, byval lcd_posx as word, byval lcd_posy as word, byval fontset as byte, byval forecolor as word, byval backcolor as word)
 

'-------------------------------------------------------------------------------
' Ili9325_text
'-------------------------------------------------------------------------------
Sub Ili9325_text(byval Lcd_text As String , Byval Lcd_posx As Word , Byval Lcd_posy As Word , Byval Fontset As Byte , Byval Forecolor As Word , Byval Backcolor As Word)

Local Pzeichen As String * 1
Dim Zeichenarray(40) As Byte
Local Zeichen_row As Word
Local Ptemp As Word
Local Ptemp2 As Word
Local Px As Word
Local Py As Word
Local Char_rows As Byte
Local Char_row_len As Byte
Local Char_bytes As Byte
Local Dummy As Byte
Local String_pos As Byte
Local Zeichen_code As Word

For String_pos = 1 To Len(lcd_text) 'F\FCr jedes Zeichen im String
If Fontset = 2 Then
Restore Font12x16
Else
Restore Font8x8
End If
Read Char_rows : Read Char_row_len : Read Char_bytes : Read Dummy 'Read the first 4 bytes from the font file

Pzeichen = Mid(lcd_text , String_pos , 1) 'Ein Zeichen aus String holen
Zeichen_code = Asc(pzeichen) - 32 'Font files start with caracter 32
' move Pointer to char
Zeichen_code = Zeichen_code * Char_bytes
For Px = 1 To Zeichen_code 'Do dummie read to point to the correct line in the fontfile
Read Dummy
Next Px
'Read Char Byte Array
For Px = 1 To Char_bytes 'Do dummie read to point to the correct line in the fontfile
Read Zeichenarray(px)
Next Px
'set canvas area
Py = Char_rows * 8
Incr Py
Px = String_pos - 1
Px = Px * Char_row_len
Px = Px + Lcd_posx
Ptemp = Char_row_len
Call Ili9325_set_window(px , Lcd_posy , Ptemp , Py)
Cs_disp = 0
'Write Data
Rs_disp = 1
For Py = Char_rows To 1 Step -1
Ptemp = Py - 1
Ptemp = Ptemp * Char_row_len
For Zeichen_row = 7 To 0 Step -1
' For Px = Char_row_len To 1 Step - 1
For Px = 1 To Char_row_len
Ptemp2 = Ptemp + Px
If Zeichenarray(ptemp2).zeichen_row = 1 Then
Data_disp = High(forecolor)
NOP
Wr_disp = 0
NOP
Wr_disp = 1
Data_disp = Low(forecolor)
NOP
Wr_disp = 0
NOP
Wr_disp = 1
Else
Data_disp = High(backcolor)
NOP
Wr_disp = 0
NOP
Wr_disp = 1
Data_disp = Low(backcolor)
NOP
Wr_disp = 0
NOP
Wr_disp = 1
End If
Next Px
Next Zeichen_row
Next Py
'Topline in Backcolor
For Px = 1 To Char_row_len
Call Ili9325_write_data(backcolor)
Next
Next String_pos
Set Cs_disp
End Sub

Declare sub ili9325_line(byval X1 as word, byval Y1 as word, byval X2 as word, byval y2 as word, byval pen_width as byte, byval color as word)
 

'-------------------------------------------------------------------------------
' ILI9325_line pixel line left-top (x1,y1) right-bottom(x2,y2),
' Pen Width in Pixel(byte), color($0000-$FFFF)
'-------------------------------------------------------------------------------
Sub Ili9325_line(byval X1 As Word , Byval Y1 As Word , Byval X2 As Word , Byval Y2 As Word , Byval Pen_width As Byte , Byval Color As Word)
Local Y As Word , X As Word , X_diff As Single , Y_diff As Single , Pos As Word
Local X_factor As Single , X_pos As Word , Y_pos As Word , Base As Word , Pen_count As Byte

If X1 > X_pixel Then X1 = X_pixel
If X2 > X_pixel Then X2 = X_pixel
If Y1 > Y_pixel Then Y1 = Y_pixel
If Y2 > Y_pixel Then Y2 = Y_pixel
Y_diff = Y2 - Y1
X_diff = X2 - X1
Pos = 0

X_factor = Abs(y_diff)
Y = X_factor
X_factor = Abs(x_diff)
X = X_factor

If Y > X Then
X_factor = X_diff / Y_diff
If Y1 > Y2 Then
Swap Y1 , Y2
Base = X2
Else
Base = X1
End If
For Y = Y1 To Y2
X_diff = Pos * X_factor
X_pos = X_diff
X_pos = X_pos + Base
Call Ili9325_set_pixel(x_pos , Y , Color)
For Pen_count = 2 To Pen_width
Call Ili9325_write_data(color)
Next Pen_count
Incr Pos
Next Y
Else
X_factor = Y_diff / X_diff
If X1 > X2 Then
Swap X1 , X2
Base = Y2
Else
Base = Y1
End If
For X = X1 To X2
Y_diff = Pos * X_factor
Y_pos = Y_diff
Y_pos = Y_pos + Base
Call Ili9325_set_pixel(x , Y_pos , Color)
For Pen_count = 2 To Pen_width
Call Ili9325_write_data(color)
Next Pen_count
Incr Pos
Next X
End If
End Sub

 

Declare sub ili9325_box(byval X1 as word, byval Y1 as word, byval X2 as word, byval Y2 as word, byval Fill-color as word, byval border_color as word, byval fill as byte, byval showborder as byte)
 

'-------------------------------------------------------------------------------
' ILI9325_box left-top (x1,y1) right-bottom(x2,y2)
' Fill_color, Border_color $0000-$ffff
' fill > 0 , Show_border > 0
'-------------------------------------------------------------------------------
Sub Ili9325_box(byval X1 As Word , Byval Y1 As Word , Byval X2 As Word , Byval Y2 As Word , Byval Fill_color As Word , Byval Border_color As Word , Byval Fill As Byte , Byval Show_border As Byte)
Local X_counter As Word , Y_counter As Word , X_pos1 As Word , X_pos2 As Word
If X1 > X2 Then Swap X1 , X2
If Y1 > Y2 Then Swap Y1 , Y2
If Show_border > 0 Then
Call Ili9325_line(x1 , Y1 , X2 , Y1 , 1 , Border_color)
Call Ili9325_line(x1 , Y2 , X2 , Y2 , 1 , Border_color)
Incr Y1
Decr Y2
Else
X_pos1 = X1
X_pos2 = X2 - 1
End If
For Y_counter = Y1 To Y2
If Show_border > 0 Then
Call Ili9325_set_cursor(x1 , Y_counter)
Call Ili9325_write_reg(write_data_to_gram , Border_color)
End If
If Fill > 0 Then
If Show_border > 0 Then
X_pos1 = X1 + 2
X_pos2 = X2 - 1
Call Ili9325_write_reg(write_data_to_gram , Fill_color)
Else
Call Ili9325_set_cursor(x1 , Y_counter)
Call Ili9325_write_reg(write_data_to_gram , Fill_color)
End If
For X_counter = X_pos1 To X_pos2
Call Ili9325_write_data(fill_color)
Next X_counter
If Show_border > 0 Then
Call Ili9325_write_reg(write_data_to_gram , Border_color)
End If
Else
If Show_border > 0 Then
Call Ili9325_set_cursor(x2 , Y_counter)
Call Ili9325_write_reg(write_data_to_gram , Border_color)
End If
End If
Next Line_counter
End Sub

 

Declare sub ili9325_lineto(byval x as word, byval y as word, byval pen_width as byte, byval color as byte)

 

'-------------------------------------------------------------------------------
' ILI9325_Lineto x,y screen pos, pen width, color border
'-------------------------------------------------------------------------------
Sub Ili9325_lineto(byval X As Word , Byval Y As Word , Byval Pen_width As Byte , Byval Color As Word)
Call Ili9325_line(move_x , Move_y , X , Y , Pen_width , Color )
Move_x = X
Move_y = Y
End Sub

 

Declare sub ili9325_moveto(byval x as word, y as word)
 

'-------------------------------------------------------------------------------
' ILI9325_Moveto x,y screen pos
'-------------------------------------------------------------------------------
Sub Ili9325_moveto(byval X As Word , Byval Y As Word)
Call Ili9325_set_cursor(x , Y)
Move_x = X
Move_y = Y
End Sub

 

Declare sub ili9325_drawcircle(byval centerx as word, byval centery as word, byval radius as word, byval sides as word, byval pen_width as byte, byval color as word)
 

'-------------------------------------------------------------------------------
' ILI9325_circle centerX, centerY, radius, sides, pen width, color Border
'-------------------------------------------------------------------------------

'deze routine nog in orde maken

Sub Ili9325_drawcircle(byval Centerx As Word , Byval Centery As Word , Byval Radius As Word , Byval Sides As Word , Byval Pen_width As Byte , Byval Color As Word)
Local I As Word
Local Pointratio As Single
Local Xsteps As Single , Ysteps As Single
Local Pointx As Single , Pointy As Single
Local X As Word , Y As Word

I = Centerx + Radius

Call Ili9325_moveto(i , Centery)
Out_of_range = 0

For I = 0 To Sides
Pointratio = I / Sides
Xsteps = Ili9325_trigfunctionx(pointratio)
Ysteps = Ili9325_trigfunctiony(pointratio)
Pointx = Xsteps * Radius
Pointx = Centerx + Pointx
X = Pointx
Pointy = Ysteps * Radius
Pointy = Centery + Pointy
Y = Pointy

If X < X_pixel And Y < Y_pixel Then
If Out_of_range = 1 Then
Call Ili9325_moveto(x , Y)
Out_of_range = 0
End If
Call Ili9325_lineto(x , Y , Pen_width , Color)
Else
Out_of_range = 1
End If
Next
End Sub

 
Declare sub ili9325_drawarc(byval centerx as word, byval centery as word, byval radius as word, byval startangle as word, byval arcangle as word, byval steps as word, byval pen_width as byte, byval color as word)
 

'-------------------------------------------------------------------------------
' Ili9325_drawarc centerX, centerY, radius, sides, pen width, color Border
'-------------------------------------------------------------------------------
'
Sub Ili9325_drawarc(byval Centerx As Word , Byval Centery As Word , Byval Radius As Word , Byval Startangle As Word , Byval Arcangle As Word , Byval Steps As Word , Byval Pen_width As Byte , Byval Color As Word)
Local Twopi As Single , I As Word
Local Anglestep As Single , Tmp_single As Single
Local X As Word , Y As Word
Local Xx As Single , Yy As Single , Startangle_temp As Single , Arcangle_temp As Single , Angle As Single

Startangle_temp = Startangle / 360
'disabling following line gives great effects!
Arcangle_temp = Arcangle / 360

Twopi = 2 * Pi
Anglestep = Arcangle_temp / Steps

Tmp_single = Startangle_temp * Twopi
Xx = Cos(tmp_single)
Xx = Xx * Radius
Xx = Xx + Centerx
X = Xx

Yy = Sin(tmp_single)
Yy = Yy * Radius
Yy = Yy + Centery
Y = Yy

Call Ili9325_moveto(x , Y)
Out_of_range = 0

For I = 1 To Steps
Angle = I * Anglestep
Angle = Angle + Startangle_temp
Tmp_single = Angle * Twopi
Xx = Cos(tmp_single)
Xx = Xx * Radius
Xx = Xx + Centerx
X = Xx
Yy = Sin(tmp_single)
Yy = Yy * Radius
Yy = Yy + Centery
Y = Yy
If X < X_pixel And Y < Y_pixel Then
If Out_of_range = 1 Then
Call Ili9325_moveto(x , Y)
Out_of_range = 0
End If
Call Ili9325_lineto(x , Y , Pen_width , Color)
Else
Out_of_range = 1
End If
Next
End Sub

 

Declare sub ili9325_drawrect(byval x1 as word, byval y1 as word, byval x2 as word, byval y2 as word, byval pen_width as byte, byval color as word)
 

'-------------------------------------------------------------------------------
' Ili9325_drawrect X, Y, Xx, Yy, pen width, color Border
'-------------------------------------------------------------------------------
'
Sub Ili9325_drawrect(byval X1 As Word , Byval Y1 As Word , Byval X2 As Word , Byval Y2 As Word , Byval Pen_width As Byte , Byval Color As Word)

If X1 > X2 Then
Swap X1 , X2
End If
If Y1 > Y2 Then
Swap Y1 , Y2
End If

Call Ili9325_line(x1 , Y1 , X2 , Y1 , Pen_width , Color) '------
Call Ili9325_line(x2 , Y1 , X2 , Y2 , Pen_width , Color) ' !
Call Ili9325_line(x1 , Y2 , X2 , Y2 , Pen_width , Color) '------
Call Ili9325_line(x1 , Y1 , X1 , Y2 , Pen_width , Color) '!
End Sub

 
Declare sub ili9325_showpicture(byval xoffset as word, byval yoffset as word)  ‘Draw an Bascom BGC image on the lcd
 

'-------------------------------------------------------------------------------
' Ili9325_showpicture Xoffset, Yoffset
'-------------------------------------------------------------------------------
'
' Important that you first RESTORE the image before calling this sub. Examp: [ Restore Plaatje ]
'
Sub Ili9325_showpicture(byval Xoffset As Word , Byval Yoffset As Word) 'Draw an Bascom BGC image on the lcd
Local Ysize As Byte , Xsize As Byte
Local Imagesize As Word
Local L As Word , Pixel As Byte ,
Local Pixelword As Word , Prevpixel As Word , Repeat As Byte
Local X1size As Word , Y1size As Word
Call Ili9325_write_reg(entry_mode , &B0001000000_00_0_000 ) 'onderkant foto onder, kopje naar links

Read Ysize 'Read the first 4 bytes from the BGC, this contains info about the image
Read Xsize
Read Imagesize 'Byte 3&4 contains the image size

X1size = Xsize
Y1size = Ysize

Call Ili9325_set_window(xoffset , Yoffset , X1size , Y1size)

Do
Read Pixel 'Read the value for the pixel
If Pixel = &HAA Then 'BGC file is rle coded &HAA represents this, the byte after &HAA is the number of times that the byte before &HAA wil be repeated
Read Repeat 'Byte after &HAA contains the number of times to repeat
Repeat = Repeat - 1
For L = 1 To Repeat 'Loop the repeat
Call Ili9325_write_data(prevpixel) 'Write the pixel data to the display
Decr Imagesize 'Decrease the bytes still to be processed
Next L 'Next repeat loop
Else 'It's a regular byte, not LRE encoded
Pixelword = Ili9325_rgb16(pixel) 'Convert the 8bit pixel to 16bit pixel
Call Ili9325_write_data(pixelword) 'Write the pixel data to the display
Prevpixel = Pixelword 'Store the pixel in a temp word, maybe we need it if the next byte is &HAA
Decr Imagesize 'Decrease the bytes still to be processed
End If
Loop Until Imagesize = 0 'Do until all bytes are processed

Modus = 2
'4096 &B0001000000000000 ' I/D[1:0] AM richting schrijven...
If Modus = 2 Then
Direction = 2
Direction = Direction Or &B0001000000_10_0_000 '4096 &B0001000000000000 ' I/D[1:0] AM richting schrijven...
Call Ili9325_write_reg(entry_mode , Direction)
X_pixel = 240
Y_pixel = 320
End If
Call Ili9325_set_window(1 , 1 , 240 , 320)
End Sub

 

Declare sub ili9325_clear(byval color as word, byval direction as word)
 

'-------------------------------------------------------------------------------
' ILI9325_Clear Clear LCD with color
'-------------------------------------------------------------------------------
Sub Ili9325_clear(byval Color As Word , Byval Direction As Word) 'direction = 0,1,2,3
Local Ili9325_count_color As Long
Local Flag As Byte
Local Zz As Word
If Direction = 2 Then Flag = 1
Select Case Direction
Case 0 : Direction = Direction Or &B0001000000_01_0_000
Case 1 : Direction = Direction Or &B0001000000_10_0_000
Case 2 : Direction = Direction Or &B0001000000_01_1_000
Case 3 : Direction = Direction Or &B0001000000_10_1_000
End Select
Call Ili9325_write_reg(entry_mode , Direction)
Call Ili9325_set_window(1 , 1 , X_pixel , Y_pixel)
Cs_disp = 0
Rs_disp = 1
For Ili9325_count_color = 1 To 76800
Data_disp = High(color)
NOP
!cbi portg,_Wr_disp '= 0
NOP
!sbi portg,_Wr_disp '= 1
Data_disp = Low(color)
NOP
!cbi portg,_Wr_disp ' = 0
NOP
!sbi portg,_Wr_disp '= 1
Next
Cs_disp = 1
Modus = 2
'4096 &B0001000000000000 ' I/D[1:0] AM richting schrijven...
Direction = 2
Direction = Direction And 3
Shift Direction , Left , 4
Direction = Direction Or &B0001000000_00_0_000 '4096 &B0001000000000000 ' I/D[1:0] AM richting schrijven...
Call Ili9325_write_reg(entry_mode , Direction)
X_pixel = 240
Y_pixel = 320
End Sub

 

Declare sub ili9325_draw_bmp(byval filename as string, byval xpos as word, byval ypos as word)
 

'-------------------------------------------------------------------------------
' Ili9320_draw_bmp
'-------------------------------------------------------------------------------
'
Sub Ili9325_draw_bmp(byval Filename As String , Byval Xpos As Word , Byval Ypos As Word)
Dim Rgb_data(1500) As Byte
Dim Palette(1024) As Byte At Rgb_data(400) Overlay
Dim Rgb(3) As Byte
Local X As Word
'Dim Line_len As Word
'Dim Line_byte As Word
Local Y As Single , Z As Word , Line_count As Word
'Dim Bmp_read_pos As Long

' Bitmap Info Header
Local Bftype As Word
Local Bfsize As Long
Local Bfoffbits As Long
Local Bisize As Long
Local Biplanes As Word
Local Bibitcount As Word
Local Bicompression As Long
Local Bisizeimage As Long
Local Bixpelspermeter As Long
Local Biypelspermeter As Long
Local Biclrused As Long
Local Biclrimportant As Long

Reset Mmc_cs
' Set Control_disp.cs_touch
Open Filename For Binary As #10

Get #10 , Bftype , &H01 '&H00 + 1
Get #10 , Bfsize , &H03 '&H02 + 1
Get #10 , Bfoffbits , &H0B '&H0A + 1
Get #10 , Bisize , &H0F '&H0E + 1
Get #10 , Biwidth , &H013 '&H12 + 1
Get #10 , Biheight , &H017 '&H16 + 1
Get #10 , Biplanes , &H1B '&H1A + 1
Get #10 , Bibitcount , &H1D '&H1C + 1
Get #10 , Bicompression , &H1F '&H1E + 1
Get #10 , Bisizeimage , &H23 '&H22 + 1
Get #10 , Bixpelspermeter , &H27 '&H26 + 1
Get #10 , Biypelspermeter , &H2B '&H2A + 1
Get #10 , Biclrused , &H2F '&H2E + 1
Get #10 , Biclrimportant , &H33 '&H32 + 1

'(

Beispiel:
- - - - - - - Bmp Info Header - - - - - - -
Bftype : 19778
Bfsize : 224054
Bfoffbits : 54
Bisize : 40
Biwidth : 233px
Biheight : 320px
Biplanes : 1
Bibitcount : 24
Bicompression : 0
Bisizeimage : 224000
Bixpelspermeter : 2834
Biypelspermeter : 2834
Biclrused : 0
Biclrimportant : 0


Add
0 Word 2 Byte Bftype Ascii -zeichenkette "BM"(dezimalwert 19778).
2 Dword 4 Byte Bfsize Gr\F6\DFe Der Bmp -datei In Byte.(unzuverl\E4ssig)
6 Dword 4 Byte Bfreserved 0
A Dword 4 Byte Bfoffbits Offset Der Bilddaten In Byte Vom Beginn Der Datei An.
E Dword 4 Byte Bisize 40(gr\F6\DFe Der Bitmapinfoheader -struktur In Byte)
12 Long 4 Byte Biwidth Breite Der Bitmap In Pixel.
16 Long 4 Byte Biheight Der Betrag Gibt Die H\F6he Der Bitmap In Pixel An.

* Ist der Wert positiv, so ist die Bitmap eine sogenannte "bottom-up"-Bitmap (die Bilddaten beginnen mit der untersten und enden mit der obersten Bildzeile). Dies ist die gebr\E4uchlichste Variante.
* Ist der Wert negativ, so ist die Bitmap eine "top-down"-Bitmap (die Bilddaten beginnen mit der obersten und enden mit der untersten Bildzeile).

1a Word 2 Byte Biplanes 1(stand In Einigen \E4lteren Formaten Wie Pcx F\FCr Die Anzahl Der Farbebenen , Wird Aber F\FCr Bmp Nicht Verwendet)
1c Word 2 Byte Bibitcount Gibt Die Farbtiefe Der Bitmap In Bpp An ; Muss Einer Der Folgenden Werte Sein : 1 , 4 , 8 , 16 , 24 Oder 32. Bei 1 , 4 Und 8 Bpp Sind Die Farben Indiziert. 16 Und 32 Bpp Sind Ungebr\E4uchlich.
1e Dword 4 Byte Bicompression Einer Der Folgenden Werte:

* 0 (BI_RGB): Bilddaten sind unkomprimiert.
* 1 (BI_RLE8): Bilddaten sind laufl\E4ngenkodiert f\FCr 8 bpp. Nur erlaubt wenn biBitCount=8 und biHeight positiv.
* 2 (BI_RLE4): Bilddaten sind laufl\E4ngenkodiert f\FCr 4 bpp. Nur erlaubt wenn biBitCount=4 und biHeight positiv.
* 3 (BI_BITFIELDS): Bilddaten sind unkomprimiert und benutzerdefiniert (mittels Farbmasken) kodiert. Nur erlaubt wenn biBitCount=16 oder 32; ungebr\E4uchlich.

22 Dword 4 Byte Bisizeimage

* Wenn biCompression=BI_RGB: Entweder 0 oder die Gr\F6\DFe der Bilddaten in Byte.
* Ansonsten: Gr\F6\DFe der Bilddaten in Byte.

26 Long 4 Byte Bixpelspermeter Horizontale Aufl\F6sung Des Zielausgabeger\E4tes In Pixel Pro Meter ; Wird Aber F\FCr Bmp -dateien Meistens Auf 0 Gesetzt.
2a Long 4 Byte Biypelspermeter Vertikale Aufl\F6sung Des Zielausgabeger\E4tes In Pixel Pro Meter ; Wird Aber F\FCr Bmp -dateien Meistens Auf 0 Gesetzt.
2e Dword 4 Byte Biclrused

* Wenn biBitCount=1: 0.
* Wenn biBitCount=4 oder 8: die Anzahl der Eintr\E4ge der Farbtabelle; 0 bedeutet die maximale Anzahl (16 bzw. 256).
* Ansonsten: Die Anzahl der Eintr\E4ge der Farbtabelle (0=keine Farbtabelle). Auch wenn sie in diesem Fall nicht notwendig ist, kann dennoch eine f\FCr die Farbquantisierung empfohlene Farbtabelle angegeben werden.

32 Dword 4 Byte Biclrimportant

* Wenn biBitCount=1, 4 oder 8: Die Anzahl s\E4mtlicher im Bild verwendeten Farben; 0 bedeutet alle Farben der Farbtabelle.
* Ansonsten:
O Wenn Eine Farbtabelle Vorhanden Ist Und Diese S\E4mtliche Im Bild Verwendeten Farben Enth\E4lt : Deren Anzahl.
O Ansonsten : 0.

Pixeldaten 3 Pro Pixel. Nach Jeder Zeile Wird Die Pixelfolge Mit Null -bytes Auf Eine Durch 4 Teilbare Anzahl Erg\E4nzt.

')
'(
Print #1 , "------- BMP INFO HEADER -------"
Print #1 , "Bftype : " ; Bftype
Print #1 , "Bfsize : " ; Bfsize
Print #1 , "Bfoffbits : " ; Bfoffbits
Print #1 , "Bisize : " ; Bisize
Print #1 , "Biwidth : " ; Biwidth ; " Px"
Print #1 , "Biheight : " ; Biheight ; " Px"
Print #1 , "Biplanes : " ; Biplanes
Print #1 , "Bibitcount : " ; Bibitcount
Print #1 , "Bicompression : " ; Bicompression
Print #1 , "Bisizeimage : " ; Bisizeimage
Print #1 , "Bixpelspermeter : " ; Bixpelspermeter
Print #1 , "Biypelspermeter : " ; Biypelspermeter
Print #1 , "Biclrused : " ; Biclrused
Print #1 , "Biclrimportant : " ; Biclrimportant

')

Call Ili9325_set_window(xpos , Ypos , Biwidth , Biheight)
Call Ili9325_write_reg(write_data_to_gram , 0)

Config Single = Scientific , Digits = 1

If Bibitcount = 24 Then
' position behind BMP Header Data
Bmp_read_pos = Bfoffbits + 1
' we need line length divideable by 4!
Line_byte = Biwidth * 3
Line_len = Biwidth Mod 4
Line_len = Line_byte + Line_len
Set Rs_disp
Reset Cs_disp

Seek #10 , Bmp_read_pos

!LDS R30, {Biheight} 'Anzahl lines in y-Register
!LDS R31, {Biheight+1}
!SBIW R30, 1

Loop_rows:
!push R30
!push R31
Get #10 , Rgb_data(1) , , Line_len

'THX MWS!!!!
!LDS R30, {Biwidth} 'Anzahl Pixel/line in Z-Register
!LDS R31, {Biwidth+1}

Loadadr Rgb_data(1) , X

Loop_line:
!LD R16, X+ ' blau in R16
!LD R17, X+ ' gruen in R17
!LD R18, X+ ' rot in R18
!ANDI R18, &b11111000 ' unnoetiges ausmaskieren

'GR\DCN
!ROL R17 ' 4 mal rotieren, da erstes Bit zuerst ins Carry geht
!ROL R17
!ROL R17
!ROL R17 ' Bits 7..5 von gruen sind nun an Bit 2..0 fuer Rgb_HB
!MOV R24, R17 ' nach R24 sichern
!ROR R17 ' 1 mal aus dem Carry zur\FCck rotieren, um die Bits 4..2 auf 7..5 zu bekommen
!ANDI R17, &b11100000 ' Bit 7..5 von gruen maskieren, fuer Rgb_LB
!ANDI R24, &b00000111 ' Bit 2..0 maskieren fuer Rgb_HB

'BLAU
!LSR R16 ' R16, blau 3mal rechts schieben
!LSR R16
!LSR R16
!OR R17, R16 ' mit bereits vorhanden Bits in Rgb_LB verodern
Nop : Nop
!STS Data_disp, R17
NOP : NOP
!sbi portg,_wr_disp 'Set Wr_disp
NOP : NOP
!cbi portg,_wr_disp 'Reset Wr_disp

'ROT
!OR R24, R18 ' Rgb_HB speichern
!STS Data_disp, R24
NOP : NOP
!sbi portg,_wr_disp 'Set Wr_disp
NOP : NOP
!cbi portg,_wr_disp

Nop : Nop 'Reset Wr_disp
!SBIW R30, 1 'decr Z-Register
!BRNE Loop_line
!pop R31
!pop R30
!SBIW R30, 1 'decr Z-Register
!BREq End_rows
!Rjmp Loop_rows
End_rows:
Set Cs_disp
End If

If Bibitcount = 8 Then
'load color table
'Jeder Eintrag der Farbtabelle ist 4 Byte gro\DF und enth\E4lt
'jeweils ein Byte f\FCr den Blau-, Gr\FCn- und Rotanteil, sowie ein auf 0 gesetztes Byte (in dieser Reihenfolge!).
Bmp_read_pos = 55
Get #10 , Palette(1) , Bmp_read_pos , 1024
Line_byte = Biwidth
Line_len = Line_byte
' position behind BMP Header Data
Bmp_read_pos = Bfoffbits + 1
Reset Cs_disp
While Bmp_read_pos < Bfsize
Get #10 , Rgb_data(1) , Bmp_read_pos , Line_len
For X = 1 To Line_byte
'point to palette entry
Z = 4 * Rgb_data(x)
'asm von MagicWhiteSmoke thx!
Loadadr Palette(z + 1) , X
!LD R16, x+ ' blau in R16
!LD R17, x+ ' gruen in R17
!LD R18, x ' rot in R18
!ANDI R18, &b11111000 ' unnoetiges ausmaskieren
'GR\DCN
!ROL R17 ' 4 mal rotieren, da erstes Bit zuerst ins Carry geht
!ROL R17
!ROL R17
!ROL R17 ' Bits 7..5 von gruen sind nun an Bit 2..0 fuer Rgb_HB
!MOV R24, R17 ' nach R24 sichern
!ROR R17 ' 1 mal aus dem Carry zur\FCck rotieren, um die Bits 4..2 auf 7..5 zu bekommen
!ANDI R17, &b11100000 ' Bit 7..5 von gruen maskieren, fuer Rgb_LB
!ANDI R24, &b00000111 ' Bit 2..0 maskieren fuer Rgb_HB

'BLAU
!LSR R16 ' R16, blau 3mal rechts schieben
!LSR R16
!LSR R16
!OR R17, R16 ' mit bereits vorhanden Bits in Rgb_LB verodern
!STS Data_disp, R17
NOP : NOP
!sbi portg,_Wr_disp
NOP : NOP
!cbi portg,_wr_disp 'Reset Wr_disp

'ROT
!OR R24, R18 ' Rgb_HB speichern
!STS Data_disp, R24
NOP : NOP
!sbi portg,_wr_disp 'Set Wr_disp
NOP : NOP
!cbi portg,_wr_disp 'Reset Wr_disp
Next
Bmp_read_pos = Bmp_read_pos + Line_len
Wend
Set Cs_disp
End If

Close #10

Call Ili9325_set_window(1 , 1 , 240 , 320)
Config Single = Scientific , Digits = 7
End Sub

 


 

Original BMP-picture 24 bit color

On the display with the ili9325_draw_bmp routine

 

Declare Function ili9325_rgb16(byval Rgb8 As Byte) As Word
 

Function Ili9325_rgb16(byval Rgb8 As Byte) As Word
'Convert the 8bit RRRGGGBB bgc data to 16 bit RRRRRGGGGGGBBBBB
Local Rd8 As Byte , Gr8 As Byte , Bl8 As Byte
Local Rd16 As Word , Gr16 As Word , Bl16 As Word , Tempword As Word
Bl8 = Rgb8 And &B00000011 'Exctract the blue bits from the byte
Shift Rgb8 , Right , 2 'Shift the 2 blue bits to heaven
Gr8 = Rgb8 And &B00000111 'Exctract the green bits from the byte
Shift Rgb8 , Right , 3 'Shift the 3 green bits to heaven
Rd8 = Rgb8 And &B00000111 'Exctract the red bits from the byte
Rd16 = Lookup(rd8 , Red16) 'look up the conversion in the tables
Gr16 = Lookup(gr8 , Green16)
Bl16 = Lookup(bl8 , Blue16)
Tempword = Rd16 'Add the 3 colors together to get the 16bit color
Tempword = Tempword + Gr16
Tempword = Tempword + Bl16
Ili9325_rgb16 = Tempword 'Give the result back to the function
End Function

 

Declare Function Ili9325_get_color(byval R As Byte , Byval G As Byte , Byval B As Byte) As Word
 

'-------------------------------------------------------------------------------
' Ili9325_get_color RGB 24 Bit to rgb 16 Bit
'-------------------------------------------------------------------------------
'
Function Ili9325_get_color(byval R As Byte , Byval G As Byte , Byval B As Byte) As Word
'24Bit Color to 16Bit Color
G = G And &B1111_1100
Rgb16 = G 'green
Rgb16 = Rgb16 * 8
R = R And &B1111_1000 ' red
Rgb16_h = Rgb16_h Or R
Shift B , Right , 3 'blue
Rgb16_l = Rgb16_l Or B
Ili9325_get_color = Rgb16
End Function

 

Declare Function Ili9325_trigfunctiony(byval Pointratio As Single) As Single
'Calc COS
 

'-------------------------------------------------------------------------------
' ILI9325_trigfunctionx calc COS
'-------------------------------------------------------------------------------
'
Function Ili9325_trigfunctionx(byval Pointratio As Single) As Single
Pointratio = Pointratio * 2
Pointratio = Pointratio * Pi
Ili9325_trigfunctionx = Cos(pointratio)
End Function

 

Declare Function Ili9325_trigfunctionx(byval Pointratio As Single) As Single
'Calc SIN
 

'-------------------------------------------------------------------------------
' ILI9325_trigfunctiony calc SIN
'-------------------------------------------------------------------------------
'
Function Ili9325_trigfunctiony(byval Pointratio As Single) As Single
Pointratio = Pointratio * 2
Pointratio = Pointratio * Pi
Ili9325_trigfunctiony = Sin(pointratio)
End Function

 

Declare Function ili9325_Readtouch_x() As Word
 
Declare Function ili9325_Readtouch_y() As Word
 
Pictures, lookup-table and fonts
 

$include "font8x8.font"
$include "font12x16.font"

Red16: 'Lookup tabel rgb8 to rgb16 RRRRRGGGGGGBBBBB
Data &B0000000000000000% , &B0010000000000000% , &B0100100000000000% , &B0110100000000000% , &B1001000000000000% , &B1011000000000000% , &B1101000000000000% , &B1111100000000000%
Green16:
Data &B0000000000000000% , &B0000000100100000% , &B0000001001000000% , &B0000001110100000% , &B0000010010000000% , &B0000010110100000% , &B0000011011000000% , &B0000011111100000%
Blue16:
Data &B0000000000000000% , &B0000000000001010% , &B0000000000010101% , &B0000000000011111%

Plaatje:
$bgf "girl.bgc"

Aandelen:
$bgf "aandelen.bgc"

Agenda:
$bgf "agenda.bgc"

Bascom:
$bgf "bascom.bgc"

Calculator:
$bgf "calculator.bgc"

Pa0kn:
$bgf "pa0knman.bgc"

Contacten:
$bgf "contacten.bgc"

Fotos:
$bgf "fotos.bgc"

Bens:
$bgf "bens.bgc"

Kaarten:
$bgf "kaarten.bgc"

Klok:
$bgf "klok.bgc"

Sms:
$bgf "sms.bgc"

Weer:
$bgf "weer.bgc"

 

 

 

 
 
 
 
 

Under construction

 

Thanks to:


Thanks to Mark Alberts
the creator of Bascom-AVR
www.mcselec.com

Bought my copy of Bascom-8051 in 1995
a few years later Bascom-AVR
Great stuff!!!

 

Thanks to Michael K\F6cher
He created the Arduino Shield with WIZ830, 128 Kbyte SRAM, VS1053 MP3 decoder,
Micro-SD-slot and wrote the Bascom-AVR-code for it.
 

Flags can be downloaded at www.3DFlags.com

 

Ben Zijlstra - Ben's HobbyCorner - 2011