processor 16f84a ;define the chip we are using to the assembler
include <p16f84a.inc> ;and include its file
__config _RC_OSC & _WDT_OFF & _PWRTE_ON ; set the config for the pic
;we are using RC circuit and power time is on while watchdog timer is off
i equ H'10' ;defining some variables to be used in the code
j equ H'11' ;i and j with place in memory "10H"and"11H'
org 0
;start running from address 0
movlw B'11111111' ; intialize port A as input bins
tris PORTA
movlw B'00000000' ;intialize port B as output port
tris PORTB
mainloop: ;the main branch in the code
btfsS PORTA,0 ;skip the next line if pin 0 in porta is set(1)
goto onloop
goto offloop
onloop:
bsf PORTB,2
bsf PORTB,0 ;set pin 0 in port b
bcf PORTB,1 ;clear pin1 in port b
call delay ;call subroutine "delay" (it will start from here after finishing delay subroutine)
bcf PORTB,0
bsf PORTB,1
call delay
goto mainloop ; goto the begining of the loop to startover
offloop:
bcf PORTB,2
bcf PORTB,0
bcf PORTB,1
goto mainloop
delay: ;delay subroutine used to waste some time in executing empty loop
movlw d'5' ;copy 5 in work register
movwf i ;copy what in work register into variables i & j
movwf j
delayloop:
decfsz i,f ;decrease value of variable i by 1 and if value of i =0 skip next line
goto delayloop
decfsz j,f
goto delayloop
return ;return to the address of the call inst
end
i equ H'10' ;defining some variables to be used in the code
j equ H'11' ;i and j with place in memory "10H"and"11H'
mainloop: ;the main branch in the code
btfsS PORTA,0 ;skip the next line if pin 0 in porta is set(1)
goto onloop
goto offloop
onloop:
bsf PORTB,2
bsf PORTB,0 ;set pin 0 in port b
bcf PORTB,1 ;clear pin1 in port b
call delay ;call subroutine "delay" (it will start from here after finishing delay subroutine)
bcf PORTB,0
bsf PORTB,1
call delay
goto mainloop ; goto the begining of the loop to startover
offloop:
bcf PORTB,2
bcf PORTB,0
bcf PORTB,1
goto mainloop
delay: ;delay subroutine used to waste some time in executing empty loop
movlw d'5' ;copy 5 in work register
movwf i ;copy what in work register into variables i & j
movwf j
delayloop:
decfsz i,f ;decrease value of variable i by 1 and if value of i =0 skip next line
goto delayloop
decfsz j,f
goto delayloop
return ;return to the address of the call inst
end