; ********************************************************* ; LED Strobe ; ; Pete Griffiths, June 2004 ; ; PIC generates a single or double output pulse at one of four ; user selectable repeat rates set by input on R0/R1 (pin 6/7). ; Pulse Width (PW) period is determined by the digital input applied ; GP4 (pin 3). ; Ouput is presented on GP2 (pin 5) and an inverted output is on GP5 (pin 2) ; Single / Double pulse is selected by digital input on GP3 (pin 4). Double pulse ; has a fixed 175mS gap between two pulses ; ; Output can drive any LED but for the best strobe effect use a High Brightness ; LED with suitable current limiting resistor. ; ; Pin functions for PIC 12F675 LED strobe ; Vdd -|1 8|- Vss ; ^Qout -|2 7|- R0 (internal weak pull-up enabled) ; PW -|3 6|- R1 (internal weak pull-up enabled) ; S/D -|4 5|- Qout ; ; R1 R0 Repeat rate ; 0 0 1S ; 0 1 2S ; 1 0 3S ; 1 1 4S ; ; SD ; 0 - Double pulse with 175mS gap ; 1 - Single pulse ; ; PW ; 0 => 30mS ; 1 => 100mS ; ; ; ; ********************************************************* ; #include "p12f675.inc" __CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _INTRC_OSC_NOCLKOUT & _MCLRE_OFF & _CPD_OFF cblock 0x20 input output dtime ltime off_time endc org 0x00 goto _main org 0x04 return ; *************************************** ; Start of the main code. Here the PIC ; peripherals and I/O are configured. ; It also gets the interbal OSC Calibration ; value and sets the OSCCAL register. ; _main bcf STATUS,RP0 ; Sel Bank 0 movlw 0x07 ; movwf CMCON ; Disable Comparator on GPIO pins movlw b'00001100' ; movwf ADCON0 ; Disable A/D bsf STATUS,RP0 ; Sel Bank 1 ; **************** ; Remove if factory setting at 0x3FF ; has been erased for any reason. ; See 12F675 manual P54 - Sec 9.2.5.1 call 0x3FF ; calls RETLW with factory setting movwf OSCCAL ; Set int OSC to factory calibrated ; **************** bcf OPTION_REG, NOT_GPPU movlw b'00010011' movwf WPU movlw b'01010000' ; Enable GP0,1,2,4 Digital movwf ANSEL ; Disable Analogue on GPIO pins movlw b'11011011' ; Specifiy GPIO port direction movwf TRISIO ; Set GPIO ports as xxOIIOII bcf STATUS,RP0 ; Sel Bank 0 movlw 0x20 ; Initialize output movwf GPIO ; port to Q=0, ^Q=1 movlw 0x05 ; 500mS delay to allow call _LDelay ; voltages to settle. ; ************************************** _strobe movf GPIO,W ; Get Digital inputs movwf input ; move to temporary working register movlw 0x04 ; Turn LED on (GP2 = 1 / GP5 =0) movwf GPIO movlw d'30' ; Pulse width 30mS btfsc input,4 ; Look at GPIO port 4 data movlw d'100' ; Pulse width 100mS call _Delay ; call LED on delay movlw 0x20 movwf GPIO ; Turn LED off (GP2 = 0 / GP5 = 1) btfsc GPIO,3 ; test GPIO bit 4 for double pulse goto _space ; skip if no double pulse required _dpulse movlw d'175' ; load W with delay of 175mS call _Delay movlw 0x04 ; Turn LED on (GP2 = 1 / GP5 = 0) movwf GPIO movlw d'30' ; Pulse width 30mS btfsc input,4 ; Look at GPIO port 4 data movlw d'100' ; Pulse width 100mS call _Delay movlw 0x20 movwf GPIO ; Turn LED off (GP2 = 0 / GP5 = 1) _space movf input,W andlw 0x03 call _off_time call _LDelay goto _strobe ; Program loops ; Computed goto table lookup ; ; W returns with delay value in 100mS intervals _off_time addwf PCL,F retlw d'10' ; 1S retlw d'20' ; 2S retlw d'30' ; 3S retlw d'40' ; 4S ; ******************************************** ; SUBROUTINE ; Delay loop _Delay movwf dtime ; Call for W x 1mS __Dcall call __1mS decfsz dtime,F goto __Dcall __DlyEnd return _LDelay movwf ltime ; Call for W x 100mS __Dlcall movlw d'100' call _Delay decfsz ltime,F goto __Dlcall return __1mS movlw 0xC6 _next nop addlw 0xFF btfss STATUS,Z goto _next nop nop nop return dt "Pete Griffiths 2004 - R040604.01" end