📄 p300.asm
字号:
;-----------------------------------------
;sssc_p300 cummunication program
;author:Wang Zhi Rong
;date:June 24,1999
;resorece destribute:
;define:
rst* bit p1.1
sdi bit p1.2
sdo bit p1.3
sclk bit p1.4
int* bit p1.5
cs* bit p1.6
as_p300 bit 20h.0 ;INT asserted withen t(reset)
cplt_p300 bit 20h.1 ;sending or writing a byte data complete
ir_err bit 20h.2 ;IR command err
w_r bit 20h.3 ;incate writing or reading
ini_ok bit 20h.4
ini_fail bit 20h.5
rri_ok bit 20h.6
wti_ok bit 20h.7
pr_ok bit 21h.0
inerface_flags data 30h
main: mov sp,#67h
mov p1,#0ffh
ini_loop: lcall ini_p300
jnb ini_ok
clr ini_ok
lcall wth
jnb wth_ok,ini_loop
clr wth_ok
lcall wti
jnb wti_ok,ini_loop
;-----------------------------------------
;Name:WBYTE
;Function:Write a byte data to p300
;input:b--The data waiting to write
;output:no
wbyte: mov r7,#8
mov a,b
wbyte_loop:rlc a
jnc clr_sdo
setb sdo
sjmp wbyte_netx
clr_sdo:clr sdo
wbyte_next:clr sclk
nop
setb sclk
nop
djnz r7,wbyte_loop
ret
;-----------------------------------------
;Name:RBYTE
;Function:Read a byte data from p300
;input: no
;output:b--the data readed from p300
Rbyte: mov r7,#8
rbyte_loop:clr sclk
nop
setb sclk
nop
mov c,sdi
rlc a
djnz r7,rbyte_loop
mov b,a
ret
;-----------------------------------------
;Name:wcommand
;function:write datas followed by the command to p300
;input: com_name--command name
; data_leng--data length
; r0--the starting address of datas waiting to write
;output: p300_err
wcommand: clr p300_err
clr cs* ;send command code
mov b,com_name
lcall wbyte
lcall del1ms
jb cmpt_p300,wcommand1
setb cs*
setb p300_err
ret
wcommand1:mov b,data_leng
lcall wbyte
jb cplt_p300,wcommand_2
setb p300_err
ret
wcommand_2:clr cplt_p300
mov r7,data_leng
wcommand_loop:mov b,@r0
lcall wbyte
lcall del1ms
jnb cmpt_p300,wcommand_err
clr cmpt_p300
inc r0
djnz r7,wcommand_loop
setb cs*
ret
wcommand_err:setb cs*
setb p300_err
ret
;----------------------------------------
;Name:rcommand
;function:read datas followed by the command from p300
;input: com_name--command name
; data_leng--data length
; r0--the starting addess of datas readed from p300
;output: p300_err
rcommand: clr p300_err
clr cs* ;send command code
mov b,com_name
lcall rbyte
lcall del1ms
jb cmpt_p300,rcommand1
setb cs*
setb p300_err
ret
rcommand1:mov r0,#3fh
lcall rbyte
jb cmpt_p300,rcommand2
setb p300_err
ret
rcommand_2:mov @r0,b
clr cmpt_p300
mov r7,data_leng
rcommand_loop:lcall rbyte
lcall del1ms
jnb cmpt_p300,rcommand_err
clr cmpt_p300
mov @r0,b
inc r0
djnz r7,wcommand_loop
setb cs*
ret
rcommand_err:setb cs*
setb p300_err
ret
;------------------------------------------
;Name:int_p300
;function: setb as_p300 flags if p300 INT asserted withen 1ms
;input: no
;output: as_p300=1 ,cplt_p300
int_p300: jb w_r,int_1
setb as_p300
reti
int_1: setb cplt_p300
reti
;------------------------------------------
;Name:ini_p300
;function:intialization p300
;input:n0
;output:
ini_p300:
lcall del10ms
mov command,#04
mov data_leng,#1
mov r0,#40h
seb w_r
lcall rcommand
clr w_r
jnb p300_err,int_2
ret
int_2: mov a,40h
jb acc.0,ini_4
mov b,#01
lcall wbyte
lcall del1ms
jnb cmpt_p300,int_3
mov command,#04
mov data_leng,#1
mov r0,#40h
seb w_r
lcall rcommand
clr w_r
int_3: sjmp int_2
int_4: clr cmpt_p300
mov 40h,#01111000b
mov 41h,#01 ;group addess=0001
mov 42h,#0
mov 43h,#01 ;device addess=0001
mov 44h,#0
mov 45h,#01 ;system addess=0001
mov 46h,#0
mov command,#03 ;lw code=03
mov data_leng,#7
mov r0,#40h
lcall wcommand
jb p300_err,int_5 ;if writing ok,reading from p300
mov command,#02 ;LR code=02
mov data_leng,#7
mov r0,#50h
setb w_r
lcall rcommand
clr w_r
jb p300_err,int_5
mov r0,#40h
mov r1,#50h
mov a,@r0
cjne a,@r1,int_5
setb int_ok
ret
int_5: setb int_fail
ret
;-----------------------------------------------------
;Name: RRIcommand
;function:receive NPDU
;input: no
;output: the starting addess:r0=50h;rri_ok
RRIcommand:clr rri_ok
clr p300_err
mov command,#0ah ;RRI code=0ah
mov data_ leng,#10
mov r0,#50h
setb w_r
lcall rcommand
clr w_r
jb p300_err,rri_1
setb rri_ok
ret
rri_1: clr p300_err
ret
;---------------------------------------------------------
;Name: WTIcommand
;function: transfor NPDU
;input: the starting addess:r0=40h
;output:wti_ok
WTIcommand:clr p300_err
clr wti_ok
mov command,#0BH ;WTI code=0bh
mov data_leng,#10
mov r0,#40h
seb w_r
lcall wcommand
clr w_r
jb p300_err,wti_1
setb wti_ok
ret
wti_1: clr p300_err
ret
;----------------------------------------------------------
;Name: WTHcommand
;function: transfor header
;input: the staring addess:r0=40h
;output:wth_ok
WTHcommand: :clr p300_err
clr wth_ok
mov command,#0dH ;WTH code=0dh
mov data_leng,#10
mov r0,#40h
seb w_r
lcall wcommand
clr w_r
jb p300_err,wth_1
setb wti_ok
ret
wth_1: clr p300_err
ret
;-------------------------------------------------------------
;Name:PRcommand
;function:receive header&NPDU
;input: the staring addess:ro=40h
;output:pr_ok
PRcommand: :clr p300_err
clr pr_ok
mov command,#08H ;pr code=08h
mov data_leng,#19
mov r0,#40h
seb w_r
lcall rcommand
clr w_r
jb p300_err,wth_1
setb pr_ok
ret
wth_1: clr p300_err
ret
;----------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -