;V-1 ;Compile with Crownhill Proton+ PIC Basic compiler. ;This program can steer 10 different things wireless with the use of a normal ; TV-remote-control with the RC5 protocol, from manufacters like Philips and Marantz. ;Use it as follows: ;When 'TV' mode is selected on your remote-control, you can with the buttons 0-9 on it, ; steer 10 outputs on and off. ;When there is an unused system on your remote-control (VCR2, SAT, AMP, DCC) then the ; code in the PIC can be changed with the remote-control to another system. ;That goes as follows: ;Switch the power from the PIC to OFF. ;Select an unused system on the remote-control (like VCR2, SAT, AMP or DCC). ;Push a button (0-9) on the remote-control and keep it pressed while switching the ; power from the PIC ON. ;If the LED blinks a couple of times slow, then the new system is programmed in EEPROM. ;Now the buttons 0-9 works only when the remote-control stands in the just programmed ; system mode. ;The LED burns continue while a valid button from a valid system is received and blinks ; fast when an invalid IR-code is received. ;This program uses 'System' which means equipment like TV, VCR, TAPE, SAT, etc. ;'Command' is used for buttons on the remote-control like 0-9, I/II, PLAY, STOP, etc. ;A push on a button from the RC5 remote-control sends: a header, a togglebit, ; an extended (7th) command bit, a 5 bit system-code and a 6 bit command code. ;When the received system-code is equal to the programmed one in the EEPROM, then the ; command-code is executed. ;The program is based on the 14-pins 16F630, but can ofcourse make workable on almost ; every type PIC. ;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 ; PIC16F630: +--v--+ ; +5V [ ] GND ; GND---[1k]---LED- <[ ]> Output 1 ; Output 0 <[ ]> Output 2 ; Signal from the TSOP1736 >[ ]> Output 3 ; Output 9 <[ ]> Output 4 ; Output 8 <[ ]> Output 5 ; Output 7 <[ ]> Output 6 ; +-----+ ;Er is ook een Nederlandse versie / There is a Dutch version too ;www.picbasic.nl / Frits Kieftenbelt, Raalte, Netherlands (Frizie) DEVICE 16F630 CONFIG INTRC_OSC_NOCLKOUT, WDT_OFF, PWRTE_ON, BODEN_OFF, MCLRE_OFF ;No crystal, PORTA.3 = input ALL_DIGITAL TRUE ;Normal aliases (constants) SYMBOL BlinkNumber = 10 ;Max 127: How many times the LED will blink when: system-code programmed SYMBOL BlinkTime = 150 ;mSec: Speed of blinking from the LED bij system-code programming SYMBOL DefaultSys = 0 ;0 = TV: After programming the PIC, the system default is TV (0) SYMBOL Glitch = 52 ;Max 255: Reduction glitches SYMBOL Ok = 50 ;Max 255: Controltime of the RC5 code is received ok SYMBOL Sample = 300 ;When all samples are UIT then there's no button pressed on the remote-control anymore SYMBOL TimeOut = 5000 ;When there is no IR-signal received within this time then ProgramMode = FALSE ;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 Output1 = PORTA.0 ;Pin 13 SYMBOL Output2 = PORTA.1 ;Pin 12 SYMBOL Output3 = PORTA.2 ;Pin 11 SYMBOL IR_Receiver = PORTA.3 ;Pin 4: TSOP1736 SYMBOL Output0 = PORTA.4 ;Pin 3 SYMBOL LED = PORTA.5 ;Pin 2: connect LED with 1k serial-resistor between PORT and GND SYMBOL Output4 = PORTC.0 ;Pin 10 SYMBOL Output5 = PORTC.1 ;Pin 9 SYMBOL Output6 = PORTC.2 ;Pin 8 SYMBOL Output7 = PORTC.3 ;Pin 7 SYMBOL Output8 = PORTC.4 ;Pin 6 SYMBOL Output9 = PORTC.5 ;Pin 5 ; 76543210 TRISA = %00001000 TRISC = %00000000 ;WORD DIM WD1 AS WORD ;Word Dummy ;BYTE DIM Command AS BYTE DIM Systeem AS BYTE DIM BD1 AS BYTE ;Byte Dummy ;BIT DIM ProgramMode AS BIT ;Becomes TRUE when directly after the start-up a IR-signal is received DIM ToggBit AS BIT ;ToggBit is unused in this program, is part of the RC5 code DIM Value AS BIT DIM ID1 AS BIT ;bIt Dummy EDATA DefaultSys CLEAR Output0 = OFF ;All outputs low when power on (start) Output1 = OFF Output2 = OFF Output3 = OFF Output4 = OFF Output5 = OFF Output6 = OFF Output7 = OFF Output8 = OFF Output9 = OFF DELAYMS 500 ;IR-receiver stabilize ProgramMode = TRUE ;By start-up the ProgramMode = TRUE 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 Start ;Error in receiving, no level change within time (No RC5 code or bad receiving) DELAYUS 1000 RETURN ;Mainprogramma Start: LED = OFF WD1 = TimeOut REPEAT IF WD1 = 0 THEN ProgramMode = FALSE DELAYUS 10 DEC WD1 UNTIL IR_Receiver = AAN ;Wait until a IR-signal is received BD1 = 0 WHILE IR_Receiver = AAN AND BD1 < Glitch INC BD1 WEND IF BD1 < Glitch THEN Start ;Error in receiving (No RC5 code or glitch) LED = ON ;Received a IR-signal DELAYUS 600 ;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 ProgramMode = TRUE THEN ProgramMode = FALSE EWRITE 0, [Systeem] BD1 = BlinkNumber * 2 Command = 127 ;Mutate the Command code, don't change any output while programming system REPEAT TOGGLE LED DEC BD1 DELAYMS BlinkTime UNTIL BD1 = 0 ENDIF IF Systeem = EREAD 0 THEN ;Only execute when the received system is equal to the one what is in EEPROM programmed SELECT CASE Command CASE 0: TOGGLE Output0 CASE 1: TOGGLE Output1 CASE 2: TOGGLE Output2 CASE 3: TOGGLE Output3 CASE 4: TOGGLE Output4 CASE 5: TOGGLE Output5 CASE 6: TOGGLE Output6 CASE 7: TOGGLE Output7 CASE 8: TOGGLE Output8 CASE 9: TOGGLE Output9 CASE 125: STOP ;Send a 125 to stop the PIC program so you can reprogram the 16F630 CASE ELSE GOTO Start ;When Systeem = EREAD 0 but no 0-9 button then the LED would burn continue, that isn't right, that's why GOTO Start END SELECT WD1 = Sample WHILE WD1 > 0 ;Wait while the button on the remote-control is pressed, if 300 samples nothing received, then the button isn't pressed anymore DEC WD1 IF IR_Receiver = AAN THEN WD1 = Sample ;Remote button still pressed, starting over with counting samples again DELAYUS 500 ;300 x 500us = 150ms WEND ENDIF GOTO Start