CAN接口匯編程序
ORG0000H
LJMPMAIN
ORG0003H
LJMPCANINT0
ORG000BH
LJMPT0-INTERRUPT
ORG0100H
MAIN:
MOV R0,#07FH
CLRA
MOV @R0,A
DJNZR0,$_1
MOV @R0,A
MOV SP,#60H
LCALLSJA1000_INIT0
LCALLDISPLAY_INIT
LCALLT0INIT
SETBPX0
SETBIT0
SETBEX0
SETBET0
SETBTR0
SETBEA
LOOPER:
JNBRCV_GOOD,LOOPER2
CLRRCV_GOOD
LCALLRCVDATAPRG
LOOPER2:
JNBSEC_FLAG,LOOPER3
CLRSEC_FLAG
LCALLSENDDATA_PRG
LOOPER3:
JNBERR_FLAG,LOOPER4
CLRERR_FLAG
LCALLERR_PRG
LOOPER4:
JNBOVER_FLAG,LOOPER5
CLROVER_FLAG
LCALLDOVER_PRG
LOOPER5:
JNBDS_ENDLFLAG,LOOPER6
CLRDS_END_FLAG
LCALLDSEND_PRG
LOOPER6:
JNBWULFLAG,LOOPER7
CLRWULFLAG
LCALLWOKE_PRG
LOOPER7:
AJMPLOOPER
SJA1000_INIT0:
LCALLCAN_CREATE_COMMUNATION
MOV R7,#12
LCALLCAN_SET_BANDRATE
MOV R7,#0A8H
MOV R6,#0ffH
LCALLCAN_SET_OBJECT
MOV R7,#0AAH
MOV R6,#048H
LCALLCAN_SET_OUTCLK
LCALLCAN_QUIT_RETMODEL
MOV DPTR,#REG_CONTROL
MOV A,#01EH
MOV X@DPTR,A
CLRF0
RET
ERR_PRG:
LCALLCAN_ENTER_RETMODEL
LCALLSJA1000_INIT0
MOV ERROR_STATUS,#0FCH
LCALLDISP_ERROR
RET
DSENDLPRG:
LCALLDISP_OK
RET
RCVDATA_PRG:
MOV R0,#RCV_DATA_BUF1
LCALLCAN_DATA_RECEIVE
MOV R7,#04H
LCALLCAN_CMD_PRG
RET
SENDDATA_PRG:
MOV R0,#SEND_DATA_BUFl
MOV @R0,#0AFH
INCR0
MOV @R0,#08H
MOV A,TEST_DATA
INCR0
MOV @R0,A
MOV R0,#SEND_DATA_BUFl
LCALLCAN_DATA_WRITE
MOV R7,#01
LCALLCAN_CMD_PRG
RET
TO_INIT:
MOV A,TMOD
ANLA,#0F0H
ORLA,#’01H
MOV TMOD,A
MOV TH0,#0FCH
MOV TL0,#066H
MOV 3AH,#00H
RET
CAN_INT0:
PUSHDPH
PUSHDPL
PUSHPSW
PUSHACC
MOV DPTR,#REGINTERRUPT
MOV XA,@DPTR
MOV SAVE_INT_INFO,A
JNBACC.0,CAN_INTl
SETBRCV_GOOD
CAN_INT1:
MOV A,SAVE_INT_INFO
JNBACC.2,CANINT2
SETBERR_FLAG
CAN_INT2:
POPACC
POPPSW
POPDPL
POPDPH
RETI
TO_INTERRUPT:
PUSHDPH
PUSHDPL
PUSHPSW
PUSHACC
MOV TH0,#80H
MOV TL0,#26H
LCALLDISPLAY
INC3AH
MOV A,3AH
CJNEA,#40H,TO_QUIT
MOV 3AH,#00H
SETBSEC_FLAG
INCTEST_DATA
TO_QUIT:
POPACC
POPPSW
POPDPL
POPDPH
RETI
DISP_ERROR:
MOV R0,#DISPLAYBUFO+1
MOV @R0,#0EH
MOV R0,#DISPLAYBUFO+2
MOV @R0,#l0H
INCR0
MOV A,ERROR_STATUS
ANLA,#0F0H
SWAPA
MOV @R0,A
INCR0
MOV A,ERROR_STATUS
ANLA,#0FH
MOV @R0,A
RET
DISP_OK:
MOV R0,#DISPLAYBUFO+1
MOV @R0,#11H
MOV R0,#DISPLAYBUFO+2
MOV R0,#l0H
MOV R0,#DISPLAYBUFO+3
MOV A,RCV_DATA_BUF3
ANLA,#0F0H
SWAPA
MOV @R0,A
INCR0
MOV A,RCV_DATA_BUF3
ANLA,#0FH
MOV @R0,A
RET_
$INCLUDE(SJA_CANFunc.ASM)
$include(display_s.inc)
END
CAN_CREATE_COMMUNATION:
MOV DPTR,#REG_TEST
MOV XA,.DPTR
MOV A,#0AAH
MOV X@DPTR,A
SETBF0
MOV XA,.DPTR
CJNEA,#OAAH,CAN_CM_QUIT
MOV A,#055H
MOV X@DPTR,A
MOV XA,@DPTR
CJNEA,#055H,CAN_CM_QUIT
CLRA
MOV X@DPTR,A
CLRF0
CAN_CM_QUIT:
RET
CAN_ENTER_RETMODEL:
MOV DPTR,#REG_CONTROL
MOV XA,@DPTR
ORLA,#01H
MOV X@DPTR,A
CLRDWF0
MOV XDWA,@DPTR
JBACC.0,CAN_ER_QUIT
SETBF0
CAN_ER_QUIT:
RET
CAN-QUIT-RETMODEL:
MOV DPTR,#REG_CONTROL
MOV XA,@DPTR
ANLA,#OFEH
MOV X@DPTR,A
CLRF0
MOV XA,@DPTR
JNBACC.0,CAN_QR_QUIT
SETBF0
CAN_QR_QUIT:
RET
CAN_SET_BANDRATE:
MOV A,R7
CLRCY
SUBBA,#13
SETBF0
JNCCAN_SETBR_QUIT
CLRF0
MOV A,R7
RLA
MOV DPTR,#CANSETBR
MOV CA,@A+DPTR
MOV R5,A
MOV A,R7
RLA
INCA
MOV CA,@A+DPTR
MOV R6,A
MOV DPTR,#REGLBTR0
MOV A,R5
MOV X.DPTR,A
SETBF0
MOV XA,QDPTR
XRLA,R5
JNZCAN_SETBR_QUIT
INCDPTR
MOV A,R6
MOV X@DPTR,A
MOV XA,@DPTR
XRLA,R6
JNZCAN_SETBR_QUIT
CLRF0
CAN_SETBR_QUIT:
RET
CAN_SETBR:
DB0EFH,0FFH
DB0D7H,0FFH
DB0CBH,0FFH
DB0C5H,0FFH
DB0C9H,0A9H
DB0C2H,0FFH
DB84H,0A7H
DB82H,025H
DB01H,045H
DB01H,025H
DB01H,012H
DB00H,025H
DB00H,012H
CAN_SET_OBJECT:
MOV DPTR,#REG_ACR
MOV A,R7
MOV X@DPTR,A
MOV XA,@DPTR
SETBF0
XRLA,R7
JNZCAN_SETO_QUIT
CLRF0
INCDPTR
MOV A,R6
MOV X@DPTR,A
MOV XA,DPTR
SETBF0
XRLA,R6
JNZCAN_SETO_QUIT
CLRF0
CAN_SETO_QUIT:
RET
CAN_SET_OUTCLK:
MOV D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