title Infra-Red VCR control routines for 3100 project. ; ; Link between 4-bit data bus on RA0:3, strobe on RA4 and IR LED / Relay ; control of VCR. Mains control is on RB0 with 1 = On, 0 = Off. ; Emulation of Remote Control unit with LED on RB1 (1 = On, 0 = Off). ; ;The DV80B uses an infra-red control link with a pulse carrier at 38KHz. ;The preamble is 8mS ON followed by 4ms OFF. ;Data is 32 bits long, sent LSB first. The device code is sent first with ;normal polarity then is sent with all bits inverted. Then the function code is sent ;with normal then inverted polarity. ;A "0" is sent as 600uS ON, 400us OFF. ;A "1" is sent as 600uS ON, 1200us (1.2mS) OFF. ; ; ------------------------------------------------------------------- ; Revision History: ; 31-07-2003 Original version to discover DV80B IR operation. ; 29-02-2004 Commands remapped to match repeater project and timing ; routines adjusted for 3.6864MHz clock instead of 4MHz. ; 15-03-2004 Added command '0A' to automatically start the VCR. The ; sequence is 'power off, wait, power on, wait, standby'. ; 22-03-2004 Added wait and rewind to command 0A. ; 10-04-2004 Added channel step down to initialise sequence ; 13-04-2004 Increased AGC pulse and end pulse lengths. Removed step ; down command from startup, code for this now in SAP. ;-------------------------------------------------------------------- __CONFIG _CP_OFF & _PWRTE_ON & _WDT_ON & _XT_OSC #include #define page_0 bcf STATUS,5 ;switch to page 0 #define page_1 bsf STATUS,5 ;switch to page 1 cblock H'10' seq_ptr ;address of sequence data byte bitcount ;number of times seq has been shifted device_1 ;shift register bits 7:0 device_2 ;shift register bits 15:8 function_1 ;shift register bits 23:16 function_2 ;shift register bits 31:24 delay1 ;counters to set pulse timing delay2 end_delay ;delay before re-trigger allowed init_delay ;long delay for VCR init. endc ; defines specific to the Toshiba DV80B VCR device_code equ 44H stop_cmd equ 14H play_cmd equ 15H rew_cmd equ 19H ff_cmd equ 13H rec_cmd equ 18H pause_cmd equ 10H freeze_cmd equ 50H down_cmd equ 1FH up_cmd equ 1EH stby_cmd equ 12H ;************************************************************************* org 0 ;reset address in 16F84 reset goto init org 4 interrupt retfie ;========================================================== init clrf bitcount clrf STATUS clrf PORTA clrf PORTB clrf TMR0 clrw page_1 clrf TRISB ;all port B pins are outputs movlw H'1F' ;set port A pins to input mode movwf TRISA movlw B'10000011' ;no pull-ups, prescale by 16 movwf OPTION_REG page_0 clrf INTCON ;no interrupts allowed ; wait for a start signal (low on RA4) idle clrwdt ;reset watchdog while idle btfsc PORTA,4 ;monitor for start signal goto idle movf PORTA,w ;retrieve the bus data call send_ir ;send the IR flash sequence goto idle ;ready for next command ; table of incoming commands send_ir addwf PCL,f goto flash ;0 = command goto flash ;1 = command goto flash ;2 = command goto flash ;3 = command goto idlecheck ;4 = not used goto flash ;5 = command goto idlecheck ;6 = not used goto flash ;7 = command goto idlecheck ;8 = not used goto flash ;9 = command goto start_up ;A = auto start control goto flash ;B = command goto flash ;C = command goto flash ;D = command goto power_on ;E = control function goto power_off ;F = control function ;set up the shift registers flash call IR_flash_table ;find the flash bit sequences flash_2 movwf function_1 ;load function code (+ pol) movlw device_code ;load device code (+ pol) movwf device_1 comf device_1,w ;load device code (- pol) movwf device_2 comf function_1,w ;load function code (- pol) movwf function_2 ;start the flash sequence clrwdt movlw .32 ;number of shifts movwf bitcount bsf PORTB,1 ;send AGC pulse call delay_9ms bcf PORTB,1 call delay_4ms bsf PORTB,2 ;scope trigger bcf PORTB,2 loop clrwdt bsf PORTB,1 ;on at start of bit period call delay_600us bcf STATUS,C rrf function_2,f rrf function_1,f rrf device_2,f rrf device_1,f ;lsb shifts into carry bit btfss STATUS,C ;skip if "1" goto zerobit ;send a "1" bcf PORTB,1 ;start of long off period call delay_1200us goto endcheck ;send a "0" zerobit bcf PORTB,1 ;start of short off period call delay_400us endcheck decfsz bitcount,f ;count down remaining shifts goto loop ;more to do bsf PORTB,1 ;final pulse to close last period call delay_600us bcf PORTB,1 movlw .11 ;loop 4ms delay 11 times movwf end_delay endwait call delay_4ms decfsz end_delay,f goto endwait clear_pulse ;send 9mS on,2mS off,600uS on bsf PORTB,1 ;on call delay_9ms ;9mS bcf PORTB,1 ;off call delay_2ms ;2mS bsf PORTB,1 ;on call delay_600us ;600uS bcf PORTB,1 ;off idlecheck btfsc PORTA,4 ;hold until trigger released return ;done clrwdt goto idlecheck ;delay routines delay_400us movlw H'E9' ;roll over after 23 counts movwf TMR0 goto wait delay_600us movlw H'DD' ;roll over after 35 counts movwf TMR0 goto wait delay_1200us movlw H'BB' ;roll over after 69 counts movwf TMR0 goto wait delay_2ms movlw H'8B' ;roll over after 139 counts movwf TMR0 goto wait delay_4ms movlw H'1A' ;roll over after 230 counts movwf TMR0 goto wait delay_9ms call delay_4ms call delay_4ms call delay_1200us return wait clrwdt movf TMR0,w btfss STATUS,Z goto wait return start_up bcf PORTB,0 ;turn power relay off call long_delay ;time for VCR to power down call long_delay bsf PORTB,0 ;turn power back on call long_delay ;time for VCR to initialise call long_delay movlw stby_cmd ;take VCR out of standby call flash_2 movlw long_delay movlw rew_cmd ;rewind the tape call flash_2 goto idle ;done long_delay clrf init_delay ;256 x 4mS = 1.024 seconds long_loop call delay_4ms decfsz init_delay,f goto long_loop return power_on bsf PORTB,0 ;turn power relay on goto idle power_off bcf PORTB,0 ;turn power relay off goto idle ; table of flash bit sequences IR_flash_table addwf PCL,f ;form offset into table retlw stop_cmd ;0 data for stop sequence retlw play_cmd ;1 data for play sequence retlw rew_cmd ;2 data for rewind sequence retlw ff_cmd ;3 data for f.forward sequence retlw H'00' ;4 spare retlw rec_cmd ;5 data for record sequence retlw H'00' ;6 spare retlw pause_cmd ;7 data for pause sequence retlw H'00' ;8 spare retlw freeze_cmd ;9 data for still picture sequence retlw H'00' ;A spare retlw up_cmd ;B data for channel+ sequence retlw down_cmd ;C data for channel- sequence retlw stby_cmd ;D data for standby sequence retlw H'00' ;E used for power control retlw H'00' ;F used for power control END