;V-1 ;Compile with Crownhill Proton+ PIC Basic compiler. ;This program displays on a (2*16) LC-Display (HD44780 4-line mode) the RC5 code. ;If PORTB.0 is set high then the system-name en command-name are given on display. ;If PORTB.0 is set low then the IR-code from system, command and togglebit are given: ;Sys: the decimal- and the binair- system value ;Com: the decimal- and the binair- command value ;Green LED: Infrared received. ;Yellow LED: No RC5 code or glitch. ;Red LED: No RC5 code or bad receiving. ;Toggle LED: RC5 toggle value (0 or 1). ;Newer systems like DVD work with the RC6 code and that's why they are not recognized. ;The RC5 list is not complete because of many dialects, they can be add in the list. ;But then there is a PICmicro with more memory on board (> 4k) necessary. ;Attention: The TSOP1736 (= 36kHz IR-receiver) must connected via a 470 Ohm resistor to ; +5V and over the + and - pin a tantalium C of minimal 0,1uF ! ; Connection TSOP1736: || | ; -+ s ; PIC16F648A: +--v--+ ; LED Green <[ ]> LED Red ; LED Toggle <[ ]> LED Yellow ; Signal from the TSOP1736 >[ ] ; Via resistor to +5V ---[33k]--- >[ ] ; GND [ ] +5V ; Unconn.=Show names/To GND=Show codes >[ ]> DB7 LCD ; [ ]> DB6 LCD ; LCD EN <[ ]> DB5 LCD ; LCD RS <[ ]> DB4 LCD ; +-----+ ;Er is ook een Nederlandse versie / There is a Dutch version too ;www.picbasic.nl / Frits Kieftenbelt, Raalte, Netherlands (Frizie) DEVICE 16F648A ;= 16F628A with 2x memory because of the many text CONFIG INTRC_OSC_NOCLKOUT, WDT_OFF, PWRTE_ON, BODEN_OFF, LVP_OFF ;No crystal ;XTAL 4 ;By use of a crystal use a 4MHz type ALL_DIGITAL TRUE ;Normal aliases (constants) SYMBOL Glitch = 52 ;Max 255: Reduction glitches SYMBOL LED_Time = 500 ;mSec: Error LED's burning time SYMBOL Ok = 50 ;Max 255: Controltime of the RC5 code is received ok ;Logic aliases (constants) SYMBOL AAN = 0 ;Reversed ON SYMBOL FALSE = 0 SYMBOL OFF = 0 SYMBOL ON = 1 SYMBOL TRUE = 1 SYMBOL UIT = 1 ;Reversed OFF ;Port aliases SYMBOL LED_Y = PORTA.0 ;Connect LED's in serial with 1k resistor between PORT and GND SYMBOL LED_R = PORTA.1 SYMBOL LED_G = PORTA.2 SYMBOL LED_Toggle = PORTA.3 SYMBOL IR_Receiver = PORTA.4 ;TSOP1736 SYMBOL ByName = PORTB.0 ;When low the IR-code is given else (unconnected) the System-name and Command-name ; 76543210 TRISA = %11110000 TRISB = %11111111 PORTB_PULLUPS ON ;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 CLEAR DELAYMS 500 ;LC-Display stabilise CLS: PRINT "RC5 Names UK V-1" ;Program name and version PRINT AT 2,1,"www.picbasic.nl" GOTO Start ;Subroutines BitOphalen: Value = IR_Receiver ;Make value 0 or 1 dependent from received IR-code BD1 = 0 WHILE IR_Receiver = Value AND BD1 < Ok;Level must change within time 'Ok' INC BD1 WEND IF Ok = BD1 THEN ErrorReceive ;No level-change whitin the 'Ok' time DELAYUS 1100 ;950 - 1600 RETURN ;Mainprogram Start: LED_G = OFF LED_Y = OFF LED_R = OFF ByNameOld = ByName BD1 = 0 WHILE IR_Receiver = 1 WEND ;Wait until a IR-signal is received WHILE IR_Receiver = 0 AND BD1 < Glitch INC BD1 WEND IF BD1 < Glitch THEN GOTO ErrorGlitch CommandOld = Command ;Save old values for repair in case of a error SysteemOld = Systeem LED_G = ON ;Received an IR-signal DELAYUS 500 ;200 - 825; Avoid RC5 header GOSUB BitOphalen Command.6 = Value ^ 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 ByName <> ByNameOld THEN ;Without this line the LCD blinks by IR receiving (because of CLS) CLS IF ByName = TRUE THEN SELECT CASE Systeem CASE 0: PRINT "TV" CASE 1: PRINT "TV2" CASE 2: PRINT "Teletext" CASE 3: PRINT "Video VD" CASE 4: PRINT "Video LV1" CASE 5: PRINT "VCR1" CASE 6: PRINT "VCR2" CASE 8: PRINT "SAT" CASE 9: PRINT "Camera" CASE 10: PRINT "SAT2" CASE 12: PRINT "CDV" CASE 13: PRINT "Camcorder" CASE 16: PRINT "Amplifier" CASE 17: PRINT "Tuner" CASE 18: PRINT "Tape" CASE 19: PRINT "Pre-amplifier" CASE 20: PRINT "CD" CASE 21: PRINT "Phono" CASE 23: PRINT "Digital tape" ;DAT, MD, DCC CASE 26: PRINT "CDR" CASE 29: PRINT "Lighting" CASE 30: PRINT "Lighting 2" CASE 31: PRINT "Telephone" CASE ELSE: PRINT "Sys:", DEC Systeem END SELECT CURSOR 2,1 SELECT CASE Command CASE 0 TO 9: PRINT "Button ", DEC Command CASE 10: PRINT "-/--" CASE 11: SELECT CASE Systeem CASE 0: PRINT "C/P" ;TV CASE 5, 6: PRINT "C/P / Select" ;VCR 1 & 2 CASE 20,23:PRINT "Time" ;CD, DCC END SELECT CASE 12: PRINT "Stand-by" CASE 13: PRINT "Mute" CASE 14: SELECT CASE Systeem CASE 0: PRINT "Personal" ;TV CASE 5, 6: PRINT "Tracking" ;VCR 1 & 2 END SELECT CASE 15: PRINT "Info" CASE 16: PRINT "Volume +" CASE 17: PRINT "Volume -" CASE 18: PRINT "Brightness +" CASE 19: PRINT "Brightness -" CASE 20: PRINT "Color +" CASE 21: PRINT "Color -" CASE 22: PRINT "Bass +" CASE 23: PRINT "Bass -" CASE 24: PRINT "Treble +" CASE 25: PRINT "Treble -" CASE 26: PRINT "Balance R" CASE 27: PRINT "Balance L" CASE 28 SELECT CASE Systeem CASE 20: PRINT "Shuffle" ;CD CASE 23: PRINT "Repeat" ;DCC END SELECT CASE 29: SELECT CASE Systeem CASE 5, 6: PRINT "Timer" ;VCR 1 & 2 CASE 20: PRINT "Repeat" ;CD END SELECT CASE 30: SELECT CASE Systeem CASE 5, 6: PRINT "Record mode" ;VCR 1 & 2 CASE 17: PRINT "Search +" ;Tuner END SELECT CASE 31: SELECT CASE Systeem CASE 5, 6: PRINT "Fast reverse 1" ;VCR 1 & 2 CASE 17: PRINT "Search -" ;Tuner END SELECT CASE 32: PRINT "Program +" CASE 33: PRINT "Program -" CASE 34 SELECT CASE Systeem CASE 0: PRINT "P