;****************************************************************************************
;*
;* 文件名: touch_lib.asm
;* 项目名: SP_TOUCH_LIB_ASM_PR
;* 版 本: v1.0
;* 日 期: 2015年06月11日 19时41分04秒
;* 作 者: Administrator
;*
;****************************************************************************************
.INCLUDE "KF8S1011.INC"
;;===========================================================================
;///EX： DAT USE  P00
	.define   DAT_OUT_IO				TR0
	.define   DAT_OUT_State				P0
	.define   DAT_OUT_Vaule				P0		;//P0LR
	.define	  DAT_OUT_Bit				0
;///EX： CLK USE  P01
	.define   CLK_OUT_IO				TR0
	.define   CLK_OUT_State				P0
	.define   CLK_OUT_Vaule				P0		;//P0LR
	.define	  CLK_OUT_Bit				1
;//	
	.define   Delay_us_1_Len			0x05
	.define   Delay_us_2_Len			0x64
	
;;//	
	.define   Touch_Channel_Protect			0  ;// 默认即可 逻辑化第一触摸通道一直上传数据
;;===========================================================================
	.extern __KF8_LIBc_channel_
	.extern __KF8_TOUCH_CH_EN

	.extern __KF8_LIBi_buff_baseline_
	.extern __KF8_LIBi_buff_hit_

	.extern _STK03
	.extern _STK02
	.extern _STK01
	.extern _STK00

	.extern	_delay_us
	.extern	__R2PCL
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!	
	.define  Enable_TOUCH_DEBUG_SEND_OUT	;// 有效该函数声明
	.define  Enable__TOUCH_DEBUG_TRS_DEAL	;// 有效该函数声明
	; 汇编无作用的函数会被编译仅hex，占用程序空间，不需要时屏蔽上面两句全部，失效代码
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!	
;--------------------------------------------------------
; global declarations
;--------------------------------------------------------
.ifdef Enable_TOUCH_DEBUG_SEND_OUT
	.global	_TOUCH_DEBUG_SEND_OUT	
;	.global	_TOUCH_CH_TRS_EN
;	.global	_T_buf
;	.global	_i_T_D
	.global	_sentbuf1
	.global	_sentbuf2
	.global	_sentbuf3
	.global	_sentbuf4
.endif	

.ifdef Enable__TOUCH_DEBUG_TRS_DEAL
	.global	_TOUCH_DEBUG_TRS_DEAL
.endif
;--------------------------------------------------------
; Var definitions
;--------------------------------------------------------
UD_debug_touch_0	.udata	;// 实际地址有编译器分配 可以固定
_T_buf	.res	1

UD_debug_touch_1	.udata
_i_T_D	.res	1
UDL_debug_touch_0	.udata
_j	.res	1
UDL_debug_touch_1	.udata
_step	.res	1

.ifdef Enable_TOUCH_DEBUG_SEND_OUT
UD_debug_touch_2	.udata
_sentbuf1	.res	1

UD_debug_touch_3	.udata
_sentbuf2	.res	1

UD_debug_touch_4	.udata
_sentbuf3	.res	1

UD_debug_touch_5	.udata
_sentbuf4	.res	1
.endif

;--------------------------------------------------------
; initialized data
;--------------------------------------------------------
.ifdef Enable__TOUCH_DEBUG_TRS_DEAL
ID_debug_touch_0	.idata
_TOUCH_CH_TRS_EN
	.db	0x01
	.db	0x00
	.db	0x00
	.db	0x00
	.db	0x00
	.db	0x00
	.db	0x00
	.db	0x00
	.db	0x00
	.db	0x00
	.db	0x00
	.db	0x00
	.db	0x00
	.db	0x00
	.db	0x00
	.db	0x00			;// len 16
;	.db	0x00
;	.db	0x00
;	.db	0x00
;	.db	0x00
;	.db	0x00
;	.db	0x00			;// len 22
.endif
;--------------------------------------------------------
; overlayable items in internal ram
;--------------------------------------------------------
Named_This_Code	.code		; 上面数据段结束 下面为代码声明  后续如果中间其他声明 需继续说明下面为代码段，需要命名不同的名字
.ifdef Enable_TOUCH_DEBUG_SEND_OUT
_TOUCH_DEBUG_SEND_OUT	;Function start
;	CLK_SET_IN;
	BANKSEL CLK_OUT_IO
	SET	CLK_OUT_IO, CLK_OUT_Bit
;	DAT_SET_IN;
	BANKSEL DAT_OUT_IO
	SET	DAT_OUT_IO, DAT_OUT_Bit
;	Touch_Delay1;
	MOV	R0,# Delay_us_1_Len
	MOV	R1,# 0x00
	PAGESEL	_delay_us
	CALL	_delay_us
	PAGESEL	$
;	if(CLK_GET_STATE)
	BANKSEL CLK_OUT_State
	JB	CLK_OUT_State, CLK_OUT_Bit
	JMP	_00078_DS_ELSE_
;	Touch_Delay1;
	MOV	R0,# Delay_us_1_Len
	MOV	R1,# 0x00
	PAGESEL	_delay_us
	CALL	_delay_us
	PAGESEL	$
;	if(!CLK_GET_STATE)
	BANKSEL CLK_OUT_State
	JNB	CLK_OUT_State, CLK_OUT_Bit
	JMP	_00079_DS_DO
;	return;
	JMP	_00116_DS_END
_00078_DS_ELSE_
;	if(!CLK_GET_STATE)
	BANKSEL CLK_OUT_State
	JNB	CLK_OUT_State, CLK_OUT_Bit
	JMP	_00075_DS_ELSE
;	return;
	JMP	_00116_DS_END

_00075_DS_ELSE
;	return;
	JMP	_00116_DS_END
;//	=================================================================
_00079_DS_DO
;	CLK_SET_OUT;
	BANKSEL CLK_OUT_IO
	CLR	CLK_OUT_IO, CLK_OUT_Bit
;	CLK_SET_LOW;
	BANKSEL CLK_OUT_Vaule
	CLR	CLK_OUT_Vaule, CLK_OUT_Bit
;	Touch_Delay1;
	MOV	R0,# 0x05
	MOV	R1,# 0x00
	PAGESEL	_delay_us
	CALL	_delay_us
	PAGESEL	$
;	CLK_SET_HIGH;		//上升沿
	BANKSEL CLK_OUT_Vaule
	SET	CLK_OUT_Vaule, CLK_OUT_Bit
;	Touch_Delay1;
	MOV	R0,# Delay_us_1_Len
	MOV	R1,# 0x00
	PAGESEL	_delay_us
	CALL	_delay_us
	PAGESEL	$
;	if(!DAT_GET_STATE)
;	return;
	BANKSEL DAT_OUT_State
	JB	DAT_OUT_State, DAT_OUT_Bit
	JMP	_00116_DS_END
;	CLK_SET_LOW;			//下降沿
	BANKSEL CLK_OUT_Vaule
	CLR	CLK_OUT_Vaule, CLK_OUT_Bit
;	Touch_Delay1;
	MOV	R0,# Delay_us_1_Len
	MOV	R1,# 0x00
	PAGESEL	_delay_us
	CALL	_delay_us
	PAGESEL	$
	
;	DAT_SET_OUT;
	BANKSEL DAT_OUT_IO
	CLR	DAT_OUT_IO, DAT_OUT_Bit
;	j=5;
	MOV	R0,# 0x05
	BANKSEL	_j
	MOV	_j, R0
;//=================================================	
;	for(step=0;step<5;step++)
	BANKSEL	_step
	CLR	_step
;---------------------------------------------
_00108_DS_For
	MOV	R0,# 0x05
	BANKSEL	_step
	SUB	R0, _step

	JNB	PSW, 0
	JMP	_00111_DS_
;/--------------------------------------------
;switch(step)
	MOV	R0,# 0x05
	BANKSEL	_step
	SUB	R0, _step

	JNB	PSW, 0
	JMP	_00087_DS_switch_End_DO	;// switch  default
	MOV	R0,#high _00138_DS_Switch_Find
	MOV	PCH, R0
	MOV	R0,#_00138_DS_Switch_Find
	BANKSEL	_step
	ADD	R0, _step
	JNB	PSW, 0
	INC	PCH
	MOV	PCL, R0
_00138_DS_Switch_Find
	JMP	_00082_DS_CASE_0
	JMP	_00083_DS_CASE_1
	JMP	_00084_DS_CASE_2
	JMP	_00085_DS_CASE_3
	JMP	_00086_DS_CASE_4
;	op : LABEL
;	op : =
_00082_DS_CASE_0
;	j=5;
	MOV	R0,# 0x05
	BANKSEL	_j
	MOV	_j, R0
;	T_buf=0x04;
	MOV	R0,# 0x04
	BANKSEL	_T_buf
	MOV	_T_buf, R0
;	break;
	JMP	_00087_DS_switch_End_DO
_00083_DS_CASE_1
;	j=8;
	MOV	R0,# 0x08
	BANKSEL	_j
	MOV	_j, R0
;	T_buf=sentbuf1;
	BANKSEL	_sentbuf1
	MOVZ	R0, _sentbuf1
	BANKSEL	_T_buf
	MOV	_T_buf, R0
;	break;
	JMP	_00087_DS_switch_End_DO

_00084_DS_CASE_2
;	j=8;
	MOV	R0,# 0x08
	BANKSEL	_j
	MOV	_j, R0
;	T_buf=sentbuf2;
	BANKSEL	_sentbuf2
	MOVZ	R0, _sentbuf2
	BANKSEL	_T_buf
	MOV	_T_buf, R0
;	break;
	JMP	_00087_DS_switch_End_DO
_00085_DS_CASE_3
;	j=8;
	MOV	R0,# 0x08
	BANKSEL	_j
	MOV	_j, R0
;	T_buf=sentbuf3;
	BANKSEL	_sentbuf3
	MOVZ	R0, _sentbuf3
	BANKSEL	_T_buf
	MOV	_T_buf, R0
;	break;
	JMP	_00087_DS_switch_End_DO
_00086_DS_CASE_4
;	j=8;
	MOV	R0,# 0x08
	BANKSEL	_j
	MOV	_j, R0
;	T_buf=sentbuf4;
	BANKSEL	_sentbuf4
	MOVZ	R0, _sentbuf4
	BANKSEL	_T_buf
	MOV	_T_buf, R0
;//////////////////////////////////////////////////////////////
_00087_DS_switch_End_DO
;	for(i_T_D=0;i_T_D<j;i_T_D++)
	BANKSEL	_i_T_D
	CLR	_i_T_D
	;// 发送次数控制for
_00104_DS_For_Send
	BANKSEL	_j
	MOVZ	R0, _j
	BANKSEL	_i_T_D
	SUB	R0, _i_T_D
	JNB	PSW, 0
	JMP	_00107_DS_
	
	;/////// n次循环结果发送出完毕	
;	if(T_buf&0x01)
	BANKSEL	_T_buf
	JB	_T_buf, 0
	JMP	_00089_DS_DATA_L
;	DAT_SET_HIGH;
	BANKSEL	DAT_OUT_Vaule
	SET	DAT_OUT_Vaule, DAT_OUT_Bit
;	op : GOTO
	JMP	_00090_DS_CLK_H_SEND
_00089_DS_DATA_L
;	DAT_SET_LOW;
	BANKSEL	DAT_OUT_Vaule
	CLR	DAT_OUT_Vaule, DAT_OUT_Bit
	
_00090_DS_CLK_H_SEND
;	CLK_SET_HIGH;
	BANKSEL	CLK_OUT_Vaule
	SET	CLK_OUT_Vaule, CLK_OUT_Bit
;	Touch_Delay1;
	MOV	R0,# Delay_us_1_Len	
	MOV	R1,# 0x00
	PAGESEL	_delay_us
	CALL	_delay_us
	PAGESEL	$
;	CLK_SET_LOW;
	BANKSEL	CLK_OUT_Vaule
	CLR	CLK_OUT_Vaule, CLK_OUT_Bit
;	Touch_Delay1;
	MOV	R0,# Delay_us_1_Len	
	MOV	R1,# 0x00
	PAGESEL	_delay_us
	CALL	_delay_us
	PAGESEL	$
;	T_buf=T_buf>>1;
	CLR	PSW, 0
	BANKSEL	_T_buf
	RRC	_T_buf
;	End for(i_T_D=0;i_T_D<j;i_T_D++)
	BANKSEL	_i_T_D
	INC	_i_T_D
	JMP	_00104_DS_For_Send	
	
;// 5次循环发送数据后面暂停一个时间等待主机向上送出数据
_00107_DS_
;	Touch_Delay2;
	MOV	R0,# Delay_us_2_Len	
	MOV	R1,# 0x00
	PAGESEL	_delay_us
	CALL	_delay_us
	PAGESEL	$
	
;	END for(step=0;step<5;step++)
	BANKSEL	_step
	INC	_step
	JMP	_00108_DS_For
;//=================================================获取是否设定指令	
_00111_DS_
;	DAT_SET_IN;
	BANKSEL DAT_OUT_IO
	SET	DAT_OUT_IO, DAT_OUT_Bit	
;	Touch_Delay2;	//编程器判断需要时间
	MOV	R0,# Delay_us_2_Len	
	MOV	R1,# 0x00
	PAGESEL	_delay_us
	CALL	_delay_us
	PAGESEL	$
;	CLK_SET_HIGH;
	BANKSEL CLK_OUT_Vaule
	SET	CLK_OUT_Vaule, CLK_OUT_Bit
;	Touch_Delay1;
	MOV	R0,# Delay_us_1_Len	
	MOV	R1,# 0x00
	PAGESEL	_delay_us
	CALL	_delay_us
	PAGESEL	$
;	Touch_Delay1;
	MOV	R0,# Delay_us_1_Len	
	MOV	R1,# 0x00
	PAGESEL	_delay_us
	CALL	_delay_us
	PAGESEL	$
;	Touch_Delay1;
	MOV	R0,# Delay_us_1_Len	
	MOV	R1,# 0x00
	PAGESEL	_delay_us
	CALL	_delay_us
	PAGESEL	$
;	if(DAT_GET_STATE)
	BANKSEL DAT_OUT_State
	JB	DAT_OUT_State, DAT_OUT_Bit
	JMP	_00102_DS_
;/================================================	
;	CLK_SET_LOW;
	BANKSEL CLK_OUT_Vaule
	CLR	CLK_OUT_Vaule, CLK_OUT_Bit
;	T_buf=0;
	BANKSEL	_T_buf
	CLR	_T_buf
;	Touch_Delay1;
	MOV	R0,# Delay_us_1_Len	
	MOV	R1,# 0x00
	PAGESEL	_delay_us
	CALL	_delay_us
	PAGESEL	$
;	for(i_T_D=0;i_T_D<6;i_T_D++)
	BANKSEL	_i_T_D
	CLR	_i_T_D
_00112_DS_
	MOV	R0,# 0x06
	BANKSEL	_i_T_D
	SUB	R0, _i_T_D

	JNB	PSW, 0
	JMP	_00103_DS_
	
;	CLK_SET_HIGH;
	BANKSEL	CLK_OUT_Vaule
	SET	CLK_OUT_Vaule, CLK_OUT_Bit
;	Touch_Delay1;
	MOV	R0,# Delay_us_1_Len	
	MOV	R1,# 0x00
	PAGESEL	_delay_us
	CALL	_delay_us
	PAGESEL	$
	
;	if(i_T_D!=5)
	BANKSEL	_i_T_D
	MOVZ	R0, _i_T_D
	XOR	R0,# 0x05
	JNB	PSW, 2
	JMP	_00099_DS_
	
;	T_buf=T_buf>>1;
	CLR	PSW, 0
	BANKSEL	_T_buf
	RRC	_T_buf
;	if(DAT_GET_STATE)
	BANKSEL DAT_OUT_State
	JB	DAT_OUT_State, DAT_OUT_Bit
	JMP	_00100_DS_
;	T_buf=T_buf|0x10;
	BANKSEL	_T_buf
	SET	_T_buf, 4
	JMP	_00100_DS_

_00099_DS_
	JMP _00100_DS_	;// 第六位 设定
;//////////////////////////////////////////
_00100_DS_
;	CLK_SET_LOW;
	BANKSEL CLK_OUT_Vaule
	CLR	CLK_OUT_Vaule, CLK_OUT_Bit
;	Touch_Delay1;
	MOV	R0,# Delay_us_1_Len	
	MOV	R1,# 0x00
	PAGESEL	_delay_us
	CALL	_delay_us
	PAGESEL	$
;	for(i_T_D=0;i_T_D<6;i_T_D++)
	BANKSEL	_i_T_D
	INC	_i_T_D
	JMP	_00112_DS_
;=---------------------------===
;================================================/	
_00102_DS_
;	CLK_SET_LOW;
	BANKSEL CLK_OUT_Vaule
	CLR	CLK_OUT_Vaule, CLK_OUT_Bit
;	Touch_Delay1;
	MOV	R0,# Delay_us_1_Len	
	MOV	R1,# 0x00
	PAGESEL	_delay_us
	CALL	_delay_us
	PAGESEL	$
_00103_DS_
;	CLK_SET_IN;
	BANKSEL	CLK_OUT_IO
	SET	CLK_OUT_IO, CLK_OUT_Bit
;	DAT_SET_IN;
	BANKSEL	DAT_OUT_IO
	SET	DAT_OUT_IO, DAT_OUT_Bit

_00116_DS_END
	CRET	
.endif
;//==============================================================//
;//==============================================================//
.ifdef Enable__TOUCH_DEBUG_TRS_DEAL
_TOUCH_DEBUG_TRS_DEAL	;Function start
	;TOUCH_CH_TRS_EN[_KF8_TOUCH_CH_EN[Touch_Channel_Protect]]=1;
	MOV R1,#High(__KF8_TOUCH_CH_EN+0)
	MOV R0,#(0)
	ADD R0,#Low(__KF8_TOUCH_CH_EN+0)
	JNB PSW,0
	INC R1
	PAGESEL __R2PCL
	CALL __R2PCL
	PAGESEL $
	ADD R0,#(_TOUCH_CH_TRS_EN+0)
	MOV R1,#0x01
	BANKSEL _TOUCH_CH_TRS_EN
	ST [R0],R1
	
	;if(TOUCH_CH_TRS_EN[_TOUCH_CH_EN[_KF8_LIBc_channel_]])
	BANKSEL __KF8_LIBc_channel_
	MOV R0,__KF8_LIBc_channel_
	ADD R0,#Low(__KF8_TOUCH_CH_EN+0)
	MOV R1,#High(__KF8_TOUCH_CH_EN+0)
	JNB PSW,0
	INC R1
	PAGESEL __R2PCL
	CALL __R2PCL
	PAGESEL $
	ADD R0,#(_TOUCH_CH_TRS_EN+0)
	BANKSEL _TOUCH_CH_TRS_EN
	LD R1,[R0]
	XOR R1,#0x00
	JNB PSW,2
	JMP Label_x_y_z_a
	;//==========================================================
;	CLK_SET_IN;
	BANKSEL CLK_OUT_IO
	SET	CLK_OUT_IO, CLK_OUT_Bit
;	DAT_SET_IN;
	BANKSEL DAT_OUT_IO
	SET	DAT_OUT_IO, DAT_OUT_Bit
;	Touch_Delay1;
	MOV	R0,# Delay_us_1_Len
	MOV	R1,# 0x00
	PAGESEL	_delay_us
	CALL	_delay_us
	PAGESEL	$
;	if(CLK_GET_STATE)
	BANKSEL CLK_OUT_State
	JB	CLK_OUT_State, CLK_OUT_Bit
	JMP	_00078_DS_ELSE_1
;	Touch_Delay1;
	MOV	R0,# Delay_us_1_Len
	MOV	R1,# 0x00
	PAGESEL	_delay_us
	CALL	_delay_us
	PAGESEL	$
;	if(!CLK_GET_STATE)
	BANKSEL CLK_OUT_State
	JNB	CLK_OUT_State, CLK_OUT_Bit
	JMP	_00079_DS_DO1
;	return;
	JMP	Label_x_y_z_a
_00078_DS_ELSE_1
;	if(!CLK_GET_STATE)
	BANKSEL CLK_OUT_State
	JNB	CLK_OUT_State, CLK_OUT_Bit
	JMP	_00075_DS_ELSE1
;	return;
	JMP	Label_x_y_z_a

_00075_DS_ELSE1
;	return;
	JMP	Label_x_y_z_a
;//	=================================================================
_00079_DS_DO1
;	CLK_SET_OUT;
	BANKSEL CLK_OUT_IO
	CLR	CLK_OUT_IO, CLK_OUT_Bit
;	CLK_SET_LOW;
	BANKSEL CLK_OUT_Vaule
	CLR	CLK_OUT_Vaule, CLK_OUT_Bit
;	Touch_Delay1;
	MOV	R0,# 0x05
	MOV	R1,# 0x00
	PAGESEL	_delay_us
	CALL	_delay_us
	PAGESEL	$
;	CLK_SET_HIGH;		//上升沿
	BANKSEL CLK_OUT_Vaule
	SET	CLK_OUT_Vaule, CLK_OUT_Bit
;	Touch_Delay1;
	MOV	R0,# Delay_us_1_Len
	MOV	R1,# 0x00
	PAGESEL	_delay_us
	CALL	_delay_us
	PAGESEL	$
;	if(!DAT_GET_STATE)
;	return;
	BANKSEL DAT_OUT_State
	JB	DAT_OUT_State, DAT_OUT_Bit
	JMP	Label_x_y_z_a
	
;	CLK_SET_LOW;			//下降沿
	BANKSEL CLK_OUT_Vaule
	CLR	CLK_OUT_Vaule, CLK_OUT_Bit
;	Touch_Delay1;
	MOV	R0,# Delay_us_1_Len
	MOV	R1,# 0x00
	PAGESEL	_delay_us
	CALL	_delay_us
	PAGESEL	$
	
;	DAT_SET_OUT;
	BANKSEL DAT_OUT_IO
	CLR	DAT_OUT_IO, DAT_OUT_Bit
;	j=5;
	MOV	R0,# 0x05
	BANKSEL	_j
	MOV	_j, R0
	;//========================================================
	;for(step=0;step<5;step++)
	BANKSEL	_step
	CLR	_step
_00037_DS_
	MOV	R0,# 0x05
	BANKSEL	_step
	SUB	R0, _step

	JNB	PSW, 0
	JMP	_00040_DS_
;	switch(step)
	MOV	R0,# 0x05
	BANKSEL	_step
	SUB	R0, _step
	JNB	PSW, 0
	JMP	_00016_DS_switch_END			;// switch default or end 
	MOV	R0,#high _00067_DS_
	MOV	PCH, R0
	MOV	R0,#_00067_DS_
	BANKSEL	_step
	ADD	R0, _step
	JNB	PSW, 0
	INC	PCH
	MOV	PCL, R0
_00067_DS_
	JMP	_00011_DS_CASE_0
	JMP	_00012_DS_CASE_1
	JMP	_00013_DS_CASE_2
	JMP	_00014_DS_CASE_3
	JMP	_00015_DS_CASE_4
_00011_DS_CASE_0
;	j=5;
	MOV	R0,# 0x05
	BANKSEL	_j
	MOV	_j, R0
;	T_buf=_KF8_TOUCH_CH_EN[_KF8_LIBc_channel_];
	BANKSEL __KF8_LIBc_channel_
	MOV R0, __KF8_LIBc_channel_
	ADD R0,#Low(__KF8_TOUCH_CH_EN+0)
	MOV R1,#High(__KF8_TOUCH_CH_EN+0)
	JNB PSW,0
	INC R1
	MOV PCH,R1
	PAGESEL __R2PCL
	CALL __R2PCL
	PAGESEL $
	BANKSEL _T_buf
	MOV _T_buf,R0	
;	break;
	JMP	_00016_DS_switch_END
_00012_DS_CASE_1
;	j=8;
	MOV	R0,# 0x08
	BANKSEL	_j
	MOV	_j, R0
;	T_buf=(unsigned char)(_KF8_LIBi_buff_baseline_[_KF8_LIBc_channel_]);
	BANKSEL __KF8_LIBc_channel_
	CLR PSW,0
	RLCR __KF8_LIBc_channel_
	BANKSEL __KF8_LIBi_buff_baseline_
	ADD R0,#(__KF8_LIBi_buff_baseline_+0)
	LD R1,[R0]
	BANKSEL _T_buf
	MOV _T_buf,R1	
;	break;
	JMP	_00016_DS_switch_END

_00013_DS_CASE_2
;	j=8;
	MOV	R0,# 0x08
	BANKSEL	_j
	MOV	_j, R0
;	T_buf=(unsigned char)(_KF8_LIBi_buff_baseline_[_KF8_LIBc_channel_]>>8);
	BANKSEL __KF8_LIBc_channel_
	CLR PSW,0
	RLCR __KF8_LIBc_channel_
	BANKSEL __KF8_LIBi_buff_baseline_
	ADD R0,#(__KF8_LIBi_buff_baseline_+1)
	LD R1,[R0]
	BANKSEL _T_buf
	MOV _T_buf,R1	
;	break;
	JMP	_00016_DS_switch_END
_00014_DS_CASE_3
;	j=8;
	MOV	R0,# 0x08
	BANKSEL	_j
	MOV	_j, R0
;	 T_buf=(unsigned char)(_KF8_LIBi_buff_hit_[_KF8_LIBc_channel_]);
	BANKSEL __KF8_LIBc_channel_
	CLR PSW,0
	RLCR __KF8_LIBc_channel_
	BANKSEL __KF8_LIBi_buff_hit_
	ADD R0,#(__KF8_LIBi_buff_hit_+0)
	LD R1,[R0]
	BANKSEL _T_buf
	MOV _T_buf,R1	
;	break;
	JMP	_00016_DS_switch_END
_00015_DS_CASE_4
;	j=8;
	MOV	R0,# 0x08
	BANKSEL	_j
	MOV	_j, R0
;	T_buf=(unsigned char)(_KF8_LIBi_buff_hit_[_KF8_LIBc_channel_]>>8);
	BANKSEL __KF8_LIBc_channel_
	CLR PSW,0
	RLCR __KF8_LIBc_channel_
	BANKSEL __KF8_LIBi_buff_hit_
	ADD R0,#(__KF8_LIBi_buff_hit_+1)
	LD R1,[R0]
	BANKSEL _T_buf
	MOV _T_buf,R1	

_00016_DS_switch_END
;	for(i_T_D=0;i_T_D<j;i_T_D++)		//  将通道数据上传 
	BANKSEL	_i_T_D
	CLR	_i_T_D

_00033_DS_
	BANKSEL	_j
	MOVZ	R0, _j
	BANKSEL	_i_T_D
	SUB	R0, _i_T_D
	JNB	PSW, 0
	JMP	_00036_DS_
	
;	if(T_buf&0x01)
	BANKSEL	_T_buf
	JB	_T_buf, 0
	JMP	_00018_DS_
;	DAT_SET_HIGH;
	BANKSEL DAT_OUT_Vaule
	SET	DAT_OUT_Vaule, DAT_OUT_Bit
	JMP	_00019_DS_
_00018_DS_
;	DAT_SET_LOW;
	BANKSEL DAT_OUT_Vaule
	CLR	DAT_OUT_Vaule, DAT_OUT_Bit
_00019_DS_
;	CLK_SET_HIGH;
	BANKSEL CLK_OUT_Vaule
	SET	CLK_OUT_Vaule, CLK_OUT_Bit
;	Touch_Delay1;
	MOV	R0,# Delay_us_1_Len	
	MOV	R1,# 0x00
	PAGESEL	_delay_us
	CALL	_delay_us
	PAGESEL	$
;	CLK_SET_LOW;
	BANKSEL CLK_OUT_Vaule
	CLR	CLK_OUT_Vaule, CLK_OUT_Bit
;	Touch_Delay1;
	MOV	R0,# Delay_us_1_Len	
	MOV	R1,# 0x00
	PAGESEL	_delay_us
	CALL	_delay_us
	PAGESEL	$
;	T_buf=T_buf>>1;
	CLR	PSW, 0
	BANKSEL	_T_buf
	RRC	_T_buf
;	END for(i_T_D=0;i_T_D<j;i_T_D++)
	BANKSEL	_i_T_D
	INC	_i_T_D
	JMP	_00033_DS_

_00036_DS_
;	Touch_Delay2;
	MOV	R0,# Delay_us_2_Len	
	MOV	R1,# 0x00
	PAGESEL	_delay_us
	CALL	_delay_us
	PAGESEL	$
;	for(step=0;step<5;step++)
	BANKSEL	_step
	INC	_step
	JMP	_00037_DS_

_00040_DS_
;	DAT_SET_IN;
	BANKSEL DAT_OUT_IO
	SET	DAT_OUT_IO, DAT_OUT_Bit
;	Touch_Delay2;	//编程器判断需要时间
	MOV	R0,# Delay_us_2_Len	
	MOV	R1,# 0x00
	PAGESEL	_delay_us
	CALL	_delay_us
	PAGESEL	$
;	CLK_SET_HIGH;
	BANKSEL CLK_OUT_Vaule
	SET	CLK_OUT_Vaule, CLK_OUT_Bit
;	Touch_Delay1;
	MOV	R0,# Delay_us_1_Len	
	MOV	R1,# 0x00
	PAGESEL	_delay_us
	CALL	_delay_us
	PAGESEL	$
;	Touch_Delay1;
	MOV	R0,# Delay_us_1_Len	
	MOV	R1,# 0x00
	PAGESEL	_delay_us
	CALL	_delay_us
	PAGESEL	$
;	Touch_Delay1;
	MOV	R0,# Delay_us_1_Len	
	MOV	R1,# 0x00
	PAGESEL	_delay_us
	CALL	_delay_us
	PAGESEL	$
	
;	if(DAT_GET_STATE)
	BANKSEL DAT_OUT_State
	JB	DAT_OUT_State, DAT_OUT_Bit
	JMP	_00031_DS_		;// 是否有设定信息
;	CLK_SET_LOW;
	BANKSEL CLK_OUT_Vaule
	CLR	CLK_OUT_Vaule, CLK_OUT_Bit
;	T_buf=0;
	BANKSEL	_T_buf
	CLR	_T_buf
;	Touch_Delay1;
	MOV	R0,# Delay_us_1_Len	
	MOV	R1,# 0x00
	PAGESEL	_delay_us
	CALL	_delay_us
	PAGESEL	$
	
;	for(i_T_D=0;i_T_D<6;i_T_D++)	// 设定信息处理
	BANKSEL	_i_T_D
	CLR	_i_T_D
_00041_DS_
	MOV	R0,# 0x06
	BANKSEL	_i_T_D
	SUB	R0, _i_T_D
	JNB	PSW, 0
	JMP	_00032_DS_
	;//============
;	CLK_SET_HIGH;
	BANKSEL CLK_OUT_Vaule
	SET	CLK_OUT_Vaule, CLK_OUT_Bit
;	Touch_Delay1;
	MOV	R0,# Delay_us_1_Len	
	MOV	R1,# 0x00
	PAGESEL	_delay_us
	CALL	_delay_us
	PAGESEL	$
;	if(i_T_D!=5)
	BANKSEL	_i_T_D
	MOVZ	R0, _i_T_D
	XOR	R0,# 0x05
	JNB	PSW, 2
	JMP	_00028_DS_
;	T_buf=T_buf>>1;
	CLR	PSW, 0
	BANKSEL	_T_buf
	RRC	_T_buf
;	if(DAT_GET_STATE)
	BANKSEL DAT_OUT_State
	JB	DAT_OUT_State, DAT_OUT_Bit
	JMP	_00029_DS_
;	T_buf=T_buf|0x10;
	BANKSEL	_T_buf
	SET	_T_buf, 4
	JMP	_00029_DS_

_00028_DS_
;//========================
;	if(T_buf<16)   //传输错误的，防下非影响其他数据
	MOV	R0,# 0x10
	BANKSEL	_T_buf
	SUB	R0, _T_buf
	JNB	PSW, 0
	JMP	_00029_DS_
;	if(DAT_GET_STATE)
	BANKSEL DAT_OUT_State
	JB	DAT_OUT_State, DAT_OUT_Bit
	JMP	_00023_DS_
;	TOUCH_CH_TRS_EN[T_buf]=1;
	BANKSEL _T_buf
	MOV R0,_T_buf
	ADD R0,#(_TOUCH_CH_TRS_EN+0)
	MOV R1,#0x01
	BANKSEL _TOUCH_CH_TRS_EN
	ST [R0],R1
	JMP	_00029_DS_
;	TOUCH_CH_TRS_EN[T_buf]=0;
_00023_DS_
	BANKSEL _T_buf
	MOV R0,_T_buf
	ADD R0,#(_TOUCH_CH_TRS_EN+0)
	MOV R1,#0x00
	BANKSEL _TOUCH_CH_TRS_EN
	ST [R0],R1
;//========================
_00029_DS_
;	CLK_SET_LOW;
	BANKSEL CLK_OUT_Vaule
	CLR	CLK_OUT_Vaule, CLK_OUT_Bit
;	Touch_Delay1;
	MOV	R0,# Delay_us_1_Len	
	MOV	R1,# 0x00
	PAGESEL	_delay_us
	CALL	_delay_us
	PAGESEL	$
;	end for(i_T_D=0;i_T_D<6;i_T_D++)
	BANKSEL	_i_T_D
	INC	_i_T_D
	JMP	_00041_DS_
;//=======================================================
_00031_DS_
;	CLK_SET_LOW;
	BANKSEL CLK_OUT_Vaule
	CLR	CLK_OUT_Vaule,CLK_OUT_Bit
;	Touch_Delay1;
	MOV	R0,# Delay_us_1_Len	
	MOV	R1,# 0x00
	PAGESEL	_delay_us
	CALL	_delay_us
	PAGESEL	$

_00032_DS_
;	CLK_SET_IN;
	BANKSEL CLK_OUT_IO
	SET	CLK_OUT_IO, CLK_OUT_Bit
;	DAT_SET_IN;
	BANKSEL DAT_OUT_IO
	SET	DAT_OUT_IO, DAT_OUT_Bit

Label_x_y_z_a
_00045_DS_
	CRET	
.endif
	.end
