;********************************************************;
;                4 vezetékes kábel teszter               ;
; Kimenetek: RB7-RB4 470 ohm-on keresztül                ;
; Bemenetek: RB3-RB0                                     ;
; HIBA Led: RA0                                          ;
; OK Led: RA1                                            ;
; Nyomógomb: RA2                                         ;
;********************************************************;

	list p=16f628  ; pic típusa
	#include   <p16f628.inc>  ;pic definíció
	__config	3F1C
	CBLOCK 20h	;timer definíció
	timera
	timerb
	endc

	org	0


	movlw	0x07
	movwf	CMCON
	bsf	STATUS,RP0
	movlw	B'00000000'
	movwf	TRISA
	movwf	TRISB	
	bcf	STATUS,	RP0
	movlw	B'00000000'
	movwf	PORTB
	movwf	PORTA	;minden pin kimenet lesz 0 szinttel

gomb:	bsf	STATUS,RP0
	movlw	b'00000100'
	movwf	TRISA
	bcf	STATUS,	RP0
be:	btfss	PORTA,2	;gombteszt
	goto	elso
	nop
	nop
	nop
	nop
	goto	be

elso:	bsf	STATUS,RP0
	movlw	b'11111110'
	movwf	TRISB
	bcf	STATUS,RP0
	bsf	PORTB,0	;RB0--->1
	btfsc	PORTB,1	;RB1=0?
	goto	hiba
	btfsc	PORTB,2	;RB2=0?
	goto	hiba
	btfsc	PORTB,3	;RB3=0?
	goto	hiba
	btfss	PORTB,4	;RB4=1?
	goto	hiba
	btfsc	PORTB,5	;RB5=0?
	goto	hiba
	btfsc	PORTB,6	;RB6=0?
	goto	hiba
	btfsc	PORTB,7	;RB7=0?
	goto	hiba

masodik:	bsf	STATUS,RP0
	movlw	b'11111101'
	movwf	TRISB
	bcf	STATUS,RP0
	bsf	PORTB,1	;RB1--->1
	btfsc	PORTB,0	;RB0=0?
	goto	hiba
	btfsc	PORTB,2	;RB2=0?
	goto	hiba
	btfsc	PORTB,3	;RB3=0?
	goto	hiba
	btfsc	PORTB,4	;RB4=0?
	goto	hiba
	btfss	PORTB,5	;RB5=1?
	goto	hiba
	btfsc	PORTB,6	;RB6=0?
	goto	hiba
	btfsc	PORTB,7	;RB7=0?
	goto	hiba

harmadik:	bsf	STATUS,RP0
	movlw	b'11111011'
	movwf	TRISB
	bcf	STATUS,RP0
	bsf	PORTB,2	;RB2--->1
	btfsc	PORTB,0	;RB0=0?
	goto	hiba
	btfsc	PORTB,1	;RB2=0?
	goto	hiba
	btfsc	PORTB,3	;RB3=0?
	goto	hiba
	btfsc	PORTB,4	;RB4=0?
	goto	hiba
	btfsc	PORTB,5	;RB5=0?
	goto	hiba
	btfss	PORTB,6	;RB6=1?
	goto	hiba
	btfsc	PORTB,7	;RB7=0?
	goto	hiba

negyedik:	bsf	STATUS,RP0
	movlw	b'11110111'
	movwf	TRISB
	bcf	STATUS,RP0
	bsf	PORTB,3	;RB3--->1
	btfsc	PORTB,0	;RB0=0?
	goto	hiba
	btfsc	PORTB,1	;RB1=0?
	goto	hiba
	btfsc	PORTB,2	;RB2=0?
	goto	hiba
	btfsc	PORTB,4	;RB4=0?
	goto	hiba
	btfsc	PORTB,5	;RB5=0?
	goto	hiba
	btfsc	PORTB,6	;RB6=0?
	goto	hiba
	btfss	PORTB,7	;RB7=1?
	goto	hiba
	goto	jo


delay1:	movlw	d'100'
	movwf	timera
DEL1:	decfsz	timera,f
	goto	DEL1
	return	

delay2:	movlw	d'200'
	movwf	timerb
DEL2:	decfsz	timerb,f
	goto	DEL2
	return
	
hiba:	bsf	PORTA,1
	call	delay1
	goto	gomb

jo:	bsf	PORTA,2
	call	delay2
	goto	gomb

	end
