Please help support the site by donating at the link below.https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=8ZRU34U47BESW
10K,100ohm, 330 ohm, 470 ohm resistors I recommend the 500 pack http://www.radioshack.com/product/index.jsp?productId=2062306
**Long Pause**........Yup, thats better than balloons
thank you for the clarification.I just realized that 170 ohm resistor doesnt exist, I think it goes form 150, 160, 180 ohms, Dont know why. either way is not that important as is only the LED brightness. Do you think the person in who revised the diagram simply forgot to change the color purple to black?Dont mean to be extremely picky, just trying to clarify any confusion.thanks
list p=12F683 ; list directive to define processor #include <p12F683.inc> ; processor specific variable definitions errorlevel -302 ; suppress message 302 from list file __CONFIG _FCMEN_OFF & _IESO_OFF & _CP_OFF & _CPD_OFF & _BOD_OFF & _MCLRE_OFF & _WDT_OFF & _PWRTE_ON & _INTOSCIO ;***** VARIABLE DEFINITIONS******************w_temp EQU 0x70 ; variable used for context saving status_temp EQU 0x71 ; variable used for context saving;********************************************************************** ORG 0x000 ; processor reset vector goto Main ; go to beginning of program ORG 0x004 ; interrupt vector location movwf w_temp ; save off current W register contents movf STATUS,w ; move status register into W register movwf status_temp ; save off contents of STATUS register movf status_temp,w ; retrieve copy of STATUS register movwf STATUS ; restore pre-isr STATUS register contents swapf w_temp,f swapf w_temp,w ; restore pre-isr W register contents retfie ; return from interrupt;*************************************SUBROUTINES**********************************;**********************************************************************************;**********************************************************************************;**********************************************************************************Main; initialize eeprom locations ORG 0x2100 DE 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 END ; directive 'end of program'
;**********************************************************************************;**********************************************************************************;**********************************************************************************main bcf STATUS, RP0 ;bank 0 movlw 0x01 movwf T2CON ;timer 2, prescale 1:4, no postscale bsf STATUS, RP0 ;bank 1 movlw 0xFA movwf PR2 ;setup 1ms hardware interrupt bsf PIE1, TMR2IE ;enable timer2 interupt bcf STATUS, RP0 ;bank 0 bsf T2CON, TMR2ON ;turn on timer2 movlw 0xC0 movwf INTCON ;turn on interrupts globally
;**********************************************************************************;**********************************************************************************;**********************************************************************************main clrf GPIO movlw 0x07 movwf CMCON0 ;comparators off bsf STATUS, RP0 ;bank 1 movlw 0x1C movwf TRISIO ;pin 0 & 1 & 5 out, all other inputs clrf ANSEL ;all digital pins movlw 0x14 movwf WPU ;enable week pullups bcf OPTION_REG, 7 ;enable all week pullups bcf STATUS, RP0 ;bank 0 movlw 0x01 movwf T2CON ;timer 2, prescale 1:4, no postscale bsf STATUS, RP0 ;bank 1 movlw 0xFA movwf PR2 ;setup 1ms hardware interrupt bsf PIE1, TMR2IE ;enable timer2 interupt bcf STATUS, RP0 ;bank 0 bsf T2CON, TMR2ON ;turn on timer2 movlw 0xC0 movwf INTCON ;turn on interrupts globally ;******MAIN LOOP***************Start goto Start
;***** VARIABLE DEFINITIONS******************w_temp EQU 0x70 ; variable used for context saving status_temp EQU 0x71 ; variable used for context savingFLAGS EQU 0x20 ;software state registerPULSER EQU 0x21 ;pulse on counterDWELLTIMER EQU 0x22 ;pulse off counterFREQR EQU 0x25 ;frequency value
;*******bits in FLAGS register***********PULSEONR equ 0;*********GPIO pin names*****************TRIGGERR equ 0TRIGGERL equ 1;********************************************************************** ORG 0x000 ; processor reset vector goto main ; go to beginning of program ORG 0x004 ; interrupt vector location movwf w_temp ; save off current W register contents movf STATUS,w ; move status register into W register movwf status_temp ; save off contents of STATUS register btfss PIR1, TMR2IF ;timer 2 int happened retfie;**************** Right trigger logic*************************************** RightTrigger bcf GPIO, TRIGGERR btfss FLAGS, PULSEONR ;is pulse active? goto OffstateR decfsz PULSER, f ;if pulse is active, count down 10ms goto EndInterupt bcf FLAGS, PULSEONR ;10ms is over, clear flags and output bsf STATUS, RP0 ;bank 1 bsf TRISIO, TRIGGERR ;and reset pulse time. bcf STATUS, RP0 ;bank 0 movf FREQR, w movwf PULSER goto EndInteruptOffstateR decfsz DWELLTIMER, f ;count down dwell time to next pulse goto EndInterupt bsf FLAGS, PULSEONR ;if dwell is done turn on outputs bsf STATUS, RP0 ;bank 1 bcf TRISIO, TRIGGERR ;and reset pulse time bcf STATUS, RP0 ;bank 0 movf FREQR, w ;from frequency value movwf DWELLTIMEREndInterupt bcf PIR1, TMR2IF movf status_temp,w ; retrieve copy of STATUS register movwf STATUS ; restore pre-isr STATUS register contents swapf w_temp,f swapf w_temp,w ; restore pre-isr W register contents retfie ; return from interrupt
;******MAIN LOOP***************Start btfsc GPIO, PROGSTATE goto Start ;wait for the fun to begin call Wait10ms btfsc GPIO, PROGSTATE ;button is down for 10ms goto StartRelease btfss GPIO, PROGSTATE ;wait for button release goto Release call Wait10ms btfss GPIO, PROGSTATE ;wait for button release goto Release
call Wait10ms btfss GPIO, PROGSTATE ;wait for button release goto Release movlw 0x40 addwf STATER, f ;cyclic change in state manipulates ;last 2 bits in STATER. movf STATER, w call WriteEE ;store state
movlw 0x40 addwf STATER, f ;cyclic change in state manipulates ;last 2 bits in STATER. movf STATER, w call WriteEE ;store state btfsc STATER, 7 ;state 1 or 2 goto Continue01 btfsc STATER, 6 goto State2 movlw FIRERATE1 ;state 1, off movwf FREQR goto StartState2 movlw FIRERATE1 ;state 2, 42ms cycle movwf FREQR goto StartContinue01 btfsc STATER, 6 goto State4 movlw FIRERATE2 ;state 3, 30 ms cycle movwf FREQR goto StartState4 movlw FIRERATE3 ;state 4, 22ms cycle movwf FREQR goto Start ;store state
RightTrigger movf STATER, f ;this will trigger the zero flag btfss STATUS, Z ;if STATER is zero, output is off. goto ActiveR bsf STATUS, RP0 ;bank 1 bsf TRISIO, TRIGGERR bsf TRISIO, TRIGGERL bcf STATUS, RP0 ;bank 0 goto EndInteruptActiveR
btfsc GPIO, CONTROLTYPE ;if pin 4 is pulled lo bsf FLAGS, TRIGOUT ;leave output lo
ActiveR btfss FLAGS, TRIGOUT bcf GPIO, TRIGGERR btfsc FLAGS, TRIGOUT bsf GPIO, TRIGGERR
ActiveL movlw 0x40 subwf STATER, w ;test if state 1 btfsc STATUS, Z goto Continue02 bsf STATUS, RP0 ;bank 1 bsf TRISIO, TRIGGERL bcf STATUS, RP0 ;bank 0 goto EndInterupt Continue02 btfss FLAGS, TRIGOUT bcf GPIO, TRIGGERL btfsc FLAGS, TRIGOUT bsf GPIO, TRIGGERL btfss FLAGS, PULSEONL ;is pulse active? goto OffstateL decfsz PULSEL, f ;if pulse is active, count down 10ms goto EndInterupt bcf FLAGS, PULSEONL ;10ms is over, clear flags and output bsf STATUS, RP0 ;bank 1 bsf TRISIO, TRIGGERL ;and reset pulse time bcf STATUS, RP0 ;bank 0 movf FREQR, w movwf PULSEL goto EndInteruptOffstateL decfsz DWELLTIMEL, f ;count down dwell time to next pulse goto EndInterupt bsf FLAGS, PULSEONL ;if dwell is done turn on outputs bsf STATUS, RP0 ;bank 1 bcf TRISIO, TRIGGERL ;and reset pulse time bcf STATUS, RP0 ;bank 0 movf FREQR, w ;from frequency value movwf DWELLTIMEL
;**************** LED blinking ********************************************* ;Our main routine will turn the flag bit ;LEDON on or off. The 10ms pulse is a duty cycle ;for the code to work with both CG and ;matrix controllers. btfsc FLAGS, LEDON ;LED off goto BlinkLed bsf STATUS, RP0 ;bank 1 bsf TRISIO, LEDR ;tristate LED bcf STATUS, RP0 ;bank 0 goto RightTrigger BlinkLed bsf STATUS, RP0 ;bank 1 bcf TRISIO, LEDR ;turn output on bcf STATUS, RP0 ;bank 0 btfss GPIO, LEDR goto LedLow decfsz LEDBLINK, f ;if pulse is active, count down 10ms goto RightTrigger bcf GPIO, LEDR movlw 0x0A movwf LEDBLINKLedLow decfsz LEDBLINK, f ;if pulse is active, count down 10ms goto RightTrigger bsf GPIO, LEDR movlw 0x0A movwf LEDBLINK
;******MAIN LOOP***************Start btfsc GPIO, PROGSTATE goto Start ;wait for the fun to begin call Wait10ms btfsc GPIO, PROGSTATE ;button is down for 10ms goto StartRelease btfss GPIO, PROGSTATE ;wait for button release goto Release call Wait10ms btfss GPIO, PROGSTATE ;wait for button release goto Release movlw 0x40 addwf STATER, f ;cyclic change in state manipulates ;last 2 bits in STATER. movf STATER, w call WriteEE ;store state btfsc STATER, 7 ;state 1 or 2 goto Continue01 btfsc STATER, 6 goto State2 movlw FIRERATE1 ;state 1, off movwf FREQR bcf FLAGS, LEDON ;turn off LED goto StartState2 movlw FIRERATE1 ;state 2, 42ms cycle movwf FREQR bsf FLAGS, LEDON ;turn on LED goto StartContinue01 btfsc STATER, 6 goto State4 movlw FIRERATE2 ;state 3, 30 ms cycle movwf FREQR bcf FLAGS, LEDON ;turn off LED 1/2 sec movlw 0x0A movwf TEMP3Loop01 call Wait10ms decfsz TEMP3, f goto Loop01 bsf FLAGS, LEDON ;turn on LED 1/2 sec movlw 0x0A movwf TEMP3Loop02 call Wait10ms decfsz TEMP3, f goto Loop02 bcf FLAGS, LEDON ;turn off LED 1/2 sec movlw 0x0A movwf TEMP3Loop04 call Wait10ms decfsz TEMP3, f goto Loop04 bsf FLAGS, LEDON ;turn on LED goto StartState4 movlw FIRERATE3 ;state 4, 22ms cycle movwf FREQR bcf FLAGS, LEDON ;turn off LED 1/2 sec movlw 0x0A movwf TEMP3Loop05 call Wait10ms decfsz TEMP3, f goto Loop05 bsf FLAGS, LEDON ;turn on LED 1/2 sec movlw 0x0A movwf TEMP3Loop06 call Wait10ms decfsz TEMP3, f goto Loop06 bcf FLAGS, LEDON ;turn off LED 1/2 sec movlw 0x0A movwf TEMP3Loop07 call Wait10ms decfsz TEMP3, f goto Loop07 bsf FLAGS, LEDON ;turn on LED 1/2 sec movlw 0x0A movwf TEMP3Loop08 call Wait10ms decfsz TEMP3, f goto Loop08 bcf FLAGS, LEDON ;turn off LED 1/2 sec movlw 0x0A movwf TEMP3Loop09 call Wait10ms decfsz TEMP3, f goto Loop09 bsf FLAGS, LEDON ;turn on LED goto Start
movlw 0x0A ;start with 10ms pulse width movwf LEDBLINK movlw FIRERATE3 ;40ms dwell for 50ms freq movwf PULSER movwf PULSEL movwf DWELLTIMER movwf DWELLTIMEL btfsc GPIO, CONTROLTYPE ;if pin 4 is pulled lo bsf FLAGS, TRIGOUT ;leave output lo call ReadEE ;get state value movwf STATER movf STATER, f btfss STATUS, Z bsf FLAGS, LEDON ;get LED status ;******MAIN LOOP***************Start
;*************************************SUBROUTINES**********************************Wait10ms clrf TEMP2 movlw 0x0D movwf TEMP1 ;rough 10ms timer for button debounce.Loop1 decfsz TEMP2, f ;count down 256*3=768 cycles goto Loop1 decfsz TEMP1, f ;count down 768*13=9986 cycles goto Loop1 return ;*************************************************************ReadEE bsf STATUS , RP0 ;Bank1 movlw 0x04 movwf EEADR bsf EECON1 , RD ;start read movf EEDAT , W bcf STATUS , RP0 ;Bank0 return ;*************************************************************WriteEE bsf STATUS , RP0 movwf EEDAT movlw 0x04 movwf EEADR bsf EECON1,WREN ;Enable write bcf INTCON, GIE ;Disable INTs btfsc INTCON, GIE ;See AN576 goto $-2 movlw 0x55 ;Unlock write movwf EECON2 movlw 0xAA movwf EECON2 bsf EECON1, WR ;Start the writeWaitForEEWrite btfsc EECON1, WR ;wait for hardware to clear (done writing) goto WaitForEEWrite bcf STATUS , RP0 ;Bank0 bsf INTCON, GIE ;Enable INTS return
14) scroll down to the part of the fire rates, it will look like this:;**********Speed settings: change these to change speed (0x05-0xFF)FIRERATE1 equ 0x3CFIRERATE2 equ 0x16FIRERATE3 equ 0x12FIRERATE4 equ 0x0F