;V-2 ;For electronic scheme see website www.picbasic.nl ; PIC12F629: +--v--+ ; +5V [ ] GND ; STANDBY key |---/--- >[ ]> -[4k7]---NPN transistor IR LED ; PROGRAM- key |---/--- >[ ]< ---/---| key VOLUME- ; pull-up! PROGRAM+ key |---/--- >[ ]< ---/---| key VOLUME+ ; - +-----+ - ;Er is ook een Nederlandse versie / There is a Dutch version too ;www.picbasic.nl / Frits Kieftenbelt, Raalte, Netherlands (Frizie) DEVICE 12F629 CONFIG INTRC_OSC_NOCLKOUT, WDT_OFF, PWRTE_ON, MCLRE_OFF ;No crystal, no reset ALL_DIGITAL TRUE ;Normal aliases (constants) SYMBOL Debounce = 5 ;mSec: Push button debounce time SYMBOL ProgramUp = 32 ;Key Program + SYMBOL ProgramDown = 33 ;Key Program - SYMBOL StandBy = 12 ;Key Stand-by SYMBOL VolumeUp = 16 ;Key Volume + SYMBOL VolumeDown = 17 ;Key Volume - ;Logical 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 IrOut = GPIO.0 ;Infrared LED. Amplifie via 4k7 resistor to NPN transistor (i.e. BC547 and 47 Ohm to IR-LED) ; 76543210 TRISIO = %11111110 PORTB_PULLUPS ON ;BYTE DIM Command AS BYTE ;Contains the RC5 command code which gonna be send DIM Cycl_1 AS BYTE ;For ASM routine DIM Cycl_2 AS BYTE ;For ASM routine DIM Key AS BYTE ;Contains the value from the inputs (de push-buttons) DIM Systeem AS BYTE ;Contains the RC5 system code for which device the RC5 code is ment ;BIT DIM ToggleBit AS BIT ;Togglebit from RC5 PORTB = 0 CLEAR Systeem = 0 ;Fill here the system address (0 = TV) (Don't define Systeem as a constant alias, because that won't work (Works only when it's 0) IF GPIO.5 = AAN THEN STOP ;When the StandBy key is pushed when switch the power on the PIC stops (for re-programming PIC12F629) ;MAIN PROGRAM Again: REPEAT Key = (GPIO & %00111110) ;Read only the inputs UNTIL Key <> 62 ;Wait for key press DELAYMS Debounce ;Debounce time for push-buttons IF Key <> (GPIO & %00111110) THEN Again ;Not the same? Then it was probably a glitch, scan buttons Again IF (Key & %00000010) = AAN THEN Command = VolumeDown IF (Key & %00000100) = AAN THEN Command = VolumeUp IF (Key & %00001000) = AAN THEN Command = ProgramUp IF (Key & %00010000) = AAN THEN Command = ProgramDown IF (Key & %00100000) = AAN THEN Command = StandBy ToggleBit = ToggleBit ^ 1 ;Toggle the RC5 togglebit WHILE (GPIO & %00111110) <> 62 ;While button is pressed, keep sending signal GOSUB RC5_Code ;Call RC5 assembler routine DELAYMS 82 ;Pause between the IR-zendingen WEND GOTO Again ;ASSEMBLER ROUTINE RC5_Code: ASM ;Send a complete RC5 code call TxEenRC5 ;Header btfss Command,6 ;Inverted command bit call TxEenRC5 btfsc Command,6 call TxNulRC5 ;Togglebit btfsc ToggleBit call TxEenRC5 btfss ToggleBit call TxNulRC5 ;Systembit (A4,3,2,1,0) Address btfsc Systeem,4 call TxEenRC5 btfss Systeem,4 call TxNulRC5 btfsc Systeem,3 call TxEenRC5 btfss Systeem,3 call TxNulRC5 btfsc Systeem,2 call TxEenRC5 btfss Systeem,2 call TxNulRC5 btfsc Systeem,1 call TxEenRC5 btfss Systeem,1 call TxNulRC5 btfsc Systeem,0 call TxEenRC5 btfss Systeem,0 call TxNulRC5 ;Commandbit (D5,4,3,2,1,0) Data btfsc Command,5 call TxEenRC5 btfss Command,5 call TxNulRC5 btfsc Command,4 call TxEenRC5 btfss Command,4 call TxNulRC5 btfsc Command,3 call TxEenRC5 btfss Command,3 call TxNulRC5 btfsc Command,2 call TxEenRC5 btfss Command,2 call TxNulRC5 btfsc Command,1 call TxEenRC5 btfss Command,1 call TxNulRC5 btfsc Command,0 call TxEenRC5 btfss Command,0 call TxNulRC5 return ;***************************** ;Send a 0 (on-off) TxNulRC5 call LichtAanRC5 call LichtUitRC5 return ;***************************** ;Send a 1 (off-on) TxEenRC5 call LichtUitRC5 call LichtAanRC5 return ;***************************** ;IR-LED off LichtUitRC5 movlw D'100' ;RC5 has 100 (255 when xtal = 10MHz) time units from IR-LED off movwf Cycl_2 LichtUit2RC5 nop ;Short delays nop nop nop nop nop decfsz Cycl_2,f goto LichtUit2RC5 return ;***************************** ;IR-LED on (pulsing) LichtAanRC5 movlw D'32' ;RC5 gives 32 fast IR-LED pulses for a '1' movwf Cycl_1 ;32 Cyclussen from a pause and a pulse LichtAan1RC5 ;Pause nop movlw D'4' ;Time for (15 when Xtal = 10MHz) pause between IR-LED blink movwf Cycl_2 LichtAan2RC5 decfsz Cycl_2,f goto LichtAan2RC5 ;Pulse bsf IrOut ;IR-LED on movlw D'1' ;Time for (5 when Xtal = 10MHz) IR-LED blink movwf Cycl_2 LichtAan3RC5 decfsz Cycl_2,f goto LichtAan3RC5 bcf IrOut ;IR-LED off decfsz Cycl_1,f goto LichtAan1RC5 return ENDASM ;V-2 update to V-1: ;Systeem as constant (SYMBOL) doesn't work (works only when Systeem = 0) ;By V-2 is Systeem a BYTE-variable