$crystal = 4000000 'Normal aliases (constants) Const Glitch = 30 ' Max 255 ' Reduction Glitches Const Led_time = 500 ' Msec : Error Led's burning time Const Ok = 50 ' Max 255 Controltime Of The Rc5 Code Is Received Ok 'Logic aliases (constants) Const Aan = 0 ' Reversed On Const False = 0 Const Off = 0 Const On = 1 Const True = 1 Const Uit = 1 ' Reversed Off 'Port aliases Led_y Alias Portd.0 ' Connect Led 's in serial with 1k resistor between PORT and GND Led_r Alias Portd.1 Led_g Alias Portd.2 Led_toggle Alias Portd.3 Ir_receiver Alias Pind.4 ' Tsop1736 'TRISA = %11110000 'TRISB = %11111111 'PORTB_PULLUPS ON 'Portc = 255 Dim Irsys As Eram Byte Dim Ircomm As Eram Byte ';BYTE Dim Command As Byte Dim Commandold As Byte Dim Systeem As Byte Dim Systeemold As Byte Dim Bd1 As Byte 'Byte Dummy ';BIT Dim Bynameold As Bit 'When switching between code- and text-mode and sending the same RC5 code then should the LCD not been updated Dim Toggbit As Bit Dim Value As Bit Dim Id1 As Bit 'bIt Dummy Config Portd = Output Portd = 255 Config Portd.1 = Input Config Portd.4 = Input 'TSOP Goto Start 'Subroutines Bitophalen: Value = Pind.4 'Ir_receiver 'Make value 0 or 1 dependent from received IR-code Bd1 = 0 While Pind.4 = Value And Bd1 < Ok 'Level must change within time 'Ok' Incr Bd1 'INC BD1 Wend If Ok = Bd1 Then Goto Errorreceive 'No level-change whitin the 'Ok' time Waitus 1100 '950 - 1600 Return 'Mainprogram Start: Led_g = 0 Led_y = 0 Led_r = 0 Led_toggle = 0 ' Bynameold = Byname 'Pinc.0 'ByName Bd1 = 0 'While Ir_receiver = 1 While Pind.4 = 1 Wend 'Wait until a IR-signal is received While Pind.4 = 0 And Bd1 < Glitch Incr Bd1 Wend If Bd1 < Glitch Then Goto Errorglitch Commandold = Command 'Save old values for repair in case of a error Systeemold = Systeem Led_g = 1 'Received an IR-signal Waitus 500 '200 - 825; Avoid RC5 header Gosub Bitophalen Command.6 = Value Toggle Command.6 ' ^ 1 'Extended bit Gosub Bitophalen Toggbit = Value Gosub Bitophalen Systeem.4 = Value Gosub Bitophalen Systeem.3 = Value Gosub Bitophalen Systeem.2 = Value Gosub Bitophalen Systeem.1 = Value Gosub Bitophalen Systeem.0 = Value Gosub Bitophalen Command.5 = Value Gosub Bitophalen Command.4 = Value Gosub Bitophalen Command.3 = Value Gosub Bitophalen Command.2 = Value Gosub Bitophalen Command.1 = Value Gosub Bitophalen Command.0 = Value If Systeem <> Systeemold Or Command <> Commandold Or Pinc.0 <> Bynameold Then Irsys = Systeem Ircomm = Command End If Led_toggle = Toggbit Goto Start Errorglitch: Led_y = 1 'Receive error (No RC5 code or glitch) Waitms Led_time Goto Start Errorreceive: Led_g = 0 Led_r = 1 'No RC5 code or no optimal receiving Waitms Led_time Command = Commandold 'Repair Command and Systeem Systeem = Systeemold Goto Start