📄 hilon.asm
字号:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;file name: modbus.asm
;creater: lily
;company: ESD Co.Ltd
;Starting time: 2003-3-1
;Description: CAN interface and Hilon B protocol
; communication between main MCU(80C196KC)and system computer
;version: 3.2
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
outcomm module
$nolist
$include(kc_sfrs.inc)
$include(memory.inc)
$include(ref_reg.inc)
$include(device.inc)
$include(flags.inc)
$list
rseg
extrn phsAprt,phsBprt,phsCprt:byte
extrn RLI,RLLowU,RLOverU,RLF,RLPF:byte ; temp register
extrn tmr1ov,second,minute,hour,day,month,year:byte
extrn msstart:word
extrn ykdoing,yx:byte
extrn station,status,rec_time:byte
extrn yk,ykct:word
funccode: dsb 1
recpt: dsw 1
sndpt: dsw 1
reclen: dsb 1
sndlen: dsb 1
recframe_num: dsb 1
soe_tempbuf: dsb 7
masaddr: dsb 1 ; source addr in receving
objectaddr: dsb 1 ; object addr in sending
sendbyte: dsb 1
send_index: dsb 1
rec_byte: dsw 1
dseg
extrn hdware_edition
extrn stationbk,baudrate:byte
extrn password,passwden
extrn systemtype
extrn llu_buf,i_buf:word
extrn ia,ib,ic,in:word
extrn ua,ub,uc,uab,ubc,uca:word
extrn freqa,freqb,freqc,freq:word
extrn pfa,pfb,pfc,pf:word
extrn wfpowl,wfpowh,wlpowl,wlpowh:word
extrn wpl
extrn power_buf,energy_buf:word
extrn eng_sum_buf:dword
extrn pulse_buf,signalname,inputfunc
extrn shortset,instset,gndset,lowvset,overvset
extrn lowfset,overfset,lowpfset
extrn shortseti,instseti,gndseti
extrn ptrate,ptratel,ptrateh,ctrate,nctrate:word
extrn soenum:byte,soept:word
extrn linkrelayLowU,linkrelayOverU,linkrelayI,linkrelayF,linkrelayPF:byte
extrn prt_time,yk_time:word
extrn yearbuf
extrn ykout:byte
extrn yksfttmrcmd,soemsk
extrn flagbk:byte
extrn prt_i_sw,prt_u_sw,prt_f_sw,prt_pf_sw:word
extrn prtctbuf:word
; compare dead zone
extrn dead_zone
dseg at savevalueadd
u_zone: dsw 1
i_zone: dsw 1
f_zone: dsw 1
pf_zone: dsw 1
p_zone:
p_zonel: dsw 1
p_zoneh: dsw 1
; already send remember value
public uarem,freqrem,cosrem
uabrem: dsw 1
ubcrem: dsw 1
ucarem: dsw 1
uarem: dsw 1
ubrem: dsw 1
ucrem: dsw 1
iarem: dsw 1
ibrem: dsw 1
icrem: dsw 1
inrem: dsw 1
freqrem:
freqarem: dsw 1 ; frequency*10
freqbrem: dsw 1
freqcrem: dsw 1
cosarem: dsw 1 ; PF*1000
cosbrem: dsw 1
coscrem: dsw 1
cosrem: dsw 1
wfpowarem:
wfpowareml: dsw 1
wfpowaremh: dsw 1
wfpowbrem:
wfpowbreml: dsw 1
wfpowbremh: dsw 1
wfpowcrem:
wfpowcreml: dsw 1
wfpowcremh: dsw 1
wlpowarem:
wlpowareml: dsw 1
wlpowaremh: dsw 1
wlpowbrem:
wlpowbreml: dsw 1
wlpowbremh: dsw 1
wlpowcrem:
wlpowcreml: dsw 1
wlpowcremh: dsw 1
public wfpowreml
wfpowrem:
wfpowreml: dsw 1
wfpowremh: dsw 1
wlpowrem:
wlpowreml: dsw 1
wlpowremh: dsw 1
dseg at recvadd
recadd: dsb 100h
recmsk equ 0ffh
dseg at sendadd
sndadd: dsb 80h
sndmsk equ 07fh
kseg
; constant define
extrn sys3p4w1ct
singleframe equ 00h
multiframe equ 60h
endframe equ 40h
ykfailure equ 0cch
ykopen equ 055h
ykclose equ 33h
broadcast_code equ 07fh
stat_insure equ 0eah
stat_set_normal equ 00h
stat_data_err equ 01h
stat_func_err equ 02h
stat_oper_fail equ 03h
setting_num equ 12h ; the total number of setting items
setting_min_code equ 014h ; modify over current
auto_send_apply equ 0e8h
yx_apply_ask equ 0f4h
yc1_apply_ask equ 061h
yc2_apply_ask equ 051h
yc3_apply_ask equ 041h
ym_apply_ask equ 085h
re_md_addr equ 0c7h
time_len equ 07h
substat_clr_len equ 03h
alarm_set_len equ 0eh
ptrate_len equ 0ah
inputfunc_len equ 0ah
set0_len equ 03h
seq_num_len equ 0eh
yk_oper_len equ 03h
short_ask_len equ 01h
long_ask_len equ 02h
set_stat_len equ 06h
;----------------------------------------------------------------
; define for motoring autosend
; rating value
u_rating_num1 equ 579 ; 220V
u_rating_num2 equ 263 ; 100V
i_rating_num equ 579 ; 7A/80%=8.8A
; step by 0.07A
f_rating_num equ 100 ; step by 0.1Hz
pf_rating_num equ 1000 ; step by 0.05
low_freq_limit equ 450
high_freq_limit equ 750
p_rating_num1 equ 3352
p_rating_num2 equ 1523
;================================================================
cseg at 2036h ; timer 2 capture
dcw t2cap_isr
;================================================================
cseg
extrn normal_name,crc_table,zero_buf
extrn adjust_systime_check,adjust_system_time
extrn compute_current
extrn compute_n_current
extrn compute_voltage
extrn compute_power
extrn get_energy_const
extrn update_led
extrn save_csboot0
extrn change_current_set
extrn change_ground_current_set
extrn change_lowvolt_set
extrn change_overvolt_set
extrn change_lowfreq_set
extrn change_overfreq_set
extrn change_lowpfactor_set
extrn yk_open_table,yk_close_table
extrn yk_exe_output
public comm_chip_reset,init_82c200
public init_outercomm
public outcomm_proc
public apply_ask_yx
;================================================================
; interrupt service routine
;----------------------------------------------------------------
cseg
t2cap_isr:
; used by outer communication
pusha
push ax
push bx
ldb axl,canir
jbs axl,1,can_snd_int ; if not send interrupt
jbs axl,0,can_rec_int
jbs axl,3,can_ovld_int
ldb axl,#0eh ; if error interrupt, clear overload, cancel send, release receive buffer
stb axl,cancmr
clrbit sendf ; for, send had stopped, so need clear send flag
sjmp exit_can_isr
can_ovld_int:
ldb axl,#08h ; clear overload
stb axl,cancmr
sjmp exit_can_isr
can_snd_int:
jbsm sendendf,can_send_con01 ; to send end frame
cmpb sndlen,#00h
jne can_send_con01
clrbit sendf ; no message left
sjmp exit_can_isr
can_send_con01:
call can_send ; continue send
sjmp exit_can_isr
can_rec_int:
clrb rec_time
jbsm rec_readyf,release_rec_buf_02 ; if already recevice a compelet frame but not be processed,drop it
ldb bxl,canrecvbuf+2
cmpb bxl,station
jne not_this_station_frame ; if not this station,maybe broadcast
cmpb bxl,#03
jnh not_this_station_frame
clrbit brdcastf
sjmp rec_this_station_frame
not_this_station_frame:
cmpb bxl,#broadcast_code
jne release_rec_buf_01 ; if not this station,nor broadcast
setbit brdcastf
ldb axl,canrecvbuf+1 ; receive interrupt
ldbze bx,axl
andb axl,#0fh
cmpb axl,#01h
jnh release_rec_buf_01
and bx,#0e0h ; 0e0h is more better than 0f0h,use later may cause error when type followed bit is 1
shr bx,#04
cmp bx,#03 ; <=3,not broadcast frame
jnh release_rec_buf_01
sjmp rec_this_station_frame_00
release_rec_buf_02:
ljmp release_rec_buf_01
rec_this_station_frame:
ldb axl,canrecvbuf+1 ; receive interrupt
ldbze bx,axl
andb axl,#0fh
cmpb axl,#01h
jnh release_rec_buf_01
and bx,#0e0h ; 0e0h is more better than 0f0h,use later may cause error when type followed bit is 1
shr bx,#04
cmp bx,#03 ; >3,not point to point frame
jh release_rec_buf_01
rec_this_station_frame_00:
ld bx,frame_type_tab[bx]
br [bx]
frame_type_tab:
dcw single_frame_rec
dcw single_frame_rec
dcw multi_frame_over_rec
dcw multi_frame_continue_rec
dcw single_frame_rec ; single broadcast frame
dcw single_frame_rec ; single broadcast frame
dcw multi_frame_over_rec ; broadcast over frame
dcw multi_frame_continue_rec ; broadcast continue frame
single_frame_rec:
ldb masaddr,canrecvbuf
andb masaddr,#7fh
decb axl
ld bx,#canrecvbuf+3
ld recpt,#recadd ; fill data form from the buffer start
ldb reclen,axl
mov_can_rec:
ldb axh,[bx]+
stb axh,[recpt]+
djnz axl,mov_can_rec
setbit rec_readyf
release_rec_buf_01:
sjmp release_rec_buf
multi_frame_continue_rec:
ldb bxl,canrecvbuf+3
cmpb r0,bxl
jne not_multi_start_frame
clrb recframe_num
ldb masaddr,canrecvbuf
andb masaddr,#7fh
ldb recframe_num,#01
decb axl
decb axl
ld bx,#canrecvbuf+4
ld recpt,#recadd
ldb reclen,axl
sjmp mov_can_rec_02
not_multi_start_frame:
cmpb bxl,recframe_num
jne release_rec_buf
incb recframe_num
decb axl
decb axl
ld bx,#canrecvbuf+4
addb reclen,axl
mov_can_rec_02:
ldb axh,[bx]+
stb axh,[recpt]+
djnz axl,mov_can_rec_02
sjmp release_rec_buf
multi_frame_over_rec:
ldb bxl,canrecvbuf+3
cmpb bxl,recframe_num
jne release_rec_buf
ld bx,canrecvbuf+4
ldb axl,reclen
cmpb bxl,axl
jne release_rec_buf
setbit rec_readyf
release_rec_buf:
ldb axl,#04h
stb axl,cancmr
exit_can_isr:
pop bx
pop ax
popa
ret
;----------------------------------------------------------------
can_send:
jbcm sendf,first_send_frame
jbsm sendendf,last_send_frame_01
sjmp not_first_send_frame
last_send_frame_01:
ljmp last_send_frame
first_send_frame:
setbit sendf
clrbit rec_readyf
subb axl,sndlen,#05h
jh first_can_more5
ldb axl,sndlen
clrb sndlen
can_less5: ; send single frame
ld bx,#cansendbuf
ldb axh,station
jbsm applyaskf,send_apply_ask00
orb axh,#80h ; PRI = 1,if apply ask yx or yc PRI = 0
send_apply_ask00:
clrbit applyaskf
stb axh,[bx]+
addb axh,axl,#singleframe+03 ; single frame+the addition length
stb axh,[bx]+ ; data length in this frame
ldb axh,objectaddr
stb axh,[bx]+
ldb axh,funccode ; function code
stb axh,[bx]+
ldb axh,status ; equal ctrolcode
stb axh,[bx]+
sjmp fill_can
first_can_more5: ; send first frame of multi
ldb axh,sndlen
addb axh,#02 ; send byte count
stb axh,sendbyte
subb sndlen,#04
ldb axl,#04 ; send data length from send buffer
ld bx,#cansendbuf
ldb axh,station
orb axh,#80h
stb axh,[bx]+ ; the first byte of the first frame of sending
addb axh,axl,#multiframe+04 ; multiframe+the addition length
stb axh,[bx]+ ; the second byte of the first frame of sending
ldb axh,objectaddr
stb axh,[bx]+ ; the third byte
ldb send_index,#00
stb send_index,[bx]+ ; the fourth byte
ldb axh,funccode
stb axh,[bx]+ ; the fifth byte
ldb axh,status
stb axh,[bx]+ ; the sixth byte
sjmp fill_can ; to fill 4 data
not_first_send_frame:
subb axl,sndlen,#06h
jh can_more6
setbit sendendf ; will send end frame next time
ldb axl,sndlen ; last send frame in multiframe
clrb sndlen
sjmp multi_send_not_first_com
can_more6:
ldb sndlen,axl
ldb axl,#06h
multi_send_not_first_com:
ld bx,#cansendbuf
ldb axh,station
orb axh,#80h
stb axh,[bx]+ ; the first byte of middle frame
addb axh,axl,#multiframe+02 ; multiframe+the addition length
stb axh,[bx]+ ; the second byte
ldb axh,objectaddr
stb axh,[bx]+ ; the third byte
incb send_index
stb send_index,[bx]+ ; the fourth byte
sjmp fill_can
last_send_frame:
ld bx,#cansendbuf
ldb axh,station
orb axh,#80h
stb axh,[bx]+ ; the first byte of over frame
ldb axh,#endframe+04 ; msgtype+the addition length
stb axh,[bx]+ ; the second byte of over frame
ldb axh,objectaddr
stb axh,[bx]+ ; the third byte of over frame
incb send_index
stb send_index,[bx]+ ; the fourth byte of over frame
ldb axh,sendbyte
stb axh,[bx]+ ; the fifth
stb r0,[bx]+ ; the sixth
clrbit sendendf
sjmp fill_send_end
fill_can:
ldb axh,[sndpt]+
stb axh,[bx]+
djnz axl,fill_can
fill_send_end:
ldb axl,#01h
stb axl,cancmr ; start send
ret
;================================================================
cseg
comm_chip_reset:
di
ldb hso_command,#01h ; low level reset 82c200
; clear bit,no interrupt,hso.1
add hso_time,timer1,#5
nop
nop
nop
nop
ldb hso_command,#31h ; normal level 82c200
; set bit,interrupt,hso.1
add hso_time,timer1,#7
nop
nop
nop
nop
ei
ret
;================================================================
; initialize devices
;----------------------------------------------------------------
init_82c200:
; initialize CAN controller 82C200
pusha
ldb axl,#01h
stb axl,cancr ; disable all interrupt, reset mode
ldb axl,#0eh
stb axl,cancmr ; cancel send, release receive buffer and overload
ldb axl,#83h
stb axl,canacr
ldb axl,#83h
stb axl,canamr ; 好像可以利用acr,amr来使装置只接收本站报文
ldbze ax,baudrate
cmpb axl,#05
jnh baudrate_correct
ld ax,#02 ; use default
stb axl,baudrate
baudrate_correct:
shl ax,#01
ld ax,baudrate_table[ax]
stb axh,canbtr0 ; communicate rate
stb axl,canbtr1
ldb axl,#0fah
stb axl,canocr ; 推挽输出,正常方式
ldb axl,baudrate ; 0 1 2 3 4 5 6 7
stb axl,cancdr ; /2 /4 /6 /8 /10 /12 /14 /1
ldb axh,#0ffh
normal_can:
ldb axl,#1eh
stb axl,cancr ; enable all interrupt, normal mode
skip r0 ; wait for a short while
skip r0
skip r0
skip r0
ldb axl,cancr
jbc axl,0,can_normaled
djnz axh,normal_can
can_normaled:
ldb r0,canir ; clear all interrupt
popa
ret
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
baudrate_table:
; table for canbtr, 125k,100k,50k,20k,10k,5k
dcw 031ch,432fh,472fh,532fh,672fh,7f7fh
;----------------------------------------------------------------
init_outercomm:
call autosending_yc_set
ld recpt,#recadd
ldb reclen,#00h
ret
;----------------------------------------------------------------
autosending_yc_set:
ldbze ax,dead_zone ; caculate the dead_zone of all items
cmp r0,ax
jne autosending_yc_set_00
setbit yc_forbidf
ret
autosending_yc_set_00:
clrbit yc_forbidf
ld ax,ptratel
ld bx,ptrateh
cmp r0,bx
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -