
	list      p=17c42             ; list directive to define processor
	#include <p17c42.inc>         ; processor specific variable definitions
        #include "pm_defs.inc"
	global blank_14x_routine
	extern read_it_6x
	code
blank_14x_routine:

start
	movlb	0
	bsf	IO
	movlw	0x90
	movwf	TBLPTRH			; point to the pin location
	clrf	TBLPTRL,1
	clrf	Addr,1			; start at zero
	clrf	Addr+1,1

blank_it:
	call	read_it_6x
	bsf	Yes_Cal

    btfsc   Has_Cal
    goto    check_cal_val

not_cal:
	movfp 	Blank_Val,WREG
	cpfseq	MI_Data
	bcf	Yes_blank
	movfp	Blank_Val+1,WREG
	cpfseq	MI_Data+1
	bcf	Yes_blank

    btfsc   ok_2_incr
    goto    now_incr            ; we must check every location if the device has cal memory

	btfss	Yes_blank
	return

now_incr:

	infsnz	Addr,1
	incf	Addr+1,1

	movfp	Mem_Size,WREG
	cpfseq	Addr
	goto	next_addr
	movfp	Mem_Size+1,WREG
	cpfseq	Addr+1
	goto	next_addr

	btfsc	Yes_Cal
	return

	tstfsz	csum
	bcf	Yes_blank
	tstfsz	csum+1
	bcf	Yes_blank

	return

check_cal_val:
	movfp	Cal_Addr+1,WREG
	cpfslt	Addr+1
    goto    chk_cal_lo
    goto    not_cal

chk_cal_lo:
	movfp	Cal_Addr,WREG
	cpfslt	Addr
    goto    chk_cal
    goto    not_cal

chk_cal:
	movfp 	Blank_Val,WREG
	cpfseq	MI_Data
	bcf     Yes_Cal             ;Since the opcode is the cal_op then don't program the cal value.
	movfp	Blank_Val+1,WREG
	cpfseq	MI_Data+1
	bcf     Yes_Cal             ;Since the opcode is the cal_op then don't program the cal value.

	movfp	MI_Data,WREG
	addwf	csum,1
	movfp	MI_Data+1,WREG
	addwfc	csum+1,1

        goto    now_incr


next_addr:

	bsf	IO

	btfsc	is_promate
	goto	old_next_addr

				; Send incr Addr command 000110 LSB first

	tablwt	0,0,Clk_Dat_10	;clock a 0
	tablwt	0,0,Clk_Dat_00

	tablwt	0,0,Clk_Dat_11	;clock a 1
	tablwt	0,0,Clk_Dat_01

	tablwt	0,0,Clk_Dat_11	;clock a 1
	tablwt	0,0,Clk_Dat_01


	tablwt	0,0,Clk_Dat_10	;clock a 0
	tablwt	0,0,Clk_Dat_00

	tablwt	0,0,Clk_Dat_10	;clock a 0
	tablwt	0,0,Clk_Dat_00

	tablwt	0,0,Clk_Dat_10	;clock a 0
	tablwt	0,0,Clk_Dat_00

	goto	blank_it


old_next_addr:

	movlw	0x90
	movwf	TBLPTRH
	tablwt	0,0,old_dat_low	;clock a 0

	movlw	0xA0
	movwf	TBLPTRH
	tablwt	1,0,old_clk_hi	;clock it
	tablwt	1,0,old_clk_low

	movlw	0x90
	movwf	TBLPTRH
	tablwt	0,0,old_dat_hi	;clock a 1

	movlw	0xA0
	movwf	TBLPTRH
	tablwt	1,0,old_clk_hi	;clock it
	tablwt	1,0,old_clk_low

	tablwt	1,0,old_clk_hi	;clock it
	tablwt	1,0,old_clk_low

	movlw	0x90
	movwf	TBLPTRH
	tablwt	0,0,old_dat_low	;clock a 0

	movlw	0xA0
	movwf	TBLPTRH
	tablwt	1,0,old_clk_hi	;clock it
	tablwt	1,0,old_clk_low

	tablwt	1,0,old_clk_hi	;clock it
	tablwt	1,0,old_clk_low

	tablwt	1,0,old_clk_hi	;clock it
	tablwt	1,0,old_clk_low

	goto	blank_it

	end
