;V-4 ;PCB 110820 ;For connection, diagram and operation see website www.picbasic.nl ; ; PIC16F628A: +--v--+ ; +5V---LED_Green----[1k ]--- <[ ]> RS LCD ; +5V---LED_Red------[1k ]--- <[ ]> EN LCD ; +5V---LED_Toggle---[1k ]--- <[ ]< X-tal 10MHz ;PULL-UP!System adjust button |---/--- >[ ]< X-tal 10MHz ; GND [ ] +5V ; S2 ADJUST button |---/--- >[ ]> DB7 LCD ; S1 SEND button _---/--- >[ ]> DB6 LCD ; NPN transistor IR LED----[4k7]--- <[ ]> DB5 LCD ; TSOP1736 IR-receiver >[ ]> DB4 LCD ; +-----+ ;Er is ook een Nederlandse versie / There is also a Dutch version ;www.picbasic.nl / Frits Kieftenbelt, Raalte, Netherlands (Frizie) DEVICE 16F628A CONFIG HS_OSC, WDT_OFF, PWRTE_ON, BODEN_OFF, LVP_OFF, MCLRE_OFF ;PORTA.5 = input for SYSTEM ADJUST BUTTON XTAL 10 ALL_DIGITAL TRUE ;Normal aliases (constants) SYMBOL Acceleration= 12 ;The acceleration from the repeatingtime while the ADJUST button is being pressed SYMBOL Debounce = 10 ;mSec: Pushbutton debounce time SYMBOL Glitch = 30 ;Max 65535: Failure-time (glitches) SYMBOL BlinkFreq = 50 ;Max 255: Blinkfrequency from LED (=mSec x 10, i.e. 50x10=500, 500mSec blinkfreq) SYMBOL LED_Time = 1000 ;mSec: Error LED's burning time SYMBOL Ok = 275 ;Max 65535: Controltime for correct receiving SYMBOL ProtocolLCD = 1000 ;mSec: Time for LCD indication RC5, RC5X or RC6 protocol SYMBOL StartRepeat = 180 ;Max.255: Time you have to push the ADJUST button before it going to repeat SYMBOL StartTime = 200 ;Max.255: Startspeed for repeating when the ADJUST button is keeping pressed ;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 ;EEPROM addressnames SYMBOL EE_Mode = 0 ;EEPROM address, contains which mode (RC5X or RC6) is used the latest time SYMBOL EE_RC5c = 1 ;EEPROM address, for RC5 command SYMBOL EE_RC5s = 2 ;EEPROM address, for RC5 system-address SYMBOL EE_RC6c = 3 ;EEPROM address, for RC6 command SYMBOL EE_RC6s = 4 ;EEPROM address, for RC6 system-address EDATA 0, 0, 0, 0, 0 ;After PIC programming the system-addresses and command to 0 and in RC6 mode ;Port aliases, when you change it, check also TRIS DECLARE LCD_ENPIN = PORTA.0 ;Because only PORTB has pullups for the buttons, the EN and RS from the LCD are displaced to PORTA DECLARE LCD_RSPIN = PORTA.1 SYMBOL LED_Green = PORTA.2 ;Infrared receiving signal LED SYMBOL LED_Red = PORTA.3 ;No RC5/RC6 code or bad receiving SYMBOL LED_Toggle = PORTA.4 ;RC5/RC6 toggle signal SYMBOL PRG_Systeem = PORTA.5 ;When this port is connected to GND, then you can adjust the RC5X/RC6 system address (PULL-UP 33k resistor!!!) SYMBOL Adjust = PORTB.0 ;Address up or down (alternately) (depence from bit Plus) SYMBOL Send = PORTB.1 ;Send the adjusted RC5X or RC6 code by connecting this port to GND (Via button SEND) SYMBOL IrOut = PORTB.2 ;Infrared LED. Amplifie the LED via a 10k resistor to the basis of a NPN transistor (i.e. BC547 to an IR-LED and 47E serial resistor) SYMBOL IR_Receiver = PORTB.3 ;TSOP1736 Infrared receiver ;WORD DIM WD1 AS WORD ;Word Dummy ;BYTE DIM Blink AS BYTE ;Counter for blinkfrequency from LED DIM Command AS BYTE ;Contains the RC5/RC6 commandvalue for the LC-Display DIM Command_O AS BYTE ;RC5/RC6 command byte which is received DIM CommandOud_O AS BYTE ;Backup for last Command, in case of a receive error Command_O can be repaired DIM Command_Z AS BYTE ;Contains the RC5 or RC6 command code which must be send out DIM Cycl_1 AS BYTE ;For ASM routine DIM Cycl_2 AS BYTE ;For ASM routine DIM MaxCommand AS BYTE ;Maximum possible command adjustment, for RC5/RC5X is this 127, for RC6 is this 255 DIM MaxSysteem AS BYTE ;Maximum possible system adjustment, for RC5/RC5X is this 31, for RC6 is this 255 DIM RepeteerTime AS BYTE ;The repeatingtime (which goes faster and faster) when keeping the ADJUST button pressed DIM Systeem AS BYTE ;Contains the RC5/RC6 systemvalue for the LC-Displa DIM Systeem_O AS BYTE ;RC5/RC6 system byte which is received DIM SysteemOud_O AS BYTE ;Backup for last System, in case of a receive error Systeem_O can be repaired DIM Systeem_Z AS BYTE ;Contains the RC5 or RC6 system code which must be send out DIM Time AS BYTE ;Time for subroutine Timer DIM BD1 AS BYTE ;Byte Dummy ;BIT DIM CodeRC5X AS BIT ;TRUE when it is a RC5X code else... DIM CodeRC6 AS BIT ;...TRUE if it is a RC6 code (else RC5) DIM CodeRC6Oud AS BIT ;By switching between RC6 and RC5/RC5X must the LCD been updated DIM Plus AS BIT ;If TRUE then Teller counts up, else down DIM PRG_EEPROM AS BIT ;If TRUE then the system-address must stored in EEPROM when for the first time the SEND button is pressed DIM RC5_Mode AS BIT ;If TRUE the RC5(X) protocol is active, if FALSE then RC6 DIM Repeteren AS BIT ;If TRUE then the Systeem_Z or Command_Z goes automatic up or down DIM ToggBit_O AS BIT ;Togglebit RC5/RC6 from IR-receiver DIM ToggBit_Z AS BIT ;Togglebit RC5/RC6 from IR-transmitter (sender) DIM UpdateLCD AS BIT ;TRUE if LCD is been updated DIM Value AS BIT ;Argument for subroutine "BitOphalen" 'DIM ID1 AS BIT ;bIt Dummy ReStart: ;If 'ADJUST' and 'SEND' are pushed at the same time follows a restart from here ; 76543210 PORTA = %00000000 PORTB = %00000000 TRISA = %11100011 TRISB = %11111011 PORTB_PULLUPS ON ;For the pushbuttons CLEAR LED_Green = UIT LED_Red = UIT LED_Toggle = UIT DELAYMS 500 ;LC-Display stabilise CLS PRINT "Transcver UK V-4" PRINT AT 2, 1, "www.picbasic.nl" DELAYMS 2000 CLS PRINT "ADJUST=Select" ;Make choice between RC6 or RC5/RC5X sending PRINT AT 2, 1, "SEND=Continue" RC5_Mode = 1 ^ EREAD EE_Mode ;Read EEPROM inverted because right after this it's being inverted back WHILE Send = UIT ;Confirm selection between RC6 and RC5/RC5X with the 'SEND' button DELAYMS Debounce RC5_Mode = RC5_Mode ^ 1 ;Toggle between RC5 and RC6 CURSOR 1, 14 IF RC5_Mode = TRUE THEN PRINT "RC5" ELSE PRINT "RC6" ENDIF WHILE Adjust = AAN ;Wait here until the 'ADJUST' button is released GOSUB BlinkLED ;Meanwhile blinks the green LED WEND WHILE Adjust = UIT AND Send = UIT ;Wait here till the 'ADJUST'- or 'SEND' button is pressed GOSUB BlinkLED ;Meanwhile blinks the green LED WEND PRINT AT 2, 6, "Confirm " WEND WHILE Send = AAN: WEND ;Wait till the 'SEND' button is released (else it would sending directly) IF RC5_Mode <> EREAD EE_Mode THEN EWRITE EE_Mode, [RC5_Mode];Store RC5_mode only when it has been changed IF RC5_Mode = TRUE THEN ;If it's RC5 betreft then... MaxCommand = 127 MaxSysteem = 31 Command_Z = EREAD EE_RC5c ;Adjust command from IR-transmitter to the last used RC5 command Systeem_Z = EREAD EE_RC5s ;Adjust system from IR-transmitter to the last used RC5 system address ELSE ;... else it's RC6 MaxCommand = 255 MaxSysteem = 255 Command_Z = EREAD EE_RC6c ;Adjust command from IR-transmitter to the last used RC6 command Systeem_Z = EREAD EE_RC6s ;Adjust system from IR-transmitter to the last used RC6 system address ENDIF Command = Command_Z ;Command which is used the last time (before switched off) Systeem = Systeem_Z ;System which is used the last time (before switched off) Plus = TRUE ;The first time default is count up CLS GOSUB Display GOTO Opnieuw ;Jump over subroutines ;SUBROUTINES BitOphalen: WD1 = 0 Value = IR_Receiver ;Make value 0 or 1, depending from received IR-code WHILE IR_Receiver = Value AND WD1 < Ok ;Level must change within time 'Ok' INC WD1 WEND IF Ok = WD1 THEN ErrorOntvangst ;No level-change whitin the 'Ok' time IF CodeRC6 = TRUE THEN Value = 1 - Value ;RC6 is inverted to RC5/RC5X DELAYUS 625 ;525 - 725 ;(889us / 2 = 444) + half from this time to come in the middle of the next bit; 444+222 = 666, - a few usec's for the program itself = about 625 ELSE DELAYUS 1100 ;950 - 1600 ENDIF RETURN Display: PRINT AT 1, 1, "Sys:", DEC Systeem, " " PRINT AT 2, 1, "Com:", DEC Command, " " IF RC5_Mode = TRUE THEN ;RC5 has 5 systembits en 7 commandbits PRINT AT 1, 11, BIN5 Systeem PRINT AT 2, 9, BIN7 Command ELSE ;RC6 has 8 systembits en 8 commandbits PRINT AT 1, 9, BIN8 Systeem PRINT AT 2, 9, BIN8 Command ENDIF RETURN BlinkLED: DELAYMS Debounce INC Blink IF Blink > BlinkFreq THEN CLEAR Blink ;Reset counter Blink LED_Green = LED_Green ^ 1 ;Toggle LED ENDIF RETURN Timer: ;Delay, but return directly if the 'ADJUST' button is released WHILE Adjust = AAN AND Time > 0 ;Wait till the 'ADJUST' button is released OR Time is past DEC Time DELAYMS 2 IF Send = AAN THEN BREAK ;When pressing 'ADJUST'- and 'SEND' buttons at the same time then restart (You can then select between RC5 and RC6 again) WEND RETURN ;MAIN PROGRAM Opnieuw: CodeRC6Oud = CodeRC6 ;By switching between RC6 and RC5/RC5X must the LCD been updated LED_Green = UIT ;IR receiving LED off LED_Red = UIT ;IR receiving error LED off IF Send = UIT AND Adjust = UIT THEN RepeteerTime = StartTime Repeteren = FALSE ENDIF WHILE Send = UIT AND Adjust = UIT AND IR_Receiver = UIT ;Wait for a key press or IR receive WEND IF IR_Receiver = AAN THEN ;Examine if it is an IR-receive or a key press GOTO IR_Ontvangst ;If it is an IR-receive then IR_Ontvangst ELSE DELAYMS Debounce ;Against bouncing from pushbuttons IF Send = UIT AND Adjust = UIT THEN Opnieuw ;Measure again, if no key is pressed, starting over ENDIF IF Adjust = AAN THEN ;If ADJUST button is pressed then... IF Send = AAN THEN Start ;If also the SEND button is pressed ('ADJUST'- and 'SEND' buttons pressed at the same time) then restart (You can then select between RC5 and RC6 again) UpdateLCD = FALSE ;LCD isn't up to date anymore, because value(s) are changed PRG_EEPROM = TRUE ;The RC code is gonna changed, program after sending the new adjustments in EEPROM IF RepeteerTime = StartTime THEN ;Check if the 'ADJUST' button is pressed for a short- or a long time BD1 = StartRepeat WHILE Adjust = AAN AND BD1 > 0 ;While the 'ADJUST' button is pressed AND the time isn't past yet... DELAYMS 5 DEC BD1 WEND IF BD1 < 1 THEN ;If the 'ADJUST' button was pressed whole StartRepeat time is then... Plus = Plus ^ 1 ;...count in other direction and... Repeteren = TRUE ;...repeat automatic ENDIF ENDIF IF Plus = TRUE THEN ;If Teller counts up then... IF PRG_Systeem = AAN THEN ;If adjusting system-address then... ' PRG_EEPROM = TRUE ;The system-address is gonna changed, program after adjusting the new system-address in EEPROM IF Systeem_Z < MaxSysteem THEN INC Systeem_Z ;Increase the system-address with 1 ELSE Systeem_Z = 0 ;If MaxSysteem address was reached, then start with 0 again ENDIF ELSE ;If NOT adjusting the system-address then adjust the command-code IF Command_Z < MaxCommand THEN INC Command_Z ;Increase the command-code with 1 ELSE Command_Z = 0 ;If MaxCommand-code was reached, then start with 0 again ENDIF ENDIF ELSE ;ELSE (Teller counts down) IF PRG_Systeem = AAN THEN ;If adjusting system-address then... ' PRG_EEPROM = TRUE ;The system-address is gonna changed, program after adjusting the new system-address in EEPROM IF Systeem_Z > 0 THEN ;If system-address wasn't 0 then... DEC Systeem_Z ;...decrease the system-address with 1 ELSE Systeem_Z = MaxSysteem ;If system-address is 0 then start with value from MaxSysteem again ENDIF ELSE ;If NOT adjusting the system-address then adjust the command-code IF Command_Z > 0 THEN DEC Command_Z ;Decrease the command-code with 1 ELSE Command_Z = MaxCommand;If command-address is 0 then start with value from MaxCommand again ENDIF ENDIF ENDIF Command = Command_Z ;Give Zend-Commandvalue to Command for display Systeem = Systeem_Z ;Give Zend-System value to System for display GOSUB Display ;Update HD44780 LCD IF Repeteren = TRUE THEN ;If the counter counts automatically up or down (repeating) then... Time = RepeteerTime ;RepeteerTime keeps a time which is more and more smaller (=faster) GOSUB Timer IF RepeteerTime = StartTime THEN ;Only the first time an extra time (to release the button when only changing from direction) Time = 250 ;This is that extra time GOSUB Timer ENDIF IF RepeteerTime > Acceleration THEN RepeteerTime = RepeteerTime - Acceleration ;Acceleration from the repeating counter ENDIF ELSEIF Send = AAN THEN ;If the 'SEND' button is pressed then... IF PRG_EEPROM = TRUE THEN ;It seems that the system-address is changed, store the new address first in EEPROM PRG_EEPROM = FALSE IF RC5_Mode = TRUE THEN ;If it's the RC5 system-address then... IF EREAD EE_RC5c <> Command_Z THEN EWRITE EE_RC5c, [Command_Z] ;Write the RC5 command in EEPROM IF EREAD EE_RC5s <> Systeem_Z THEN EWRITE EE_RC5s, [Systeem_Z] ;Write the RC5 system-address in EEPROM ELSE ;ELSE (RC6) IF EREAD EE_RC6c <> Command_Z THEN EWRITE EE_RC6c, [Command_Z] ;Write the RC6 command in EEPROM IF EREAD EE_RC6s <> Systeem_Z THEN EWRITE EE_RC6s, [Systeem_Z] ;Write the RC6 system-address in EEPROM ENDIF ENDIF ToggBit_Z = ToggBit_Z ^ 1;Toggle the RC5/RC6 togglebit from the IR-transmitter LED_Toggle = ToggBit_Z ;Toggle also the toggle LED WHILE Send = AAN LED_Green = AAN IF RC5_Mode = FALSE THEN ;If user select not RC5 then... GOSUB RC6_Code ;...call RC6 assembler routine... ELSE ;...ELSE... GOSUB RC5_Code ;...call RC5 assembler routine ENDIF LED_Green = UIT IF Adjust = AAN THEN Start ;When pressing 'ADJUST'- and 'SEND' buttons at the same time then restart (You can then select between RC5 and RC6 again) DELAYMS 82 ;Pauze between every IR-sending WEND ENDIF GOTO Opnieuw IR_Ontvangst: WD1 = 0 WHILE IR_Receiver = AAN AND WD1 < 65500 ;65500 is only for escaping from this loop, because if the IR_Receiver is always AAN, the program should hang INC WD1 WEND CodeRC5X = FALSE ;Reset RC5 / RC5X indicator CodeRC6 = FALSE ;Reset RC5 / RC6 indicator ;Find out which protocol ----- SELECT CASE WD1 CASE < Glitch ;Glitch... GOTO Opnieuw ;... so start measuring again CASE 45 TO 60 ;RC5 DELAYUS 2125 ;1750 - 2500; RC5 CASE 90 TO 110 ;RC5X CodeRC5X = TRUE DELAYUS 1280 ;900 - 1700; RC5X CASE 130 TO 180 ;RC6 CodeRC6 = TRUE CASE ELSE ;None from the codes here-above? Then start measuring again GOTO Opnieuw END SELECT ;---------------------------- CommandOud_O = Command_O ;Save old values for repearing in case of a receive error SysteemOud_O = Systeem_O Command_O = 0 ;Clear first because RC5/RC5X doesn't overwrite bits 6 & 7, if RC6 earlier make those bits high, then they should stay high (=error) Systeem_O = 0 ;Clear first because RC5/RC5X doesn't overwrite bits 5,6,7, if RC6 earlier make those bits high, then they should stay high (=error) LED_Green = AAN ;An IR signal received IF CodeRC6 = TRUE THEN 'WHILE IR_Receiver = UIT :WEND ;00 Cancelled (by protocol examine) 'WHILE IR_Receiver = AAN :WEND ;1 Cancelled (by protocol examine) WHILE IR_Receiver = UIT :WEND ;00 WHILE IR_Receiver = AAN :WEND ;1 WHILE IR_Receiver = UIT :WEND ;0 WHILE IR_Receiver = AAN :WEND ;1 WHILE IR_Receiver = UIT :WEND ;0 DELAYUS 2000 ;Wait till the last '1' from the header comes (1778us), by this it come in the middle of the first toggle bit LED_Toggle = IR_Receiver WHILE LED_Toggle = IR_Receiver :WEND ;Wait till the inverted part from the togglebit comes DELAYUS 1100 ;1000 - 1200; By this it comes in the middle of the first system bit GOSUB BitOphalen : Systeem_O.7 = Value GOSUB BitOphalen : Systeem_O.6 = Value GOSUB BitOphalen : Systeem_O.5 = Value ELSE GOSUB BitOphalen : LED_Toggle = Value ENDIF GOSUB BitOphalen : Systeem_O.4 = Value GOSUB BitOphalen : Systeem_O.3 = Value GOSUB BitOphalen : Systeem_O.2 = Value GOSUB BitOphalen : Systeem_O.1 = Value GOSUB BitOphalen : Systeem_O.0 = Value IF CodeRC6 = TRUE THEN ;RC5 has no 6th and 7th bits GOSUB BitOphalen Command_O.7 = Value GOSUB BitOphalen Command_O.6 = Value ENDIF GOSUB BitOphalen Command_O.5 = Value GOSUB BitOphalen Command_O.4 = Value GOSUB BitOphalen Command_O.3 = Value GOSUB BitOphalen Command_O.2 = Value GOSUB BitOphalen Command_O.1 = Value GOSUB BitOphalen Command_O.0 = Value IF CodeRC5X = TRUE THEN Command_O.6 = 1 ;The 6th bit must in case of RC5X been set IF Systeem_O <> SysteemOud_O OR Command_O <> CommandOud_O OR CodeRC6 <> CodeRC6Oud OR UpdateLCD = FALSE THEN ;Without this line the LCD blinks when receiving IR signal (because of CLS) CLS IF CodeRC5X = TRUE THEN PRINT "RC5X" ELSEIF CodeRC6 = TRUE THEN PRINT "RC6" ELSE PRINT "RC5" ENDIF PRINT " Protocol" DELAYMS ProtocolLCD ;Time for indication RC5, RC5X or RC6 protocol IF CodeRC6 = TRUE THEN RC5_Mode = FALSE ELSE RC5_Mode = TRUE ENDIF Command = Command_O ;Give receive-Commandvalue to Command for display Systeem = Systeem_O ;Give receive-System value to System for display CLS GOSUB Display UpdateLCD = TRUE ;LCD is now up-to-date ; Systeem_Z = Systeem_O ;It's possible to send the received codeThe receivedDe ontvangen code with this device (PCB 110820)... Command_Z = Command_O ;...delete this block with code if you on't want this ToggBit_Z = ToggBit_O Plus = TRUE ;After receiving an IR code, the first time with adjusting system-address or command-code, the counter will count up IF CodeRC6 = TRUE THEN ;To send out the same code as the received code make variable RC5_Mode in the same protocol (RC5 or RC6) RC5_Mode = FALSE ELSE RC5_Mode = TRUE ENDIF ; ENDIF GOTO Opnieuw ErrorOntvangst: LED_Green = UIT LED_Red = AAN ;No RC5 code or no optimal receiving DELAYMS LED_Time Command_O = CommandOud_O ;Repair Command and Systeem Systeem_O = SysteemOud_O GOTO Opnieuw Start: ;If 'ADJUST' and 'SEND' are pushed both, then restart again CLS PRINT "Restart" WHILE Adjust = AAN OR Send = AAN: WEND ;Wait till both buttons are released GOTO ReStart ;ASSEMBLER ROUTINES RC5_Code: ASM ;Send a complete RC5 code call TxEenRC5 ;Header btfss Command_Z,6 ;Inverted command bit call TxEenRC5 btfsc Command_Z,6 call TxNulRC5 ;Togglebit btfsc ToggBit_Z call TxEenRC5 btfss ToggBit_Z call TxNulRC5 ;Systembit (A4,3,2,1,0)Address btfsc Systeem_Z,4 call TxEenRC5 btfss Systeem_Z,4 call TxNulRC5 btfsc Systeem_Z,3 call TxEenRC5 btfss Systeem_Z,3 call TxNulRC5 btfsc Systeem_Z,2 call TxEenRC5 btfss Systeem_Z,2 call TxNulRC5 btfsc Systeem_Z,1 call TxEenRC5 btfss Systeem_Z,1 call TxNulRC5 btfsc Systeem_Z,0 call TxEenRC5 btfss Systeem_Z,0 call TxNulRC5 ;Commandbit (D5,4,3,2,1,0) Data btfsc Command_Z,5 call TxEenRC5 btfss Command_Z,5 call TxNulRC5 btfsc Command_Z,4 call TxEenRC5 btfss Command_Z,4 call TxNulRC5 btfsc Command_Z,3 call TxEenRC5 btfss Command_Z,3 call TxNulRC5 btfsc Command_Z,2 call TxEenRC5 btfss Command_Z,2 call TxNulRC5 btfsc Command_Z,1 call TxEenRC5 btfss Command_Z,1 call TxNulRC5 btfsc Command_Z,0 call TxEenRC5 btfss Command_Z,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 255 ;For RC5 255 timecyclusses (by Xtal:10MHz) IR-LED off movwf Cycl_2 LichtUit2RC5 nop ;Short delay's nop nop nop nop nop decfsz Cycl_2,f goto LichtUit2RC5 return ;IR-LED on (pulsing) LichtAanRC5 movlw 32 ;RC5 has 32 fast IR-LED pulses for a '1' movwf Cycl_1 ;32 Cyclusses from a pause and a pulse LichtAan1RC5 ;Pause nop movlw 15 ;Time for (by Xtal:10MHz) pause between IR-LED blink movwf Cycl_2 LichtAan2RC5 decfsz Cycl_2,f goto LichtAan2RC5 ;Pulse bsf IrOut ;IR-LED on movlw 5 ;Time for (by 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 RC6_Code: ASM ;Send a complete RC6 code ;Startbits (Header) call LichtAan call LichtAan call LichtAan call LichtAan call LichtAan call LichtAan call LichtUit call LichtUit call TxEen call TxNul call TxNul call TxNul ;Togglebits btfss ToggBit_Z ;Togglebit by turns 1100 and 0011 call LichtAan btfss ToggBit_Z call LichtAan call LichtUit call LichtUit btfsc ToggBit_Z call LichtAan btfsc ToggBit_Z call LichtAan ;Systembyte (A7,6,5,4,3,2,1,0) Address btfsc Systeem_Z,7 call TxEen btfss Systeem_Z,7 call TxNul btfsc Systeem_Z,6 call TxEen btfss Systeem_Z,6 call TxNul btfsc Systeem_Z,5 call TxEen btfss Systeem_Z,5 call TxNul btfsc Systeem_Z,4 call TxEen btfss Systeem_Z,4 call TxNul btfsc Systeem_Z,3 call TxEen btfss Systeem_Z,3 call TxNul btfsc Systeem_Z,2 call TxEen btfss Systeem_Z,2 call TxNul btfsc Systeem_Z,1 call TxEen btfss Systeem_Z,1 call TxNul btfsc Systeem_Z,0 call TxEen btfss Systeem_Z,0 call TxNul ;Commandbyte (D7,6,5,4,3,2,1,0) Data btfsc Command_Z,7 call TxEen btfss Command_Z,7 call TxNul btfsc Command_Z,6 call TxEen btfss Command_Z,6 call TxNul btfsc Command_Z,5 call TxEen btfss Command_Z,5 call TxNul btfsc Command_Z,4 call TxEen btfss Command_Z,4 call TxNul btfsc Command_Z,3 call TxEen btfss Command_Z,3 call TxNul btfsc Command_Z,2 call TxEen btfss Command_Z,2 call TxNul btfsc Command_Z,1 call TxEen btfss Command_Z,1 call TxNul btfsc Command_Z,0 call TxEen btfss Command_Z,0 call TxNul return ;Send a 0 (off-on) (RC6 = reversed to RC5) TxNul call LichtUit call LichtAan return ;Send a 1 (on-off) (RC6 = reversed to RC5) TxEen call LichtAan call LichtUit return ;IR-LED off LichtUit movlw 225 ;For RC6 225 timecyclusses (by Xtal:10MHz) IR-LED off movwf Cycl_2 LichtUit2 nop nop decfsz Cycl_2,f goto LichtUit2 return ;IR-LED on (pulsing) LichtAan movlw 16 ;RC6 gives 16 fast IR-LED pulses for a '1' movwf Cycl_1 ;16 Cyclusses from a pause and a pulse LichtAan1 ;Pause nop movlw 15 ;Time for (Xtal:10MHz) pause between IR-LED blink movwf Cycl_2 LichtAan2 decfsz Cycl_2,f goto LichtAan2 ;Puls bsf IrOut ;IR-LED aan movlw 5 ;Time voor (Xtal:10MHz) IR-LED blink movwf Cycl_2 LichtAan3 decfsz Cycl_2,f goto LichtAan3 bcf IrOut ;IR-LED off decfsz Cycl_1,f goto LichtAan1 return ENDASM ;V4: RC5 command binary display fixed (7 bits instead of 6 bits)