$regfile = "m8def.dat"
$crystal = 16000000
$baud = 19200
$hwstack = 200 ' HW-Stack: Rücksprungadressen für Interrupts und Registerspeicherung
$swstack = 50 ' SW-Stack: Rücksprungadressen von Subs und Variableadressen
$framesize = 25
Config Pind.2 = Input
Config Portd.5 = Output
Alive_led Alias Portd.5
Dim Zeit As Byte
Dim Byte0 As Byte
Dim Byte1 As Byte
Dim Byte2 As Byte
Dim Byte3 As Byte
Dim Empfang As Byte
Dim Anzahl As Byte
'interrupts
Enable Int0
Config Int0 = Falling
On Int0 Infrared
'16.000.000/8 = 2.000.000
'2.000.000/36700= 54,5
'255-55 = 200 bzw 65535-56= 65479 bei
Config Timer1 = Timer , Prescale = 8
Enable Timer1
On Timer1 Tikers
Const Timervorgabe = 65021
Stop Timer1
Dim Tik As Word 'counter of teaks of timer
Dim Byt As Byte 'counter accepted bit
Dim Repeat_flag As Bit 'flag of repetition
Dim Start_flag As Bit 'flag of start condition
Dim Address As Byte 'byte of address
Dim Command As Byte 'byte of command
Dim Address_1 As Byte 'direct byte of address
Dim Command_1 As Byte 'direct byte of command
Dim Address_0 As Byte 'indirect byte of address
Dim Command_0 As Byte 'indirect byte of command
Dim Summa As Word
'################################################################################################################
Do 'Main cycle
'Print Address ; " " ; Command 'Lcd ADDRESS and COMMAND
If Command = 8 Then alive_led = 1 'If pressed key "P+" - to include LED
If Command = 240 Then Alive_led = 0 'If pressed key "P-" - to switch off LED
Waitms 10 'Delay 10 e(n'
Loop
End 'End of main cycle
'################################################################################################################
Tikers: 'work on timer
'Timer0 = 253 '31250/(256-253)=10416,66 Hz (96 e(e;n')
Incr Tik
If Tik >= 1200 Then 'if 1200 teaks, have thrown all in source condition
Tik = 0
Repeat_flag = 0
Start_flag = 0
Address_1 = 0
Command_1 = 0
Address_0 = 0
Command_0 = 0
Address = 0
Command = 0
Stop Timer1
End If
Return
'################################################################################################################
Infrared: 'work on interruption
Start Timer1
Print "ir int"
If Tik >= 139 And Tik < 150 Then 'if has happenned from 139 before 150 teaks - "START"
Address = 1
Repeat_flag = 0
Start_flag = 1
Address_1 = 0
Command_1 = 0
Address_0 = 0
Command_0 = 0
End If
If Tik >= 116 And Tik < 139 Then 'if has happenned from 116 before 138 teaks - "REPETITION"
Address = 2
Repeat_flag = 1
Start_flag = 0
End If
If Tik >= 22 And Tik < 116 And Start_flag = 1 Then 'if has happenned from 22 before 115 teaks - have taken "1"
Incr Byt
If Byt < 9 Then
Shift Address_1 , Left
Address_1 = Address_1 + 1
End If
If Byt >= 9 And Byt < 17 Then
Shift Address_0 , Left
Address_0 = Address_0 + 1
End If
If Byt >= 17 And Byt < 25 Then
Shift Command_1 , Left
Command_1 = Command_1 + 1
End If
If Byt >= 25 Then
Shift Command_0 , Left
Command_0 = Command_0 + 1
End If
End If
If Tik >= 10 And Tik < 22 And Start_flag = 1 Then 'if has happenned from 10 before 21 teaks - have taken "0"
Incr Byt
If Byt < 9 Then
Shift Address_1 , Left
End If
If Byt >= 9 And Byt < 17 Then
Shift Address_0 , Left
End If
If Byt >= 17 And Byt < 25 Then
Shift Command_1 , Left
End If
If Byt >= 25 Then
Shift Command_0 , Left
End If
End If
Tik = 0
If Byt = 32 Then 'if have taken 4 bytes, check correctness a receiving a command
'if address or command 16-bit, check does not pass
'Summa = Address_0 + Address_1
'If Summa = 255 Then
Address = Address_1
'Else
'Address = 0
'End If
'Summa = Command_0 + Command_1
'If Summa = 255 Then
Command = Command_1
'Else
'Command = 0
'End If
Byt = 0
Repeat_flag = 0
Start_flag = 0
Print "Command." ; Command
Print "Address:" ; Address
Stop Timer1
End If
Return