首 页文档资料下载资料维修视频包年699元
请登录  |  免费注册
当前位置:精通维修下载 > 文档资料 > 家电技术 > 单元电路介绍 > 其它电路
CAN接口汇编程序
来源:本站整理  作者:佚名  2011-02-05 21:44:13



CAN接口汇编程序

ORG     0000H
LJMP     MAIN
ORG     0003H
LJMP     CANINT0                    
ORG     000BH
LJMP    T0-INTERRUPT
ORG     0100H
MAIN:
MOV      R0,#07FH
CLR     A
MOV     @R0,A
DJNZ     R0,$_1
MOV     @R0,A
MOV      SP,#60H                        
LCALL     SJA1000_INIT0                    
LCALL     DISPLAY_INIT                    
LCALL     T0INIT                        
SETB     PX0                            
SETB     IT0                            
SETB     EX0                            
SETB     ET0 
SETB     TR0                            
SETB     EA                            
LOOPER:
JNB     RCV_GOOD,LOOPER2                
CLR     RCV_GOOD                    
LCALL     RCVDATA PRG                    
LOOPER2:
JNB     SEC_FLAG,LOOPER3
CLR     SEC_FLAG 
LCALL     SENDDATA_PRG                
LOOPER3:
JNB     ERR_FLAG,LOOPER4
CLR     ERR_FLAG
LCALL     ERR_PRG                        
LOOPER4:
JNB         OVER_FLAG,LOOPER5            
CLR     OVER_FLAG
LCALL     DOVER_PRG                    
LOOPER5: 
JNB         DS_ENDLFLAG,LOOPER6            
CLR     DS_END_FLAG
LCALL     DSEND_PRG
LOOPER6:
JNB         WUL FLAG,LOOPER7            
CLR     WUL FLAG
LCALL     WOKE_PRG                    
LOOPER7:
AJMP     LOOPER
SJA1000_INIT0:                         
LCALL     CAN_CREATE_COMMUNATION
MOV      R7,#12                        
LCALL     CAN_SET_BANDRATE            
MOV      R7,#0A8H                        
MOV      R6,#0ffH                        
LCALL     CAN_SET_OBJECT
MOV      R7,#0AAH                        
MOV      R6,#048H 
LCALL     CAN_SET_OUTCLK             
LCALL     CAN_QUIT_RETMODEL            
MOV      DPTR,# REG_CONTROL
MOV      A,#01EH                        
MOV X     @DPTR,A
CLR     F0
RET

ERR_PRG:
LCALL     CAN_ENTER_RETMODEL        
LCALL     SJA1000_INIT0                    
MOV     ERROR_STATUS,#0FCH            
LCALL     DISP_ERROR                    
RET
DSENDLPRG:
LCALL     DISP_OK                        
RET 
RCVDATA_PRG:
MOV      R0,#RCV_DATA_BUF1
LCALL     CAN_DATA_RECEIVE            
MOV      R7,#04H
LCALL     CAN_CMD_PRG
RET
SENDDATA_PRG:
MOV      R0,#SEND_DATA_BUFl
MOV     @R0,#0AFH
INC         R0                            
MOV     @R0,#08H
MOV      A,TEST_DATA
INC         R0                             
MOV      @R0,A
MOV      R0,#SEND_DATA_BUFl
LCALL     CAN_DATA_WRITE
MOV      R7,#01
LCALL     CAN_CMD_PRG
RET
TO_INIT:
MOV      A,TMOD                        
ANL     A,#0F0H
ORL     A,#’01H
MOV      TMOD,A                        
MOV      TH0,#0FCH
MOV      TL0,#066H
MOV      3AH,# 00H
RET
CAN_INT0:                            
PUSH     DPH                            
PUSH     DPL
PUSH     PSW                            
PUSH     ACC
MOV      DPTR,#REG INTERRUPT            
MOV X     A,@DPTR
MOV      SAVE_INT_INFO,A                
JNB         ACC.0,CAN_INTl                
SETB    RCV_GOOD                    
CAN_INT1:                             
MOV      A,SAVE_INT_INFO
JNB         ACC.2,CAN INT2                
SETB     ERR_FLAG
CAN_INT2:
POP         ACC
POP         PSW
POP         DPL
POP         DPH
RETI
TO_INTERRUPT:
PUSH     DPH                            
PUSH    DPL
PUSH     PSW                            
PUSH     ACC
MOV      TH0,#80H
MOV      TL0,#26H
LCALL     DISPLAY
INC         3AH                        
MOV      A,3AH
CJNE     A,#40H,TO_QUIT                
MOV      3AH,#00H
SETB     SEC_FLAG
INC        TEST_DATA                    
TO_QUIT:
POP         ACC                            
POP         PSW
POP         DPL
POP         DPH
RETI
DISP_ERROR:
MOV      R0,#DISPLAYBUFO+1            
MOV     @R0,#0EH
MOV      R0,#DISPLAYBUFO+2
MOV     @R0,#l0H
INC         R0                            
MOV      A,ERROR_STATUS
ANL     A,#0F0H
SWAP     A
MOV     @R0,A
INC         R0
MOV      A,ERROR_STATUS
ANL     A,# 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
ANL     A,#0F0H                            
SWAP     A
MOV     @R0,A
INC         R0
MOV      A,RCV_DATA_BUF3
ANL     A,#0FH
MOV     @R0,A
RET_
$INCLUDE(SJA_CANFunc. ASM)             
$include( display_s. inc)
END
CAN_CREATE_COMMUNATION:
MOV      DPTR,#REG_TEST                    
MOV X     A,.DPTR
MOV      A,#0AAH                            
MOV X    @DPTR,A
SETB     F0
MOV X     A,.DPTR
CJNE     A,#OAAH,CAN_CM_QUIT                
MOV      A,#055H                        
MOV X     @DPTR,A
MOV X     A,@DPTR
CJNE     A,#055H,CAN_CM_QUIT                
CLR     A
MOV X    @DPTR,A
CLR     F0
CAN_CM_QUIT:
RET
CAN_ENTER_RETMODEL:                
MOV      DPTR,#REG_CONTROL                
MOV X     A,@DPTR
ORL     A,#01H                            
MOV X    @DPTR,A 
CLR     DWF0
MOV X     DWA,@DPTR                        
JB         ACC.0,CAN_ER_QUIT
SETB     F0
CAN_ER_QUIT:
RET
CAN-QUIT-RETMODEL:
MOV     DPTR,#REG_CONTROL                
MOV X     A,@DPTR
ANL     A,#OFEH                            
MOV X    @DPTR,A 
CLR     F0
MOV X     A,@DPTR
JNB         ACC. 0,CAN_QR_QUIT                
SETB     F0
CAN_QR_QUIT:
RET
CAN_SET_BANDRATE:                         
MOV      A,R7
CLR     CY
SUBB     A,#13
SETB     F0
JNC         CAN_SETBR_QUIT                    
CLR     F0 
MOV      A,R7
RL         A
MOV      DPTR,#CAN SETBR                    
MOV C     A,@A+DPTR 
MOV      R5,A                                
MOV      A,R7                                
RL         A
INC         A
MOV C     A,@A+DPTR
MOV      R6,A                                
MOV      DPTR,# REGLBTR0                    
MOV      A,R5                                
MOV X .    DPTR,A
SETB     F0
MOV X     A,QDPTR
XRL     A,R5
JNZ         CAN_SETBR_QUIT                    
INC         DPTR
MOV      A,R6
MOV X     @DPTR,A
MOV X     A,@DPTR
XRL     A,R6                            
JNZ         CAN_SETBR_QUIT
CLR     F0
CAN_SETBR_QUIT:
RET
CAN_SETBR:
DB     0EFH,0FFH                            
DB     0D7H,0FFH                            
DB     0CBH,0FFH                            
DB     0C5H,0FFH                            
DB     0C9H,0A9H                            
DB     0C2H,0FFH                            
DB     84H,0A7H                                
DB     82H,025H                                
DB     01H,045H                                
DB    01H,025H                                
DB    01H,012H                                
DB     00H,025H                                
DB     00H,012H                                
CAN_SET_OBJECT:
MOV      DPTR,#REG_ACR                    
MOV      A, R7 
MOV X     @DPTR,A
MOV X     A,@DPTR
SETB     F0
XRL     A,R7                                
JNZ         CAN_SETO_QUIT
CLR     F0
INC         DPTR                            
MOV      A,R6
MOV X     @DPTR,A
MOV X     A,DPTR
SETB     F0
XRL     A,R6                                
JNZ         CAN_SETO_QUIT
CLR     F0
CAN_SETO_QUIT:
RET
CAN_SET_OUTCLK:
MOV      DPTR,#REG_OCR                    
MOV      A,R7
MOV X     @DPTR,A
MOV X     A,@ DPTR                        
SETB     F0
XRL     A,R7
JNZ     CAN_SETOQ_QUIT
CLR        F0
MOV      DPTR,#REG CDR                
MOV      A,R6
MOV X     @DPTR,A
MOV      B,A
MOV X     A,@ DPTR
SETB     F0
XRL     A,R6                                
JNZ         CAN_SETOC_QUIT
CLR     F0
CAN_SETOC_QUIT
RET
CAN     DATA WRITE:
MOV      DPTR,# REG_STATUS
MOV X     A,@DPTR
SETB     F0
JNB         ACC.3,CAN_DW_QUIT
CLR     F0
MOV X     A,@DPTR
SETB     F0
JNB         ACC.2,CAN_DW_QUIT
CLR     F0
INC         R0
MOV      A, R0
DEC     R0
MOV      DPTR,#REG_TxBufferl
JB         ACC.4, CAN_WYB
ANL     A,#0FH                            
ADD     A,#02H                            
MOV      R7,A
AJMP     CAN_WRTXBUF
CAN_WYB:
MOV      R7,#02                            
CAN_WRTXBUF:
MOV      A,R0                                
MOV X .    DPTR,A
SETB     F0
MOV X     A,@DPTR                            
XRL     A,.R0 
JNZ         CAN_DW_QUIT                    
CLR     F0                                
INC         R0 
INC         DPTR
DJNZ     R7,CAN_WRTXBUF                    
CAN_DW_QUIT:
RET
CAN_DATA_RECEIVE:
MOV      DPTR,井REG_STATUS                
MOV X     A,@DPTR                            
SETB     F0
JNB         ACC.0,CAN_DR_QUIT
CLR     F0
MOV      DPTR,#REG_RxBuffer2
MOV X     A,@DPTR
MOV      DPTR,#REG RxBufferl
JB         ACC. 4,CAN_RCVYB
ANL     A,#0FH                            
ADD     A,# 02H                            
MOV      R7,A
AJMP     CAN_RCVDATA
CAN_RCVYB:
MOV      R7,#02                            
CAN_RCVDATA:                            
MOV X     A,.DPTR
MOV     @R0,A
INC         DPTR
INC         R0
DJNZ     R7,CAN RCVDATA
CAN_DR_QUIT:
RET
CAN_CMD_PRG:
MOV      A,R7
CJNE     A,#01,CAN_CMDl                    
MOV      DPTR,#REG COMMAND                
MOV X     @DPTR,A                            
CLR     F0
RET
CAN_CMDl:
CJNE     A,#02,CAN_CMD2
MOV      DPTR,#REG STATUS                    
MOV X     A,@DPTR                            
SETB     F0
JB         ACC.5,CAN_CMDLQUIT
CLR     F0
CAN_CMD_QUIT:
RET
CAN_CMD2:
CJNE    #04,CAN CMD3                        
MOV      DPTR,# REG_COMMAND                
MOV X     @DPTR,A                            
NOP
NOP
MOV      DPTR,#REG STATUS                    
MOV X     A,.DPTR
SETB     F0
JB         ACC.0,CAN_DB_QUIT
CLR     F0
CAN_DB_QUIT:
RET
CAN_CMD3:
CJNE     A,#08,CAN_CMD4                    
MOV      DPTR,# REG_COMMAND                
MOV X     @DPTR,A                            
NOP
NOP
MOV      DPTR,#REG_STATUS                
MOV X     A,@DPTR
SETB     F0
JB         ACC.1,CAN_DOVER_QUIT
CLR     F0
CAN_DOVER_QUIT:
RET
SCAN CMD4:
CJNE     A,#10H,CAN_CMD5                    
MOV      DPTR,#REG_COMMAND                
MOV X    @DPTR,A                            
CLR     F0
CAN     CMD5:
RET

关键词:

文章评论评论内容只代表网友观点,与本站立场无关!

   评论摘要(共 0 条,得分 0 分,平均 0 分)
Copyright © 2007-2017 down.gzweix.Com. All Rights Reserved .
页面执行时间:273,246.10000 毫秒