Hi!
Now getting the touch display to work stable and as intended so far. Below is the relevant parts for how I am sending commands/text and the Tasks dealing with interrupt/checking for touched Display. I'm not a proffesional programmer so there are probably more elegant ways to do it but it works!
The size of Stack buffers are guesstimates but when reducing the 'Private taskCheckReady(1 to 100) to 50 it stopped working. Are there some rules for size or just try ?
CODE FROM Pool.bas and Touch.bas
Code: Select all
'****************** Project to deal with my pool,reading temps etc *******
Option Explicit
Option ExtRamConfig On
Public COM3 As Boolean = False'Touch LCD
Public COM4 As Boolean = False'LCD Plus
Public COM5 As Boolean = False'#142- temp/relay
Public COM6 As Boolean = False'reserve
Private taskCheckTouch(1 to 100) as Byte 'stack for Sub CheckLCDTouch_TouchResponse
Private tmpCommand as String ' for sending commands/text to Display
Public Sub Main()
'Reset LCDTouch
tmpCommand="R"
Call PrintText_TouchLCD(tmpCommand)
tmpCommand=":#"
Call PrintText_TouchLCD(tmpCommand)
'**************************************'
'set 4 SW serial channels
Call ComChannels(4,9600)
'Load Main Menu
Call Main_LCDTouch_Menu
Do
'this routine not ready,just for testing respons on touch Display
CallTask CheckLCDTouch_TouchResponse,taskCheckTouch
call delay(0.1)
Loop
End Sub
Code below from Touch.bas
'***** Touch LCD uses Pin 14,8,9 ***************************
Private Const Tx_TouchLCD As Byte = 9
Private Const Rx_TouchLCD As Byte = 8
Private Const CmdPin As Byte = 14'Pin 14 interrupt 6
Private Cmd_status As Boolean ' True means Display ready for new command
'**********************************************************
Dim OutBuffer(0 To 128) As Byte
Dim InBuffer(0 To 128) As Byte
Private taskCheckReady(1 to 100) as Byte ' Checks if Display are ready for new command
'***********************************************************
'** must be called first before communicate with COM 3
'***********************************************************
Public Sub Init_TouchLCD()
'open buffers for COM-port
Call OpenQueue(OutBuffer, 127)
Call OpenQueue(InBuffer, 127)
' Open COM3 port:noninverted 8-bit 1 stop bit
Call DefineCom(3,Rx_TouchLCD, Tx_TouchLCD, bx0000_1000,1)'Pin 8 = grey Pin 9 = brown
Call OpenCom(3,9600,InBuffer, OutBuffer)
COM3 = True
End sub
'******************************** MAIN MENU ************************************
Public Sub Main_LCDTouch_Menu()
Dim tmpCommand As String
tmpCommand = "*"'just to make sure the Display is ready if 'coldstarted'
Call PrintText_TouchLCD(tmpCommand)
tmpCommand = "C"'clear sreen
Call PrintText_TouchLCD(tmpCommand)
'print text on line 1 to 4
tmpCommand="tm12,Installningar"
Call PrintText_TouchLCD(tmpCommand)
tmpCommand="tm32,Temperaturer"
Call PrintText_TouchLCD(tmpCommand)
tmpCommand="tm52,Relastatus"
Call PrintText_TouchLCD(tmpCommand)
tmpCommand="tm72,Lampstatus"
Call PrintText_TouchLCD(tmpCommand)
'overlay with built in touchsreen, four lines, respons 1 to 4 when touched
tmpCommand = "BA"
Call PrintText_TouchLCD(tmpCommand)
End Sub
'*********************************************************************************
' Main Display routine for sending commands/text *********************************
'*********************************************************************************
Public Sub PrintText_TouchLCD(tmpText As String)
' Open com3 port for TouchLCD if closed
If COM3 = False Then
Call Init_TouchLCD
End if
'if '*' skip Check if Ready to recieve, just to wake Display up
If tmpText = "*" Then
Call PutQueueStr(OutBuffer,tmpText & Chr(13))
End If
'Check if Ready to recieve
CallTask CheckLCDTouch_Ready,taskCheckReady
If Cmd_Status Then
Call PutQueueStr(OutBuffer,tmpText & Chr(13))
'reset Cmd_Status
Cmd_Status = False
End if
Call delay(0.1) 'pause to give Display time to catch up
End Sub
'**********************************************
'****** Task called from PrintText_TouchLCD ***
'****** High on Pin 14 means Display ready for command
'**********************************************
Public Sub CheckLCDTouch_Ready()
Call WaitForInterrupt(zxPinRisingEdge,6)'Pin 14, int 6 on ZX 1281e
Cmd_Status = True
End Sub
'**********************************************
'****** Task called from Sub Main ***
'****** to check if touch screen pressed ******
'**********************************************
Public Sub CheckLCDTouch_TouchResponse()
Dim tmpResponse As String
Dim tmpCommand As String
Dim TouchRespons As String
Call ClearQueue(InBuffer)'empty buffer to make sure respons char is 4-th char (# or response char)
tmpCommand="K"
Call PrintText_TouchLCD(tmpCommand)' sending a 'K' tells Display to response on touch
tmpResponse = GetQueueStr(InBuffer)
TouchRespons = mid(tmpResponse,4,1) '# or number according to touched button
Select Case TouchRespons
Case "#"'do nothing
Call PutPin(6,zxOutPutHigh)
Case Else 'check button touched and open relevant menu or whatever
Call PutPin(6,zxOutPutLow)'just visualize rutine is responding to touch (maybe a Beep to)
Call Delay(0.05)
Call PutPin(6,zxOutPutHigh)
End Select
debug.print "Touched = " & TouchRespons
End Sub
Regards Hucke