	list		p=16f877a
	#include	<p16f877a.inc>
;	__CONFIG	_CP_OFF & _WDT_OFF & _PWRTE_ON & _XT_OSC
	
; дeфиниране на константи
;w		EQU	0
;f		EQU	1
speed		EQU	D'10'

counter		EQU	0x25
shift_counter 	EQU 	H'26'
W_temp		EQU	H'27'
STATUS_temp	EQU	H'28'
flag_reg	EQU H'29'
	
; потребителска програма
		org	H'0000'
		goto	start
	
		org	H'0004'
		goto 	int_service
	
; начало на програмата
start	
		bcf	STATUS,RP1
		bsf	STATUS,RP0
		movlw	B'10010111'
		movwf	OPTION_REG
		bcf	STATUS,RP0
		clrf	PORTB
		bsf	STATUS,RP0
		clrf	TRISB
		bcf	STATUS,RP0
		clrf	TMR0
		movlw	B'10100000'
		movwf	INTCON
		clrf	flag_reg
		movlw	speed
		movwf	counter
		goto	main
		
; подпрограма за обслужване на прекъсването
int_service	
		movwf	W_temp
		swapf	STATUS,w
		movwf	STATUS_temp
		btfss	INTCON,T0IF
		goto	end_int
TMR0_int
		decfsz	counter,f
		goto	end_int
		bsf	flag_reg,0
		movlw	speed
		movwf	counter
end_int
		bcf	INTCON,T0IF
		swapf	STATUS_temp,w
		movwf	STATUS
		swapf	W_temp,f
		swapf	W_temp,w
		retfie
		
; главна програма
main
		movlw	D'8'
		movwf	shift_counter
		movlw	B'00000001'
		movwf	PORTB
		bcf	STATUS,C
loop1
		btfss	flag_reg,0
		goto	loop1
		rlf	PORTB,f
		bcf	flag_reg,0
		decfsz	shift_counter
		goto	loop1
		goto	main
		end
		

	