'Color-Display 175x131 Pixel Touch $prog &HFF , &HFF , &H91 , &HF5 '---------------------------------------------------------------------------------------------------------------------------------- ' Make sure, that at menu "Options, Compiler, Chip" the following values are used. More Gosubs etc. might need ' even larger numbers - you will recognize this, when your program suddenly shows an unexpected behavior ' HWSTACK-64 ' SWSTACK-128 ' FRAMESIZE-16 'An alternative is using this code: $hwstack = 64 $swstack = 128 $framesize = 16 'you might need to raise these numbers if your code grows !!!!!!! (unexpected behaviour of the program often results of too small stacks) '---------------------------------------------------------------------------------------------------------------------------------- $regfile = "m128can.dat" $crystal = 14745600 'enter the used clock of your actual microcontroller Config Com1 = 9600 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0 Open "com1:" For Binary As #1 On Urxc Onrxd Config Timer0 = Timer , Prescale = 8 On Timer0 Timer0_isr Enable Timer0 Config Timer1 = Pwm , Pwm = 8 , Compare_c_pwm = Clear_down , Prescale = 1 Config Date = Dmy , Separator = / Config Clock = Soft Config Adc = Single , Prescaler = Auto , Reference = Avcc Dim Y As Word , X As Word , Y_str As String * 4 , X_str As String * 4 , V As Byte , Z As Word Dim X1 As Byte , Temp1 As Byte , Temp As Byte , V1 As Bit , Chan_zimmer As Byte , Ch_uhr As Byte Dim Eins As Byte Dim Null As Byte Eins = 1 Null = 0 Declare Sub Touch Declare Sub X_y_print Date$ = "30/12/12" Time$ = "18:59:00" Chan_zimmer = 1 '############################################################################################ '4 - Definition of used ports and pull up resistors 'At our boards we are using Port B for the SPI-communication to the LCD. 'Now we need to select Port B as to an output port (data output to the display) Ddrb = &B11111111 'DDR = Data direction register; All 8 ports switched to output (1) Ddra = &B10000000 'switch all 8 Ports of Port A to input (0), Pin (PA.0 - PA.7) Porta = &B01111111 'All port pins have individually selectable pull-up resistors. Here we enable these pull-up-resisitors, so these Pins are always at logical 1 'You need to pull these Pins against ground (GND) Ddrc = &B00000000 'switch all Ports of Port C to input Portc = &B11111111 'all pull-up-Resistors turned on Ddrd = &B00001111 Portd = &B11111010 Ddre = &B00000010 Porte = &B11111100 Ddrf = &B00000000 'switch all Ports of Port F to input Portf = &B11111111 'all pull-up-Resistors turned on Ddrg = &B00000000 'switch all Ports of Port G to input Portg = &B11111111 'all pull-up-Resistors turned on Enable Urxc Enable Interrupts $include Init21_display3000.bas '############################################################################################ 'Main program, demo program Bluebild: V1 = 0 Orientation = Landscape Call Lcd_box(0 , 0 , 175 , 131 , Blue) Call Lcd_rect(4 , 50 , 168 , 82 , Thick , Dark_red) Call Lcd_print( " HOMEBUS " , 6 , 52 , 2 , 2 , 2 , Green , Black) '################################################################### ' LOOP '################################################################### Do Call Touch If Y < 800 And X < 800 And V1 = 0 Then Goto Start_menue ' Call Lcd_print(date$ , 17 , 10 , 2 , 2 , 2 , White , Black) ' Call Lcd_print(time$ , 17 , 95 , 2 , 2 , 2 , White , Black) If Pwm1c < 253 Then For Pwm1c = 0 To 253 Call Touch If Y < 800 And X < 800 And V1 = 0 Then Exit For Next Pwm1c End If Loop '##########################STARTMENUE############################### Start_menue: Orientation = Landscape Pwm1c = 0 Call Lcd_box(0 , 0 , 175 , 131 , White) Call Lcd_print( " Loading, wait... " , 5 , 0 , 2 , 1 , 1 , White , Dark_red) Call Lcd_box(30 , 25 , 150 , 115 , Black) Call Lcd_rect(30 , 25 , 150 , 115 , Thick , Dark_red) For Temp1 = 1 To 5 Call Lcd_print( ">" , 45 , 40 , 1 , 1 , 1 , Green , Black) Waitms 250 Call Lcd_print( " " , 45 , 40 , 1 , 1 , 1 , Green , Black) Waitms 250 Next Temp1 Call Lcd_print( "> PowerUp" , 45 , 40 , 1 , 1 , 1 , Green , Black) Waitms 300 Call Lcd_print( "> OK " , 45 , 49 , 1 , 1 , 1 , Green , Black) Call Lcd_print( "> ." , 45 , 58 , 1 , 1 , 1 , Green , Black) For X1 = 69 To 111 Step 6 Call Lcd_print( "." , X1 , 58 , 1 , 1 , 1 , Green , Black) Waitms 200 Next X1 Call Lcd_print( "> Read OK <" , 45 , 67 , 1 , 1 , 1 , Green , Black) V1 = 1 Wait 1 '####################### HAUPTMENUE ################################### Hauptmenue: Orientation = Landscape Call Lcd_box(0 , 0 , 175 , 131 , Black) Call Lcd_print( " HAUPTMENUE " , 1 , 1 , 2 , 1 , 1 , Black , White) Call Lcd_box(10 , 29 , 51 , 54 , Green) Call Lcd_print( "Zentral" , 10 , 37 , 1 , 1 , 1 , Black , White ) Call Lcd_print( "Jalous." , 10 , 60 , 1 , 1 , 1 , Black , Yellow ) Call Lcd_box(10 , 75 , 51 , 100 , Green) Call Lcd_print( "Einzel " , 10 , 83 , 1 , 1 , 1 , Black , White) Call Lcd_rect(9 , 28 , 52 , 101 , Thick , Dark_red) Call Lcd_box(65 , 29 , 106 , 54 , Blue) Call Lcd_print( " Wand " , 65 , 37 , 1 , 1 , 1 , Black , White ) Call Lcd_print( "Heizung" , 65 , 60 , 1 , 1 , 1 , Black , Yellow ) Call Lcd_box(65 , 75 , 106 , 100 , Blue) Call Lcd_print( "Pumpen " , 65 , 83 , 1 , 1 , 1 , Black , White) Call Lcd_rect(64 , 28 , 107 , 101 , Thick , Dark_red) Call Lcd_box(120 , 29 , 161 , 54 , Yellow) Call Lcd_print( " " , 120 , 37 , 1 , 1 , 1 , Black , White) Call Lcd_print( " " , 120 , 60 , 1 , 1 , 1 , Black , Yellow ) Call Lcd_box(120 , 75 , 161 , 100 , Yellow) Call Lcd_print( " UHR " , 120 , 83 , 1 , 1 , 1 , Black , White ) Call Lcd_rect(119 , 28 , 162 , 101 , Thick , Dark_red) Call Lcd_box(120 , 110 , 175 , 131 , White) Call Lcd_print( "RETURN" , 120 , 112 , 2 , 1 , 1 , Black , White ) Main1: Call Touch If Y > 175 And Y < 275 And X > 345 And X < 440 Then Goto Jal_zentral 'If Y > 355 And Y < 450 And X > 345 And X < 440 Then Goto Jal_einzel 'If Y > 175 And Y < 275 And X > 220 And X < 315 Then Goto Heizung_wand 'If Y > 355 And Y < 450 And X > 220 And X < 315 Then Goto Pumpensteuerung 'If Y > 355 And Y < 450 And X > 95 And X < 190 Then Goto Uhr If Y > 466 And Y < 600 And X > 70 And X < 200 Then Goto Bluebild Call X_y_print Goto Main1 '########################################################################## '####################### JALOUSIE_ZENTRAL ################################# Jal_zentral: Orientation = Landscape Call Lcd_box(0 , 0 , 175 , 131 , Black) Call Lcd_print( " JALOUSIE ZENTRAL " , 1 , 1 , 2 , 1 , 1 , Black , White) Call Lcd_box(50 , 25 , 120 , 55 , Green) Call Lcd_print( " AUF " , 64 , 33 , 2 , 1 , 1 , Black , White ) Call Lcd_box(50 , 70 , 120 , 100 , Red) Call Lcd_print( " AB " , 64 , 78 , 2 , 1 , 1 , Black , White) Call Lcd_box(120 , 110 , 175 , 131 , White) Call Lcd_print( "RETURN" , 120 , 112 , 2 , 1 , 1 , Black , White ) '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ '####################################################################### Main2: Call Touch If Y > 466 And Y < 600 And X > 70 And X < 200 Then Goto Hauptmenue If Y > 150 And Y < 275 And X > 180 And X < 350 Then Gosub Senden_auf_zen If Y > 330 And Y < 450 And X > 180 And X < 350 Then Gosub Senden_ab_zen Goto Main2 '####################################################################### '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 'JALOUSIE ZENTRAL AUF SENDEN '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Senden_auf_zen: Disable Interrupts '++++++++++++ Wohnzimmer +++++++++++++++++++++++++++++++++++++++++++++++ Porta.7 = 1 Waitms 5 For Temp = 1 To 2 ' Startbyte/Absenderadr./Zieladresse/Kanal/Daten/Stopbyte Print #1 , "Startbyt" ; "011" ; "003" ; "099" ; Bin(eins) ; "Stopbyte"; Waitms 50 Next Temp Porta.7 = 0 Orientation = Landscape Call Lcd_print( " " , 125 , 78 , 2 , 1 , 1 , Black , Black ) For Temp = 1 To 20 Call Touch If Y > 466 And Y < 600 And X > 70 And X < 200 Then Exit For Orientation = Landscape Call Lcd_print( "J-3" , 125 , 33 , 2 , 1 , 1 , Black , White ) Call Lcd_print( " " , 64 , 33 , 2 , 1 , 1 , Black , White ) Waitms 500 Call Lcd_print( " AUF " , 64 , 33 , 2 , 1 , 1 , Black , White ) Waitms 500 Next Temp '+++++++++++ Arbeitszimmer + Kinderzimmer ++++++++++++++++++++++++++++++ Porta.7 = 1 Waitms 5 For Temp = 1 To 2 ' Startbyte/Absenderadr./Zieladresse/Kanal/Daten/Stopbyte Print #1 , "Startbyt" ; "011" ; "005" ; "099" ; Bin(eins) ; "Stopbyte"; Waitms 50 ' Startbyte/Absenderadr./Zieladresse/Kanal/Daten/Stopbyte Print #1 , "Startbyt" ; "011" ; "007" ; "099" ; Bin(eins) ; "Stopbyte"; Waitms 50 Next Temp Porta.7 = 0 For Temp = 1 To 20 Call Touch If Y > 466 And Y < 600 And X > 70 And X < 200 Then Exit For Orientation = Landscape Call Lcd_print( "J-5/7" , 125 , 33 , 2 , 1 , 1 , Black , White ) Call Lcd_print( " " , 64 , 33 , 2 , 1 , 1 , Black , White ) Waitms 500 Call Lcd_print( " AUF " , 64 , 33 , 2 , 1 , 1 , Black , White ) Waitms 500 Next Temp '++++++++++++ Schlafzimmer + Bad ++++++++++++++++++++++++++++++++++++++++ Porta.7 = 1 Waitms 5 For Temp = 0 To 2 ' Startbyte/Absenderadr./Zieladresse/Kanal/Daten/Stopbyte Print #1 , "Startbyt" ; "011" ; "008" ; "099" ; Bin(eins) ; "Stopbyte"; Waitms 50 ' Startbyte/Absenderadr./Zieladresse/Kanal/Daten/Stopbyte Print #1 , "Startbyt" ; "011" ; "009" ; "099" ; Bin(eins) ; "Stopbyte"; Waitms 50 Next Temp Porta.7 = 0 For Temp = 0 To 20 Call Touch If Y > 466 And Y < 600 And X > 70 And X < 200 Then Exit For Orientation = Landscape Call Lcd_print( "J-8/9" , 125 , 33 , 2 , 1 , 1 , Black , White ) Call Lcd_print( " " , 64 , 33 , 2 , 1 , 1 , Black , White ) Waitms 500 Call Lcd_print( " AUF " , 64 , 33 , 2 , 1 , 1 , Black , White ) Waitms 500 Next Temp '++++++++++++ELT-Raum + Küche ++++++++++++++++++++++++++++ Porta.7 = 1 Waitms 5 For Temp = 0 To 2 ' Startbyte/Absenderadr./Zieladresse/Kanal/Daten/Stopbyte Print #1 , "Startbyt" ; "011" ; "001" ; "099" ; Bin(eins) ; "Stopbyte"; Waitms 50 ' Startbyte/Absenderadr./Zieladresse/Kanal/Daten/Stopbyte Print #1 , "Startbyt" ; "011" ; "002" ; "099" ; Bin(eins) ; "Stopbyte"; Waitms 50 Next Temp Porta.7 = 0 For Temp = 0 To 20 Call Touch If Y > 466 And Y < 600 And X > 70 And X < 200 Then Exit For Orientation = Landscape Call Lcd_print( "J-1/2" , 125 , 33 , 2 , 1 , 1 , Black , White ) Call Lcd_print( " " , 64 , 33 , 2 , 1 , 1 , Black , White ) Waitms 500 Call Lcd_print( " AUF " , 64 , 33 , 2 , 1 , 1 , Black , White ) Waitms 500 If Temp = 20 Then Call Lcd_print( " OK " , 125 , 33 , 2 , 1 , 1 , Black , White ) Next Temp Enable Interrupts Return '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 'JALOUSIE ZENTRAL AB SENDEN '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Senden_ab_zen: Disable Interrupts '++++++++++++ Wohnzimmer +++++++++++++++++++++++++++++++++++++++++++++++ Porta.7 = 1 Waitms 5 For Temp = 0 To 2 ' Startbyte/Absenderadr./Zieladresse/Kanal/Daten/Stopbyte Print #1 , "Startbyt" ; "011" ; "003" ; "099" ; Bin(null) ; "Stopbyte"; Waitms 50 Next Temp Porta.7 = 0 Orientation = Landscape Call Lcd_print( " " , 125 , 33 , 2 , 1 , 1 , Black , Black ) For Temp = 0 To 20 Call Touch If Y > 466 And Y < 600 And X > 70 And X < 200 Then Exit For Orientation = Landscape Call Lcd_print( "J-3" , 125 , 78 , 2 , 1 , 1 , Black , White ) Call Lcd_print( " " , 64 , 78 , 2 , 1 , 1 , Black , White ) Waitms 500 Call Lcd_print( " AB " , 64 , 78 , 2 , 1 , 1 , Black , White ) Waitms 500 Next Temp '+++++++++++ Arbeitszimmer + Kinderzimmer ++++++++++++++++++++++++++++++ Porta.7 = 1 Waitms 5 For Temp = 0 To 2 ' Startbyte/Absenderadr./Zieladresse/Kanal/Daten/Stopbyte Print #1 , "Startbyt" ; "011" ; "005" ; "099" ; Bin(null) ; "Stopbyte"; Waitms 50 ' Startbyte/Absenderadr./Zieladresse/Kanal/Daten/Stopbyte Print #1 , "Startbyt" ; "011" ; "007" ; "099" ; Bin(null) ; "Stopbyte"; Waitms 50 Next Temp Porta.7 = 0 For Temp = 0 To 20 Call Touch If Y > 466 And Y < 600 And X > 70 And X < 200 Then Exit For Orientation = Landscape Call Lcd_print( "J-5/7" , 125 , 78 , 2 , 1 , 1 , Black , White ) Call Lcd_print( " " , 64 , 78 , 2 , 1 , 1 , Black , White ) Waitms 500 Call Lcd_print( " AB " , 64 , 78 , 2 , 1 , 1 , Black , White ) Waitms 500 Next Temp '++++++++++++ Schlafzimmer + Bad ++++++++++++++++++++++++++++++++++++++++ Porta.7 = 1 Waitms 5 For Temp = 0 To 2 ' Startbyte/Absenderadr./Zieladresse/Kanal/Daten/Stopbyte Print #1 , "Startbyt" ; "011" ; "008" ; "099" ; Bin(null) ; "Stopbyte"; Waitms 50 ' Startbyte/Absenderadr./Zieladresse/Kanal/Daten/Stopbyte Print #1 , "Startbyt" ; "011" ; "009" ; "099" ; Bin(null) ; "Stopbyte"; Waitms 50 Next Temp Porta.7 = 0 For Temp = 0 To 20 Call Touch If Y > 466 And Y < 600 And X > 70 And X < 200 Then Exit For Orientation = Landscape Call Lcd_print( "J-8/9" , 125 , 78 , 2 , 1 , 1 , Black , White ) Call Lcd_print( " " , 64 , 78 , 2 , 1 , 1 , Black , White ) Waitms 500 Call Lcd_print( " AB " , 64 , 78 , 2 , 1 , 1 , Black , White ) Waitms 500 Next Temp '++++++++++++ELT-Raum + Küche ++++++++++++++++++++++++++++ Porta.7 = 1 Waitms 5 For Temp = 0 To 2 ' Startbyte/Absenderadr./Zieladresse/Kanal/Daten/Stopbyte Print #1 , "Startbyt" ; "011" ; "001" ; "099" ; Bin(null) ; "Stopbyte"; Waitms 50 ' Startbyte/Absenderadr./Zieladresse/Kanal/Daten/Stopbyte Print #1 , "Startbyt" ; "011" ; "002" ; "099" ; Bin(null) ; "Stopbyte"; Waitms 50 Next Temp For Temp = 0 To 20 Call Touch If Y > 466 And Y < 600 And X > 70 And X < 200 Then Exit For Orientation = Landscape Call Lcd_print( "J-1/2" , 125 , 78 , 2 , 1 , 1 , Black , White ) Call Lcd_print( " " , 64 , 78 , 2 , 1 , 1 , Black , White ) Waitms 500 Call Lcd_print( " AB " , 64 , 78 , 2 , 1 , 1 , Black , White ) Waitms 500 If Temp = 20 Then Call Lcd_print( " OK " , 125 , 78 , 2 , 1 , 1 , Black , White ) Next Temp Enable Interrupts Return '####################################################################### Onrxd: 'noch nix drin Return 'Timing Anzeige Koordinaten-Touch Timer0_isr: Incr Z Return '########## Auswertung Touchscreen ##################################### Touch: Portd = &B00000110 Start Adc Y = Getadc(0) Y_str = Str(y) Y_str = Format(y_str , "0000") Stop Adc Portd = &B00001001 Start Adc X = Getadc(1) X_str = Str(x) X_str = Format(x_str , "0000") Stop Adc Waitms 20 Return '########### Koordinaten Touchscreen ################################## X_y_print: If Z >= 5000 Then Orientation = Landscape Call Lcd_print(y_str , 25 , 120 , 1 , 1 , 1 , White , Blue) Call Lcd_print( "Y=" , 10 , 120 , 1 , 1 , 1 , White , Blue) Call Lcd_print(x_str , 75 , 120 , 1 , 1 , 1 , White , Blue) Call Lcd_print( "X=" , 60 , 120 , 1 , 1 , 1 , White , Blue) Z = 0 End If Return $include Glcd21_display3000.bas 'Dummy Data um Fehlermeldungen bei der Kompilierung der Standardroutinen zu vermeiden 'Die Tabelle wird dann bei Nutzung eines indizierten Grafikdatei mit "echten" Daten ausgetauscht Colortable: Data 0 'includes the color table for the 256 color graphics $include Glcd21_fonts.bas