$TITLE (PLOTTER DRIVER ver. 1.0 [C] OLEO)
$DATE (MAJ 1990)
$PROCESSOR (8051)
$PAGEWIDTH (110)
$PAGELENGTH (65)
;$NOSYMBOLS
;$NOLIST
;$XREF

START_UP	CODE	0032H
TIMER0_INT	CODE	000BH
TIMER1_INT	CODE	001BH
SERIAL_INT	CODE	0023H


RST	BIT	P1.7	;L signal resetira L297 stepperja 1 in 2
CLKX	BIT	P1.6	;Rising edge clock za x os
CWX	BIT	P1.5	;Clock wise smer vrtenja za x os
HALFX	BIT	P1.4	;Polovicni korak x osi ce je H
CLKY	BIT	P1.3	;Glej CLK1 le za Y os
CWY	BIT	P1.2	; -||- Y os
HALFY	BIT	P1.1	; -||- Y os
XLIM	BIT	P1.0	;Opticno stikalo za X os (H=vozicek v mejni legi

x_bspd	equ	15	;zacetna hitrost x osi pri resetu
max_x_steps equ 33	;*100 najvecje stevilo korakov za x os


DSEG at 30h
x1:	ds 2
x2:	ds 2
y1:	ds 2
y2:	ds 2


CSEG AT RESET
	JMP START_UP

CSEG AT START_UP
	CLR  EA		;onemogoci prekinitve
	CALL ZAC_POL



ZAC_POL:	;(void) Nastavi x os v zacetni polozaj
	mov	P1, 0FFH
	clr	RST 	; restiram krmilnika 1 in 2
	setb	RST 
loop:	

	mov	R0,#x_bspd ;nastavimo zacetno hitrost vozicka
	setb	clkx	;in ga postavimo na zacetek
	call	delay100
	clr	clkx
	jnb	xlim,loop

	cpl	cwy

su0:	cpl	cwx
	cpl	cwy
	mov	r3,#max_x_steps
su1:	mov	r2,#100
su2:

	mov	R0,#x_bspd ;nastavimo zacetno hitrost vozicka
	setb	clkx
	setb	clky
	call	delay100
	clr	clkx
	clr 	clky
	djnz	r2,su2
	djnz	r3,su1		
	jmp	su0
	
  

;subw:	(stk+2&3=x1,stk+4&5=x2) odsteje dve int spremenljivki









	
	
DELAY100:  	;(R0),R1 - zakasni R0 krat 100us
	MOV 	R1,#49
	DJNZ	R1,$
	DJNZ	R0,DELAY100
	RET
	
  	
END