发表于:2004-04-23 22:51:00
7楼
高手们,帮忙看一下啊,为什么这个自发自收的程序一发送就出错,显示是帧开始出错,状态寄存器显示为0F4H
;CAN控制器SJA1000片外存储器起始地址为0000H
MODE EQU 0000H
CMR EQU 0001H
SR EQU 0002H
IR EQU 0003H
IER EQU 0004H
BTR0 EQU 0006H
BTR1 EQU 0007H
OCR EQU 0008H
ALC EQU 000BH
ECC EQU 000CH
EWLR EQU 000DH
RXERR EQU 000EH
TXERR EQU 000FH
TXB EQU 0010H
RXB EQU 0010H
RXCMD EQU 0015H
RTRDLC EQU 0010H
ACR EQU 0010H
AMR EQU 0014H
RMC EQU 001DH
RBSA EQU 001EH
CDR EQU 001FH
jieshou EQU 30H ;CPU里接收报文存储区
fasong EQU 40H ;CPU里发送报文存储区
ORG 0000H
LJMP MAIN
ORG 0003H
LJMP CUOWU
ORG 0030H
MAIN:
MOV SP,#6FH ;SP初始化
MOV R0,#6FH
CLR A
CLAIR:
MOV @R0,A
DJNZ R0,CLAIR
MOV A,#0AAH
MOV R0,#4
MOV R1,#40H
lOOP1:
MOV @R1,A
INC R1
DJNZ R0,LOOP1
LCALL CANINI
MOV IE,#81H
MOV P1.0,#0
LCALL TDATA
TLOOP:
MOV DPTR,#SR
MOVX A,@DPTR
JB ACC.3,PUT1
JMP TLOOP
PUT1:
SETB P1.0
LCALL CANREC
RET
CANINI:
MOV DPTR,#MODE
MOV A,#01H
MOVX @DPTR,A
MOV DPTR,#CDR
MOV A,#88H
MOVX @DPTR,A
MOV DPTR,#IER
MOV A,#8CH
MOVX @DPTR,A
MOV DPTR,#AMR
MOV R0,#4
MOV A,#0FFH
AMRINI:
MOVX @DPTR,A
INC DPTR
DJNZ R0,AMRINI
MOV DPTR,#ACR
MOV R1,#4
MOV A,#80H
ACRINI:
MOVX @DPTR,A
INC DPTR
DJNZ R1,ACRINI
MOV DPTR,#BTR0
MOV A,#07H
MOVX @DPTR,A
MOV DPTR,#BTR1
MOV A,#0FFH
MOVX @DPTR,A
MOV DPTR,#OCR
MOV A,#0AAH
MOVX @DPTR,A
MOV DPTR,#RBSA
MOV A,#0
MOVX @DPTR,A
MOV DPTR,#TXERR
MOV A,#0
MOVX @DPTR,A
MOV DPTR,#ECC
MOVX @DPTR,A
MOV DPTR,#MODE
MOV A,#04H
MOVX @DPTR,A
RET
TDATA:
MOV DPTR,#SR
MOVX A,@DPTR
JB ACC.4,TDATA
TS20:
MOVX A,@DPTR
JNB ACC.3,TS20
TS21:
MOVX A,@DPTR
JNB ACC.2,TS21
TS22:
MOV DPTR,#TXB
MOV A,#84H
MOVX @DPTR,A
MOV R0,#4
LOOP2:
INC DPTR
MOV A,#80H
MOVX @DPTR,A
DJNZ R0,LOOP2
MOV R0,#4
MOV R1,#fasong
LOOP3:
INC DPTR
MOV A,@R1
MOVX @DPTR,A
INC R1
DJNZ R0,LOOP3
MOV DPTR,#CMR
MOV A,#10H
MOVX @DPTR,A
RET
CUOWU:
MOV DPTR,#IR
MOVX A,@DPTR
MOV 50H,A
MOV DPTR,#ECC
MOVX A,@DPTR
MOV 51H,A
SETB P1.2
RET
CANREC:
MOV DPTR,#SR
MOVX A,@DPTR
ANL A,#0C3H
JNZ TIAO
RET
TIAO:
JNB ACC.7,PROCI
BUSERR:
MOV DPTR,#IP
MOVX A,@DPTR
MOV DPTR,#MODE
MOV A,#08H
MOVX @DPTR,A
RET
NOP
PROCI:
MOV DPTR,#IR
MOVX A,@DPTR
JNB ACC.3,OTHER
OVER:
MOV DPTR,#CMR
MOV A,#0CH
MOVX @DPTR,A
RET
NOP
OTHER:
JB ACC.0,RECE
LJMP RECOUT
NOP
RECE:
MOV DPTR,#RXB
MOV R1,#jieshou
MOVX A,@DPTR
MOV @R1,A
ANL A,#0FH
ADD A,#4
MOV R6,A
RDATA0:
INC DPTR
INC R1
MOVX A, @DPTR
MOV @R1,A
DJNZ R6,RDATA0
SETB P1.1
MOV DPTR,#CMR
MOV A,#04H
MOVX @DPTR,A
RECOUT:
MOV DPTR,#ALC
MOVX A,@DPTR
MOV DPTR,#ECC
MOVX A, @DPTR
NOP
RET