list p=10F206 ; list directive to define processor
#include <p10F206.inc> ; processor specific variable definitions
__CONFIG _MCLRE_OFF & _CP_OFF & _WDT_OFF & _IntRC_OSC
; '__CONFIG' directive is used to embed configuration word within .asm file.
; The lables following the directive are located in the respective .inc file.
; See respective data sheet for additional information on configuration word.
;**********************************************************************
ORG 0x1FF ; processor reset vector
; Internal RC calibration value is placed at location 0x1FF by Microchip
; as a movlw k, where the k is a literal value.
ORG 0x000 ; coding begins here
movwf OSCCAL ; update register with factory cal value
bcf CMCON0, CMPON
movlw b'00000000'
OPTION
cblock 0x08
Delay1
Delay2
Count
Count1
Shooter
SF1
SF2
endc
Start:
movlw b'1000'
TRIS GPIO
Main:
movlw d'5'
movwf Count1
Repeat:
movlw d'5' ; Loading the count block
movwf Count ; For how many times the LED will blink
decfsz Count1
goto MainLoop1
goto Shoot
MainLoop1:
decfsz Count,f ; Countdown starts for LED blinking
goto On1 ; Goto instruction for start of blinking
goto Repeat2 ; Goto for the second LED
On1:
movlw b'0001'
movwf GPIO ; turn on LED C0
movlw .010 ; setting the timing
movwf Delay2 ; for delay loop
OnDelayLoop1:
decfsz Delay1,f ; Wasting time.
goto OnDelayLoop1 ;
decfsz Delay2,f ;
goto OnDelayLoop1 ;
;
movlw b'0000'
movwf GPIO ; Turn off LED C0
movlw .150 ; Load timing for LED off loop
movwf Delay2
OffDelayLoop1:
decfsz Delay1,f ; same delay as above
goto OffDelayLoop1
decfsz Delay2,f
goto OffDelayLoop1
goto MainLoop1 ; Do it again...
Repeat2:
movlw d'5'
movwf Count
MainLoop2: ;This is the same instruction set as above except for it's the C1 LED
decfsz Count,f
goto On2
goto Repeat
On2:
movlw b'0010'
movwf GPIO
movlw .010
movwf Delay2
OnDelayLoop2:
decfsz Delay1,f
goto OnDelayLoop2
decfsz Delay2,f
goto OnDelayLoop2
movlw b'0000'
movwf GPIO
movlw .150
movwf Delay2
OffDelayLoop2:
decfsz Delay1,f
goto OffDelayLoop2
decfsz Delay2,f
goto OffDelayLoop2
goto MainLoop2
Shoot:
movlw d'10' ;Setting how many times IR LED will send signal
movwf Shooter
Burst:
decfsz Shooter, f
goto Burster
goto Receive
Burster:
movlw b'0100' ;Turning on IR LED
movwf GPIO
nop
nop
nop
nop
movlw b'0000' ;Turning IR LED off
movwf GPIO
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
goto Burst
Receive:
movlw d'2' ;added these comments long after program was written and in use
movwf SF1 ;I think I was playing around with giving the IR receiver time
movlw d'2' ;to recover before I checked for a signal
movwf SF2 ;so it wouldn't receive it's own signal
Stop: ;not sure it's necessary, but it works, so I left it
decfsz SF1, f
goto Stop
decfsz SF2, f
goto Stop
goto Check
Check:
btfsc GPIO, 3 ;checking for input
goto Shoot ;If no input, fire another burst on the IR LED
goto Main ;If there is, go blink the red LED's.
End