;********************************************************************
1.;接收一个字符,C=0接收正确,C=1接收出错,容错次数为3
;********************************************************************
recchar://接收字符
MOV.B#3,ERRCNT
RECCHAR1:
clr.bicflag1
MOV.B#8,CNTREG
CLR.BTRDATA
MOV.W#40000,DELAYCNT
RECC_WAIT:
BIT.B#ICSAM//判断对卡还是对ESAM操作
JNZRECC_IC
bit.b#samio,&pinb//对SAM操作
jzRECC_WAITSAM05
JMPRECC_DEL
RECC_WAITSAM05:
call#delay05etu
bit.b#samio,&pinb
JZRECC_BEGIN
JMPRECC_DEL
RECC_IC:
BIT.B#ICIO,&PINA//判起始位,不超过40000个CLK
JZRECC_WAITIC05
JMPRECC_DEL
RECC_WAITIC05:
CALL#DELAY05ETU
BIT.B#ICIO,&PINA
JZRECC_BEGIN
RECC_DEL:
DEC.WDELAYCNT
JNZRECC_WAIT
BIS.B#C,SR//超时,置C=1
RET
RECC_BEGIN:
call#reconebyte//
BIT.B#ICXOR
JNZRECC_CMP1
BIT.B#MXOR
JZRECC_OK
JMPRECC_CMPERR
RECC_CMP1:
BIT.B#MXOR//MXOR=1?
JZRECC_CMPERR//=0,ERR
RECC_OK:
call#delay1etu
clrc
ret
RECC_CMPERR:
BIT.B#ICSAM
JNZRECC_IC2
BIS.B#SAMIO,&PDIRB
BIC.B#SAMIO,&POUTB
CALL#DELAY1ETU
BIS.B#SAMIO,&POUTB
JMPRECC_AGAIN
RECC_IC2:
BIS.B#ICIO,&PDIRA
BIC.B#ICIO,&POUTA
CALL#DELAY1ETU
BIS.B#ICIO,&POUTA
RECC_AGAIN:
CALL#DELAY1ETU
DEC.BERRCNT
CMP.B#0,ERRCNT
JNZRECCHAR1
SETC
RET
;********************************************************************
2.;开始接收数据位,并计算校验位
;********************************************************************
reconebyte:
BIT.B#ICSAM
JNZROB_IC
rob_next:
call#delay1etu
bit.b#samio,&pinb
jzrob_1
xor.b#80h,icflag1
setc
jmprob_2
rob_1:
clrc
rob_2:
rrc.btrdata
sub.b#1,cntreg
jnzrob_next
call#delay1etu
bit.b#samio,&pinb
jzrob_out
bis.b#icxor
JMPROB_OUT
ROB_IC:
call#delay1etu
bit.b#ICio,&pinA
jzrob_IC1
xor.b#80h,icflag1
setc
jmprob_IC2
rob_IC1:
clrc
rob_IC2:
rrc.btrdata
sub.b#1,cntreg
jnzROB_IC
call#delay1etu
bit.b#ICio,&pinA
jzrob_out
bis.b#icxor
rob_out:
call#delay05etu
ret