Code:
	'############################################################################
'DEBUG-Firmware für Panel
'Testprogramme für
'  -  Displayhelligkeit
'  -  Touchscreenfunktion
'############################################################################
$regfile = "m128def.dat"
$crystal = 12000000
$baud = 19200                                               ' use baud rate
$hwstack = 32                                               ' default use 32 for the hardware stack
$swstack = 10                                               ' default use 10 for the SW stack
Config Graphlcd = 240 * 128 , Dataport = Porta , Controlport = Portc , Ce = 4 , Cd = 3 , Wr = 6 , Rd = 5 , Reset = 2 , Fs = 7 , Mode = 8
Config Adc = Single , Prescaler = Auto , Reference = AVCC
Config Timer1 = Pwm , Pwm = 8 , Compare A Pwm = Clear Up , Prescale = 8
Dim X As Word , Y As Word
Dim X2 As Word , Y2 As Word
Dim T_zeile As Byte
Dim T_spalte As Byte
Dim A1 As Byte
Dim A2 As Word
Dim Ymid As Word
Dim Xmid As Word
Dim Ok As Bit
Dim Brightness As Byte
Config Portb.5 = Output
Declare Sub Readtouch
Declare Sub Touch_zuordnung
Declare Sub Status_bargraph
Declare Sub Lcd_funktionsbutton
Declare Sub Lcd_stat_info
Declare Sub Lcd_stat_home
Declare Sub Lcd_draw_object_touchscreen
Ok = 0
'############################################################################
'LCD Initialisierung / Lizenzierung
'############################################################################
Cls
Cursor Off
Waitms 500
Locate 1,1
LCD "Brightness: "
Do
Incr Brightness
Compare1a = Brightness
Locate 1,13
LCD Brightness
Waitms 10
Loop Until Brightness = 255
Wait 1
Stop ADC
Start ADC
CLS
'############################################################################
'HAUPTSCHLEIFE
'############################################################################
call lcd_draw_object_touchscreen
Do
   A1 = 0
   locate 1,1
   lcd "                    "
      locate 4,10
      lcd "F.0"
      locate 5,10
      lcd "hi" ; "    "
      locate 15, 10
      lcd "F.2"
      locate 16,10
      lcd "lo"    ; "    "
      locate 9,2
      lcd "F.1"
      locate 10,2
      lcd "read"  ; "    "
      locate 10, 18
      lcd "F.3"
      locate 11,18
      lcd "-"  ; "    "
   locate 1,1
   lcd "Y-Value: "
      do
         Config Pinf.0 = Output
         Config Pinf.2 = Output
         Set Portf.0
         Reset Portf.2
         Ddrf.1 = 0
         Ddrf.3 = 0
         Waitms 10
         Y = Getadc(1)
         Y2 = 1024 - Y
         locate 1,22
         lcd Y;"   "
         locate 2,22
         lcd Y2;"   "
         incr A1
      loop until A1 = 255
   A1 = 0
   locate 1,1
   lcd "                    "
      locate 4,10
      lcd "F.0"
      locate 5,10
      lcd "read"  ; "    "
      locate 15, 10
      lcd "F.2"
      locate 16,10
      lcd "-"  ; "    "
      locate 9,2
      lcd "F.1"
      locate 10,2
      lcd "hi"; "    "
      locate 10, 18
      lcd "F.3"
      locate 11,18
      lcd "lo"  ; "    "
   locate 1,1
   lcd "X-Value: "
      do
           Config Pinf.3 = Output
           Config Pinf.1 = Output
           Reset Portf.3
           Set Portf.1
           Ddrf.0 = 0
           Ddrf.2 = 0
           Waitms 10
           X = Getadc(0)
           X2 = 1024 - X
           locate 1,22
           lcd X ; "   "
           locate 2,22
           lcd X2; "   "
           incr A1
      loop until A1 = 255
Loop
End
'############################################################################
'TOUCHSCREEN Einteilung in Spalten und Zeilen
'############################################################################
Sub Touch_zuordnung
   Select Case Y
   Case 340 To 400 : T_zeile = 1
   Case 401 To 470 : T_zeile = 2
   Case 471 To 550 : T_zeile = 3
   Case 551 To 620 : T_zeile = 4
   Case 621 To 700 : T_zeile = 5
   Case Else : T_zeile = 0
   End Select
   Select Case X
   Case 165 To 300 : T_spalte = 1
   Case 301 To 435 : T_spalte = 2
   Case 436 To 570 : T_spalte = 3
   Case 571 To 700 : T_spalte = 4
   Case 701 To 840 : T_spalte = 5
   Case Else : T_spalte = 0
   End Select
End Sub
'############################################################################
'TOUCHSCREEN Auswertung
'############################################################################
Sub Readtouch
Ymid = 0
Xmid = 0
For A1 = 1 To 3
 Config Pinf.1 = Output                                     ' Makes port F.0 output
 Config Pinf.2 = Output                                     ' Makes port F.0 output
 Set Portf.1                                                ' Sets port F.0 High
 Reset Portf.2                                              ' Sets port F.2 Low
 Ddrf.3 = 0                                                 ' Sets port F.1 as input
 Ddrf.0 = 0                                                 ' Sets port F.1 as input because we need it now as ad input
 Waitms 3                                                   ' Wait until the port is stable
 Y = Getadc(4)                                              ' Read the ad value for the y
 Y = 1024 - Y                                               ' Invert the reading
 Config Pinf.3 = Output                                     ' Makes port F.1 output
 Config Pinf.0 = Output                                     ' Makes port F.3 output
 Reset Portf.3                                              ' Sets port F.3 Low
 Set Portf.0                                                ' Sets port F.1 High
 Ddrf.1 = 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 3                                                   ' Wait until the port is stable
 X = Getadc(1)                                              ' Read the ad value for the x
 X = 1024 - X                                               ' Invert the reading
Ymid = Ymid + Y
Xmid = Xmid + X
Next A1
Y = Ymid / 3                                                'Mittelung der X,Y Werte über 3 Messungen
X = Xmid / 3
End Sub
'############################################################################
'LCD Objekt Touchscreen
'############################################################################
Sub Lcd_draw_object_touchscreen
Box(50,50)-(125,100),255
box(51,51)-(124,99),255
Line(52,48)-(123,48),255
line(52,102)-(123,102),255
line(48,52)-(48,98),255
line(127,52)-(127,98),255
locate 12,9
lcd "TOUCH"
'locate 4,10
'lcd "F.0"
'locate 5,10
'lcd "hi"
'locate 15, 10
'lcd "F.2"
'locate 16,10
'lcd "lo"
'locate 8,3
'lcd "F.1"
'locate 9,3
'lcd "read"
'locate 10, 18
'lcd "F.3"
'locate 11,18
'lcd "-"
End Sub
 
Lesezeichen