$regfile = "m32def.dat"
$crystal = 16000000
$hwstack = 64
$swstack=40
$framesize = 64
$baud = 9600
'*****************************************************************
'* CONFIG LCD *
'*****************************************************************
Config Lcd = 20x4
Config Lcdpin = Pin , Db4 = Portc.4 , Db5 = Portc.5 , Db6 = Portc.6 , Db7 = Portc.7 , E = Portc.3 , Rs = Portc.2
Cursor Off , Noblink
Cls
' wlacz LCD
Set Porta.2
'*****************************************************************
'* CONFIG BUFFERED USART FOR DEBUG via USB *
'*****************************************************************
'Config Com1 = Dummy , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
Config Serialin0 = Buffered , Size = 50 'RX from Terminal
Dim Char As Byte , Cmd_timeout1 As Byte , Got_str1 As Byte
Dim Command1 As String * 30
Dim Address As String * 4
Dim Buff(4) As Byte At Address Overlay
Dim Temperatures(2) As String * 20
'Open "COM1:" For Binary As #1
Config Print0 = Portd.2 , Mode = Set ' specify RS-485 and direction pin
Config Portd.2 = Output
'*****************************************************************
'* TIMER2 FOR TIME BASE *
'*****************************************************************
Config Timer2 = Timer , Prescale = 1024 , Compare = Disconnect , Clear_timer = 1
Compare2 = 155 '10ms @16MHz/1024
Dim Miliseconds As Byte , Seconds As Byte , Helpb As Byte , N As Byte
Enable Interrupts
Dim 1b As Byte
Dim 2b As Byte
Dim 3b As Byte
Dim 4b As Byte
Do
'--[ TIMER2 10ms ]----------------------------
If Tifr.ocf2 = 1 Then
Tifr.ocf2 = 1
If Miliseconds < 99 Then
Incr Miliseconds
Else
Miliseconds = 0
Incr Seconds : If Seconds > 15 Then Seconds = 0
Select Case Seconds
Case 0
cls
Locate 1 , 1 : Lcd "Ask * T04" : Waitms 200 ': Cls 'Heartbeat ;)
'tak nie zadziała
'--------------------------------------------
' Buff(1) = &H54
' Buff(2) = &H30
' Buff(3) = &H32
' Buff(4) = &H0D
' Printbin Buff(1)
'--------------------------------------------
'teraz zadziała
'--------------------------------------------
'1b = &H54 ' (T)
'2b = &H30 ' (0)
'3b = &H32 ' (2)
'4b = &H0D ' (ENTER)
1b = &H54 ' (T)
2b = &H30 ' (0)
3b = &H34 ' (4)
4b = &H0D ' (ENTER)
Printbin 1b
Printbin 2b
Printbin 3b
Printbin 4b
'--------------------------------------------
case 7
cls
Locate 1 , 1 : Lcd "Ask * T23" : Waitms 200 ': Cls 'Heartbeat ;)
'teraz zadziała
1b = &H54 ' (T)
2b = &H32 ' (2)
3b = &H33 ' (3)
4b = &H0D ' (ENTER)
Printbin 1b
Printbin 2b
Printbin 3b
Printbin 4b
End Select
End If
'COM1 USB
If Cmd_timeout1 > 0 Then
Decr Cmd_timeout1
If Cmd_timeout1 = 0 Then
'Got_str1 = 1
Command1 = ""
End If
End If
End If
'--[ USART0 COM1 USB ]------------------------
If 0 < Ischarwaiting() Then
Char = Inkey()
Select Case Char
Case 10
Case 13 : Got_str1 = 1
Case Else
Command1 = Command1 + Chr(char)
End Select
If Len(command1) > 49 Then Got_str1 = 1
If Got_str1 = 0 Then Cmd_timeout1 = 50 '50x10ms
'end if Ischarwaiting
End If
'--[ PARSE COM1 USB ]-------------------------
If Got_str1 = 1 Then
'-----------------------------------
' przykładowa odpowiedź T23= 31,9"C;T24= 34.1"C
Helpb = Split(command1 , Temperatures(1) , ";") 'podzieli na dwie linie ;)
Locate 2 , 1 : Lcd Temperatures(1)
Locate 3 , 1 : Lcd Temperatures(2)
Got_str1 = 0
Command1 = ""
Cmd_timeout1 = 0
End If
Loop