Code:
$regfile = "m2560def.DAT"
$crystal = 18000
$baud = 9200
$eepleave
$loadersize = 512
$hwstack = 100
$swstack = 75
$framesize = 40
$lib "glcdKS108.lib" 'Include the library for the KS-108 controler
Config Graphlcd = 320 * 240sed , Dataport = Porta , Controlport = Portc , Ce = 0 , Ce2 = 1 , Cd = 2 , Rd = 3 , Reset = 5 , Enable = 4
'The dataport is the portname that is connected to the data lines of the LCD
'The controlport is the portname which pins are used to control the lcd
'CE =CS1 Chip select
'CE2=CS2 Chip select second chip
'CD=Data/instruction
'RD=Read
'RESET = reset
'ENABLE= Chip Enable
Config Adc = Single , Prescaler = Auto , Reference = Internal 'Setting up the a/d convertor
Config Timer1 = Timer , Prescale = 1024 ' Timer 1 sets the screen back to the mainmenu after 10sec
Const Timer1preload = 58336 'Timer 1 preload for 1 sec interrupt
Speaker Alias Portf.7 'Buzzer connected to portf.7, see circuit diagram
Dim Temp As Byte , X As Word , Y As Word
Dim Row As Byte , Keyarray(3) As Byte , Col As Byte , Key As Byte , Keylus As Byte
Dim Keypressed As Byte , Menu As Byte
Dim Timecount As Byte
Setfont Font8x8
Enable Ovf1
Enable Interrupts
On Timer1 1secint ' on overflow jump to 1 sec int routine
Start Adc ' Start the A<->D convertor
Stop Timer1
Gosub Showmainmenu ' Starts with the Mainmenu
' =====Main=====
Main:
Do
'*************************
' Here your main prog
'*************************
Gosub Readtouch ' Read the touch cordinates
Gosub Whichkey ' Which key is pressed
If Menu > 1 Then ' Starts the timer if the menu is not the Mainmenu
Start Timer1
Else
Stop Timer1
End If
If Keypressed > 0 Then ' Key is pressed
Select Case Menu ' Depends on the menu that we are in what to do with the pressed key
Case 1 : Select Case Keypressed 'Mainmenu
Case 11 : Print " You pressed key: " ; Keypressed ; " in menu: " ; Menu
Case 12 : Print " You pressed key: " ; Keypressed ; " in menu: " ; Menu
Case 13 : Print " You pressed key: " ; Keypressed ; " in menu: " ; Menu
Case 21 : Print " You pressed key: " ; Keypressed ; " in menu: " ; Menu
Case 22 : Print " You pressed key: " ; Keypressed ; " in menu: " ; Menu
Case 23 : Gosub Showlichteettafelmenu ' Shows a sub menu
Case 31 : Print " You pressed key: " ; Keypressed ; " in menu: " ; Menu
Case 32 : Print " You pressed key: " ; Keypressed ; " in menu: " ; Menu
Case 33 : Print " You pressed key: " ; Keypressed ; " in menu: " ; Menu
Case 41 : Print " You pressed key: " ; Keypressed ; " in menu: " ; Menu
Case 42 : Print " You pressed key: " ; Keypressed ; " in menu: " ; Menu
Case 43 : Print " You pressed key: " ; Keypressed ; " in menu: " ; Menu
End Select
Case 13 : Select Case Keypressed 'LichtEetafelmenu (menu 13)
Case 11 : Print " You pressed key: " ; Keypressed ; " in menu: " ; Menu
Case 12 : Print " You pressed key: " ; Keypressed ; " in menu: " ; Menu
Case 13 : Gosub Showmainmenu ' Back to the mainmenu
Case 21 : Print " You pressed key: " ; Keypressed ; " in menu: " ; Menu
Case 22 : Print " You pressed key: " ; Keypressed ; " in menu: " ; Menu
Case 23 : Print " You pressed key: " ; Keypressed ; " in menu: " ; Menu
Case 31 : Print " You pressed key: " ; Keypressed ; " in menu: " ; Menu
Case 32 : Print " You pressed key: " ; Keypressed ; " in menu: " ; Menu
Case 33 : Print " You pressed key: " ; Keypressed ; " in menu: " ; Menu
Case 41 : Print " You pressed key: " ; Keypressed ; " in menu: " ; Menu
Case 42 : Print " You pressed key: " ; Keypressed ; " in menu: " ; Menu
Case 43 : Print " You pressed key: " ; Keypressed ; " in menu: " ; Menu
End Select
End Select
Keypressed = 0 ' Key is processed so put it back to 0
End If
Loop
'=== Subroutines===
$include "font8x8.font"
1secint: ' Interrupt routine will set the screen back to the mainmenu in 10 seconds
Incr Timecount ' increment every sec the counter with 1
If Timecount => 10 Then ' here is the 10 sec
Stop Timer1 : Timecount = 0
Gosub Showmainmenu ' Sets the screen
Else
Timer1 = Timer1preload
End If
Return
Showmainmenu: 'Shows the main menu
Menu = 1 'Menu number
Cls 'Clears the screen
Showpic 0 , 0 , Headerhoofdmenu ' Draw the 9 pictures on the screen
Showpic 0 , 16 , Jalvoor
Showpic 32 , 16 , Jalachter
Showpic 64 , 16 , Lichtkeuken
Showpic 96 , 16 , Autoprog
Showpic 0 , 40 , Lichtsalontafel
Showpic 32 , 40 , Lichteettafel
Showpic 64 , 40 , Schemerlamp
Showpic 96 , 40 , Pijlrechts
Return
Showlichteettafelmenu: ' Shows the ShowLichtEetafel menu (sub menu 13)
Menu = 13 ' Menu number
Cls 'Clears the screen
Showpic 0 , 0 , Headerlichteettafel ' Draw the 9 pictures on the screen
Showpic 0 , 16 , Stopbutton
Showpic 32 , 16 , Pijlomhoog
Showpic 64 , 16 , F1preset
Showpic 96 , 16 , F2preset
Showpic 0 , 40 , Escbutton
Showpic 32 , 40 , Pijlomlaag
Showpic 64 , 40 , F3preset
Showpic 96 , 40 , F4preset
Return
Whichkey: 'Determins which key is pressed
Select Case X ' For the x value
Case 200 To 340 : Col = 10 ' The cordinates on the touchscreen determins which key is pressed for example;
Case 341 To 486 : Col = 20 ' 341 to 486 are the cordinates where between the second column is
Case 487 To 635 : Col = 30
Case 636 To 774 : Col = 40
Case Else Col = 0
End Select
Select Case Y ' For the y value
Case 250 To 360 : Row = 1 ' The cordinates on the touchscreen determins which key is pressed for example;
Case 361 To 540 : Row = 2 ' 361 to 540 are the cordinates where between the second row is
Case 541 To 730 : Row = 3
Case Else Row = 0
End Select
Key = Col + Row ' Add the row and column value so we get 1 key value
If Key > 0 Then ' There is a key pressed
Keyarray(keylus) = Key 'Must read the same key 3 times in a row, to prefent bouncing
Incr Keylus
If Keylus > 3 Then Keylus = 1
If Keyarray(1) = Keyarray(2) Then
If Keyarray(2) = Keyarray(3) Then ' Key is correct read 3 times the same
Sound Speaker , 1 , 65000 ' Give a key beep
Keypressed = Key
Timecount = 0
End If
End If
End If
Return
Readtouch:
Config Pinf.0 = Output ' Makes port F.0 output
Config Pinf.2 = Output ' Makes port F.0 output
Set Portf.0 ' Sets port F.0 High
Reset Portf.2 ' Sets port F.2 Low
Ddrf.1 = 0 ' Sets port F.1 as input
Ddrf.3 = 0 ' Sets port F.1 as input because we need it now as ad input
Waitms 20 ' Wait until the port is stable
Y = Getadc(3) ' Read the ad value for the y
Y = 1024 - Y ' Invert the reading
'Print "VALUE Y : " ; Y ' for debugging
Config Pinf.1 = Output ' Makes port F.1 output
Config Pinf.3 = Output ' Makes port F.3 output
Reset Portf.1 ' Sets port F.1 Low
Set Portf.3 ' Sets port F.3 High
Ddrf.0 = 0 ' Sets port F.0 as input
Ddrf.2 = 0 ' Sets port F.2 as input because we need it now as ad input
Waitms 20 ' Wait until the port is stable
X = Getadc(2) ' Read the ad value for the x
X = 1024 - X ' Invert the reading
'Print "VALUE X : " ; X
Return
'=====The buttons images=====
Headerhoofdmenu:
$bgf "HeaderHoofdmenu.bgf"
Headerlichteettafel:
$bgf "HeaderLichtEettafel.bgf"
Jalvoor:
$bgf "Jalvoor.bgf"
Jalachter:
$bgf "Jalachter.bgf"
Lichtsalontafel:
$bgf "LichtSalonTafel.bgf"
Lichteettafel:
$bgf "LichtEetTafel.bgf"
Lichtkeuken:
$bgf "Lichtkeuken.bgf"
Schemerlamp:
$bgf "Schemerlamp.bgf"
Escbutton:
$bgf "Esc.bgf"
Pijlomhoog:
$bgf "PijlOmhoog.bgf"
Pijlomlaag:
$bgf "PijlOmlaag.bgf"
Pijlrechts:
$bgf "PijlRechts.bgf"
Pijllinks:
$bgf "PijlLinks.bgf"
Autoprog:
$bgf "Autoprog.bgf"
Stopbutton:
$bgf "Stop.bgf"
F1preset:
$bgf "F1preset.bgf"
F2preset:
$bgf "F2preset.bgf"
F3preset:
$bgf "F3preset.bgf"
F4preset:
$bgf "F4preset.bgf"
F3leeg:
$bgf "F3Leeg.bgf"
F4leeg:
$bgf "F4Leeg.bgf"
Leeg:
$bgf "Leeg.bgf"
Das ist erstaml in Bascom, aber der endgültige Code wird in C geproggt
Lesezeichen