.include	"8535def.inc"
.def	tmp1=r16
.def	tmp2=r17
.equ	mosi=5
.equ	miso=6
.equ	sck=7
.equ	ss=4
.dseg
	.org	$60
disp_buf:	.byte 2
byte_pos:	.byte 1
.cseg
	.org  0
	rjmp	init
;******* *******
init:
; ***** Other initializtion
init_spi:
	sbi	portb,mosi	;mosi is output pin
	sbi	portb,sck	;sck is output pin
	ldi 	tmp1,0b01010011	;SPI-enable, MASTER mode, SCK=f/128
	out	spcr,tmp1
	sbi	ddrb,ss		;LD is output pin
	clr	tmp1
	sts	byte_pos,tmp1	;first digit
main:

;*** Other routines 
	rcall	Display
;******
	rjmp	main

Display:
;***First check if SPI is free *******
	in	tmp1,spsr
	sbrs	tmp1,spif
	ret		;*** return if not redy
	lds	tmp1,byte_pos
	cpi	tmp1,2
	brlo	disp1
	sbi	portb,ss
	clr	tmp1
	cbi	portb,ss
disp1:
	ldi	xl,low(disp_buf)
	ldi	xh,high(disp_buf)
	clr	tmp2
	add	xl,tmp2
	adc	xh,tmp2
	ld	tmp2,x
	out	spdr,tmp2
	inc	tmp1
	sts	byte_pos,tmp1
	ret
