⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hilon.asm

📁 hilon B协议编程
💻 ASM
📖 第 1 页 / 共 4 页
字号:
	jne	caculate_u_zone_01
	cmp	ax,#100
	jne	caculate_u_zone_01
	ld	bx,#u_rating_num1
	sjmp	caculate_u_zone_02
caculate_u_zone_01:
	ld	bx,#u_rating_num2
caculate_u_zone_02:
	ld	ax,dead_zone
	mulu	ax,bx
	divu	ax,#100
	st	ax,u_zone

	ldbze	ax,dead_zone
	ld	bx,#i_rating_num
	mulu	ax,bx
	divu	ax,#100
	st	ax,i_zone

	ldbze	ax,dead_zone
	ld	bx,#f_rating_num
	mulu	ax,bx
	divu	ax,#100
	st	ax,f_zone

	ldbze	ax,dead_zone
	ld	bx,#pf_rating_num
	mulu	ax,bx
	divu	ax,#100
	st	ax,pf_zone

	ld	ax,ptratel
	ld	bx,ptrateh
	cmp	r0,bx
	jne	caculate_u_zone_03
	cmp	ax,#100
	jne	caculate_u_zone_03
	ld	bx,#p_rating_num1
	sjmp	caculate_u_zone_04
caculate_u_zone_03:
	ld	bx,#p_rating_num2
caculate_u_zone_04:
	ld	ax,dead_zone
	mulu	ax,bx
	st	ax,p_zonel
	st	bx,p_zoneh

	bmovm	#uabrem,#uab,#9			; initialize the sending memory value
	ld	ax,in
	st	ax,inrem
	ld	ax,freq
	st	ax,freqrem
	ld	ax,pf
	st	ax,cosrem
	bmovm	#wfpowrem,#wfpowl,#4
	bmovm	#freqarem,#freqa,#06
	bmovm	#wfpowarem,#power_buf,#12
	ret
;----------------------------------------------------------------
; function code form
; broadcast time	ask time		yx
; important yc		normal yc		other rest yc
; ask soe		ask setting		modify setting
; ask remote pulse	single yk		group yk
; return slaveaddr and baudrate
station_cmdnum:
	dcb	12
station_cmdtab:
	dcb	07ah,0a7h,0f4h
	dcb	061h,051h,041h
	dcb	026h,018h,01Ah
	dcb	085h,0c2h,0cch
;----------------------------------------------------------------
set_stat_byte:
	dcb	11h,88h,00h,99h
;----------------------------------------------------------------
outcomm_proc:
; analyse received message's form master machine
; out:	bxl:current analysed message's style
;	cx:current analysed message's start point
	jbsm	sendf,cancomm_proc_00
	call	judge_yc_autosending
yc_autosend_not_permit:
	jbsm	rec_readyf,rec_already_complete
cancomm_proc_00:
	ret				; if data not receive complete, return directly
rec_already_complete:
	ld	cx,#recadd
con_analyse:
	ld	ax,cx
	ldb	bxl,[ax]+		; received character start point
	ld	dx,#station_cmdtab
	clr	ax
cmp_station_type:
	ldb	bxh,station_cmdnum	
	cmpb	axl,bxh
	jc	not_correct
	ldb	bxh,[dx]+
	cmpb	bxl,bxh
	je	station_type_right
	incb	axl
	sjmp	cmp_station_type
not_correct:
	ljmp	do_modify_funcerr

station_type_right:
	ldb	funccode,bxl
;	clrb	rec_time
	shl	ax,#01
	ld	ax,execute_command_tab[ax]
	br	[ax]		

execute_command_tab:
	dcw	adjust_time		; system time
	dcw	return_time		; time call back
	dcw	answer_yx		; remote signaling
	dcw	answer_important_yc	; voltage meter
	dcw	answer_normal_yc	; current meter
	dcw	answer_other_rest_yc	; frequency and power factor
	dcw	answer_soe		; SOE query
	dcw	answer_substat_set	; query setting
	dcw	modify_substat_set	; modify setting
	dcw	answer_remote_pulse	; query remote pulse
	dcw	single_execute_yk	; do single control
	dcw	group_execute_yk	; do group control
;----------------------------------------------------------------
cseg
adjust_time:
	ldb	axl,reclen
	cmpb	axl,#time_len
	jne	exit_adj_time
	add	ax,cx,#01h
	ld	dx,#yearbuf
	ldb	bxh,#6
adjust_time_loop:
	ldb	bxl,[ax]+
	stb	bxl,[dx]+
	djnz	bxh,adjust_time_loop
	call	adjust_systime_check
	jbsm	illegal_timef,exit_adj_time
	call	adjust_system_time
	clrb	tmr1ov
	ld	msstart,timer1
	andb	status,#0fdh
;	ljmp	return_time		; %%% just for debug
exit_adj_time:
	clrbit	rec_readyf
	ret
;----------------------------------------------------------------
return_time:
	ldb	axl,reclen
	cmpb	axl,#short_ask_len
	jne	short_ask_data_error
	ld	sndpt,#sndadd
	ldb	sndlen,#06
	stb	year,[sndpt]+
	stb	month,[sndpt]+
	stb	day,[sndpt]+
	stb	hour,[sndpt]+
	stb	minute,[sndpt]+
	stb	second,[sndpt]
	ljmp	do_answer_ending
short_ask_data_error:
	ljmp	do_modify_dataerr
;----------------------------------------------------------------
answer_yx:
	ldb	axl,reclen
	cmpb	axl,#short_ask_len
	jne	short_ask_data_error
	ld	sndpt,#sndadd
	ldb	sndlen,#04
;
        ldb     axl,yx
        st      r0,cx
answer_yx_02:
        cmpb    r0,inputfunc[cx]
        je      answer_yx_03
        andb    axl,clr_bit_tab[cx]             ; if the channel input pulse,not included in yx
answer_yx_03:
        inc     cx
        cmp     cx,#07
        jnh     answer_yx_02
	stb	axl,[sndpt]+
;
	stb	phsAprt,[sndpt]+
	stb	phsBprt,[sndpt]+
	stb	phsCprt,[sndpt]
	ljmp	do_answer_ending
clr_bit_tab:
        dcb     0feh,0fdh,0fbh,0f7h,0efh,0dfh,0bfh,07fh
;----------------------------------------------------------------
apply_ask_yx:
	ldb	axl,#yx_apply_ask
	sjmp	auto_send_apply_com

auto_send_apply_com:
	ldb	funccode,#auto_send_apply
	stb	r0,masaddr
	ld	sndpt,#sndadd
	ldb	sndlen,#01
	stb	axl,[sndpt]
        setbit  applyaskf                       ; for PRI=0 when apply ask yx or yc PRI=0
	ljmp	do_answer_ending
;----------------------------------------------------------------
apply_ask_important_yc:
	ldb	axl,#yc1_apply_ask
	sjmp	auto_send_apply_com
;----------------------------------------------------------------
apply_ask_common_yc:
	ldb	axl,#yc2_apply_ask
	sjmp	auto_send_apply_com
;----------------------------------------------------------------
apply_ask_subordinate_yc:
	ldb	axl,#yc3_apply_ask
	sjmp	auto_send_apply_com
;----------------------------------------------------------------
short_ask_yc_error00:
	ljmp	short_ask_data_error
answer_important_yc:
	ldb	axl,reclen
	cmpb	axl,#short_ask_len
	jne	short_ask_yc_error00
	ld	sndpt,#sndadd
	ldb	sndlen,#42
;
        ld      dx,#llu_buf
        ldb     cxl,#24
answer_voltage_loop:			; the high bit ahead
        ldb     axl,systemtype 
        cmpb    axl,#01
        jnh     answer_voltage_3p4w
        sub     ax,dx,#llu_buf
        cmp     ax,#4
        jnh     answer_voltage_3p4w       ; answer line to line voltage
	stb	r0,[sndpt]+
	stb	r0,[sndpt]+
	stb	r0,[sndpt]+
	stb	r0,[sndpt]+
        inc     dx
        inc     dx
       sjmp    answer_voltage_loop_01
answer_voltage_3p4w:
	ld	ax,[dx]+  
	push	cx
	push	dx
	call	compute_voltage	
	pop	dx
	pop	cx
	stb	bxh,[sndpt]+            ; pay attention to the high and low byte order
	stb	bxl,[sndpt]+
	stb	axh,[sndpt]+
	stb	axl,[sndpt]+
answer_voltage_loop_01:
	subb	cxl,#04
	cmpb	r0,cxl
	jne	answer_voltage_loop
;
        ld      dx,#i_buf
        ld      cxl,#12
answer_current_loop:
	ld	ax,[dx]+
	push	cx
	push	dx
	call	compute_current
	pop	dx
	pop	cx
	stb	bxh,[sndpt]+
	stb	bxl,[sndpt]+
	stb	axh,[sndpt]+
	stb	axl,[sndpt]+
	subb	cxl,#04
	cmpb	r0,cxl
	jne	answer_current_loop		; modify by suny
;
	ld	ax,in
	call	compute_n_current
	stb	axh,[sndpt]+
	stb	axl,[sndpt]+
	ld	ax,pf
	stb	axh,[sndpt]+
	stb	axl,[sndpt]+
	ld	ax,freq
	stb	axh,[sndpt]+
	stb	axl,[sndpt]+

	bmovm	#uabrem,#uab,#9
	ld	ax,in
	st	ax,inrem
	ld	ax,freq
	st	ax,freqrem
	ld	ax,pf
	st	ax,cosrem

	ljmp	do_answer_ending
short_ask_yc_error:
	ljmp	short_ask_data_error
;----------------------------------------------------------------
short_ask_yc_error01:
	ljmp	short_ask_data_error
answer_normal_yc:
	ldb	axl,reclen
	cmpb	axl,#short_ask_len
	jne	short_ask_yc_error01
	ld	sndpt,#sndadd
	ldb	sndlen,#16
	ld	ax,wfpowl
	ld	bx,wfpowh
	call	compute_power
	stb	bxh,[sndpt]+
	stb	bxl,[sndpt]+
	stb	axh,[sndpt]+
	stb	axl,[sndpt]+
	ld	ax,wlpowl
	ld	bx,wlpowh
	call	compute_power
	stb	bxh,[sndpt]+
	stb	bxl,[sndpt]+
	stb	axh,[sndpt]+
	stb	axl,[sndpt]+
	ld	cx,#energy_buf
	add	cx,#24
	ldb	dxl,#02h
sum_energy_yc_01:			; 累加电能
	ld	ax,[cx]+
	ld	bx,[cx]+
	stb	bxh,[sndpt]+
	stb	bxl,[sndpt]+
	stb	axh,[sndpt]+
	stb	axl,[sndpt]+
	djnz	dxl,sum_energy_yc_01
	bmovm	#wfpowrem,#wfpowl,#4
	ljmp	do_answer_ending
;----------------------------------------------------------------
answer_rest_yc_zero_value:
        ldb     axl,#60
rest_yc_continue_fill_zero:
        stb     r0,[sndpt]+
        djnz    axl,rest_yc_continue_fill_zero
	bmovm	#freqarem,#zero_buf,#06
	bmovm	#wfpowarem,#zero_buf,#12
	ljmp	do_answer_ending              
;
short_ask_yc_error02:
	ljmp	short_ask_data_error
answer_other_rest_yc:
	ldb	axl,reclen
	cmpb	axl,#short_ask_len
	jne	short_ask_yc_error02
	ld	sndpt,#sndadd
	ldb	sndlen,#60
;
        ldb     axl,systemtype 
        cmpb    axl,#01
        jnh     answer_rest_yc_zero_value
;
	ld	ax,pfa
	stb	axh,[sndpt]+
	stb	axl,[sndpt]+
	ld	ax,pfb
	stb	axh,[sndpt]+
	stb	axl,[sndpt]+
	ld	ax,pfc
	stb	axh,[sndpt]+
	stb	axl,[sndpt]+
	ld	ax,freqa
	stb	axh,[sndpt]+
	stb	axl,[sndpt]+
	ld	ax,freqb
	stb	axh,[sndpt]+
	stb	axl,[sndpt]+
	ld	ax,freqc
	stb	axh,[sndpt]+
	stb	axl,[sndpt]+
	ldb	cxl,#06
	ld	dx,#power_buf
loop_compute_power:			; 循环计算功率
	ld	ax,[dx]+
	ld	bx,[dx]+
	push	cx
	push	dx
	call	compute_power
	pop	dx
	pop	cx
	stb	bxh,[sndpt]+
	stb	bxl,[sndpt]+
	stb	axh,[sndpt]+
	stb	axl,[sndpt]+
	djnz	cxl,loop_compute_power
	ld	cx,#energy_buf
	ldb	dxl,#06h
single_phase_energy_01:
	ld	ax,[cx]+
	ld	bx,[cx]+
	stb	bxh,[sndpt]+
	stb	bxl,[sndpt]+
	stb	axh,[sndpt]+
	stb	axl,[sndpt]+
	djnz	dxl,single_phase_energy_01
	bmovm	#freqarem,#freqa,#06
	bmovm	#wfpowarem,#power_buf,#12
	ljmp	do_answer_ending
;----------------------------------------------------------------
short_ask_soe_error:
	ljmp	short_ask_data_error
answer_soe:
	ldb	axl,reclen
	cmpb	axl,#short_ask_len
	jne	short_ask_soe_error
	ld	sndpt,#sndadd
	cmpb	r0,soenum
	jne	continue_do_soe
	ldb	bxl,#00h
	stb	bxl,[sndpt]+
	ldb	sndlen,#01h
	andb	status,#0feh		; if no soe left, clear soe flag
	ljmp	do_answer_ending
continue_do_soe:
	ldb	cxl,soenum
	cmpb	cxl,#04h
	jnh	soe_less4		; if current left soe message is less than 4
	subb	cxh,cxl,#04		; if more than, leave the soe number after sending in cxh
	ldb	cxl,#04h		; this round send soe number
	sjmp	soe_more4
soe_less4:
	ldb	cxl,soenum
	clrb	cxh			; leave the soe number after sending in cxh
	andb	status,#0feh		; if no soe left, clear soe flag
soe_more4:
	shlb	cxl,#03			; 8 byte/4 word per soe
	ldb	sndlen,cxl		; send length
	ld	ax,soept		; source address
	ldbze	bx,soenum
	stb	cxh,soenum
	shl	bx,#03
	sub	ax,bx
get_soe_data:
	and	ax,#soemsk
	or	ax,#soeadd
	ldb	bxl,[ax]+
	stb	bxl,[sndpt]+
	decb	cxl
	ld	dx,#07h
reverse_order_soe_time:
	dec	dx
	and	ax,#soemsk
	or	ax,#soeadd
	ldb	bxl,[ax]+
	stb	bxl,soe_tempbuf[dx]
	cmp	r0,dx
	jne	reverse_order_soe_time
fill_send_soe_time:
	ldb	bxl,soe_tempbuf[dx]	
	stb	bxl,[sndpt]+
	decb	cxl
	inc	dx
	cmp	dx,#07h
	jnc	fill_send_soe_time
	cmpb	r0,cxl
	jne	get_soe_data
	ljmp	do_answer_ending
;----------------------------------------------------------------
single_yk_forbid_broadcast:
        clrbit  brdcastf
        ret
do_yk_fail:
	ldb	axh,#ykfailure		; return yk fail
	stb	axh,[sndpt]
	sjmp	yk_common
single_execute_yk:
        jbsm    brdcastf,single_yk_forbid_broadcast
	ldb	axl,reclen
	cmpb	axl,#yk_oper_len
	je	oper_yk_continue
yk_data_error:
	ljmp	do_modify_dataerr
oper_yk_continue:
	inc	cx
	ldb	axl,[cx]+		; yk object
	ld	sndpt,#sndadd
	ldb	sndlen,#02
	stb	axl,[sndpt]+		; return yk object
	ldb	axh,[cx]		; yk type
	stb	axh,[sndpt]		; return yk type
	cmpb	axl,#03h
	jh	yk_data_error
	cmpb	axl,linkrelayI
	je	do_yk_fail
	cmpb	axl,linkrelayLowU
	je	do_yk_fail
	cmpb	axl,linkrelayOverU
	je	do_yk_fail
	cmpb	axl,linkrelayF
	je	do_yk_fail
	cmpb	axl,linkrelayPF
	je	do_yk_fail

	cmpb	axh,#ykclose
	je	single_yk_close		; if close
	cmpb	axh,#ykopen
	jne	yk_data_error		; if command error
	clrb	axh			; if open
	andb	r0,yk,yk_close_table[ax]
	je	do_yk_fail		; if already open
	andb	yk,yk_open_table[ax]
	lcall	yk_exe_output			; release relay
	andb	ykdoing,yk_open_table[ax]
	sjmp	yk_common
do_yk_fail_00:
	ljmp	do_yk_fail
single_yk_close:
	clrb	axh
	ld	bx,ax
	shl	bx,#01
	cmp	r0,yk_time[bx]
	je	holding_yk
	andb	r0,yk,yk_close_table[ax]
	jne	do_yk_fail_00
	di
	orb	yk,yk_close_table[ax]	; close
	lcall	yk_exe_output
	st	r0,ykct[bx]
	cmpb	r0,ykdoing
	jne	no_need_start_yk_timer
	ldb	hso_command,#yksfttmrcmd
	add	hso_time,timer1,#50000	; 50ms	
no_need_start_yk_timer:
	orb	ykdoing,yk_close_table[ax]	; set yk executing flag	
	ei
	sjmp	yk_common
holding_yk:
	orb	yk,yk_close_table[ax]	; if close
	lcall	yk_exe_output
	sjmp	yk_common
yk_common:
	ljmp	do_answer_ending
;----------------------------------------------------------------
group_execute_yk:
	ljmp	do_modify_funcerr
;----------------------------------------------------------------
short_ask_substat_set_error:
	ljmp	short_ask_data_error
answer_substat_set:
	ldb	axl,reclen
	cmpb	axl,#long_ask_len
	jne	short_ask_substat_set_error
	ld	sndpt,#sndadd
	inc	cx
	ldb	bxh,[cx]+
	cmpb	bxh,#setting_min_code
	jc	answer_setting_00
	stb	bxh,[sndpt]+
	cmpb	bxh,#01h
	jne	not_ask_module_name

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -