; ****************************************** ; RemoteEx-3.asm ; Infrared remote control repeater ; Pete Griffiths (C) 2004 ; http://picprojects.org.uk/projects/ ; ; Bug correction for 12F629 operation 07/11/2008 ; ..thanks to Pete Putnam for this fix. ; ; This code can be used with either the 12F675 or the 12F629 ; since it doesn't use any of the additional features in the 675 part ; ; This software generates a 39.5Khz or 38Khz carrier that is modulated on or off ; depending on the logic level on GPIO2. ; ; By connecting a device such as a TSOP2238 IR Receiver module to GPIO2 and driving an IR ; LED emitter from GPIO0 (GPIO1) a very low component count IR Remote Control Repeater ; can be realised. ; ; When GPIO2 goes low, the PIC wakes from sleep and executes a software ; loop that toggles pins GPIO0 and GPIO1 with a 15% duty cycle square wave ; at either ~39.5Khz or ~38Khz depending on the logic level on GPIO5 after ; reset. GPIO5 isn't sampled again during operation although you could tweak the code. ; ___ ___ ; GPIO0 Q __| |______________| |______________| ; __ ______________ ______________ ; GPIO1 ^Q |___| |___| | ; ; The software will always leave GPIO0 clear and GPIO1 set when GPIO2 goes high, ; Once GPIO2 goes high, the PIC enters a low power sleep state. A high to low ; transition on GPIO2 will wake the PIC and exectute the carrier loop ; ;************************************************************************ ; 12F629 / 675 * ; +---------+ * ; 1 | | 8 * ; 5.0 V ----+ +---- GND * ; 2 | | 7 * ; Frequency Sel GP5 ----+ +---- GP0 Q Output to IR LED * ; 3 | | 6 * ; GP4 ----+ +---- GP1 ^Q Output to IR LED * ; 4 | | 5 * ; GP3 ----+ +---- GP2 Input from IR Detector * ; +---------+ * ; * ;************************************************************************ ; ; ; -=*** If you are using a PIC 12F629 then you need substitute p12f629 for p12f675 in the line below #include "p12f675.inc" ;#include "p12f675.inc" __CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _INTRC_OSC_NOCLKOUT & _MCLRE_OFF & _CPD_OFF cblock 0x20 output frequency endc org 0x000 ; ****************************************** ; Startup initialisation _reset ;Initialise registers in Bank 1 bsf STATUS,RP0 ; Select Bank 1 call 0x3ff ; Get OSCAL value movwf OSCCAL ; write to OSCCAL register clrf ANSEL ; Set ports for digital mode movlw b'11111100' ; set up W to movwf TRISIO ; enable GPIO 0,1 for output movlw b'00010000' ; set up W to movwf INTCON ; enable edge interupts bcf OPTION_REG,NOT_GPPU ; enable global pull up bsf WPU,5 ; enable pull up on GPIO5 bsf WPU,2 ; enable pull up on GPIO2 bcf STATUS,RP0 ; Select Bank 0 movlw 0x07 ; Set up W to movwf CMCON ; turn off Comparator ports movlw 0x02 ; Set up W to movwf output ; Set initial state of output movwf GPIO ; and update physical output Q=0, ^Q=1 clrf ADCON0 ; turn off A/D convertor movf GPIO,W andlw b'00100000' ; mask in bit 5 bsf STATUS,RP0 ; select bank 1 bcf OPTION_REG,INTEDG ; Interupt on negative edge on GPIO 2 bcf STATUS,RP0 ; Select bank 0 ; GPIO5 = 0 carrier Fo ~39.5Khz ; GPIO5 = 1 carrier Fo ~38.0Khz clrf frequency ; Clear frequency flag FR btfsc GPIO,5 ; Test GPIO5 bsf frequency,0 ; If GPIO5 ==1 then set frequency flag FR _sleep movlw 0x02 movwf output movwf GPIO movfw GPIO bcf INTCON,INTF sleep btfsc frequency,0 ; Check Frequency flag goto _lo ; If 1 do 38Khz Lo ; else do 39.5Khz Hi _hi movlw 0x01 ;1 movwf GPIO ;1 Hi nop ;1 nop movlw 0x02 ;1 movwf GPIO ;1 Lo call _dummy ;4 call _dummy ;4 call _dummy ;4 nop ;1 nop ;1 nop ;1 movfw GPIO ;1 andlw 0x04 ;1 bz _hi ;3 goto _sleep _lo movlw 0x01 ;1 movwf GPIO ;1 nop ;1 nop movlw 0x02 ;1 movwf GPIO ;1 call _dummy ;4 call _dummy ;4 call _dummy ;4 call _dummy ;4 movfw GPIO ;1 andlw 0x04 ;1 bz _lo ;3 goto _sleep _dummy return dt "IR Remote Repeater. Pete Griffiths 2004" end