📄 can_ref.lst
字号:
00206 ;
00207 ; Shift left 2 byte integer once.
00208 iShiftL macro iVar
00209 bcf _C ; clear carry bit
00210 rlf iVar,F
00211 rlf iVar+1,F
00212 endm
00213
00214 ; Shift right 2 byte integer once.
00215 iShiftR macro iVar
MPASM 02.20.15 Intermediate CAN_REF.ASM 2-8-2000 13:27:59 PAGE 19
CAN_Ref Design
LOC OBJECT CODE LINE SOURCE TEXT
VALUE
00216 bcf _C ; clear carry bit
00217 rrf iVar+1,F
00218 rrf iVar,F
00219 endm
00220
00221 ; Increment 2 byte integer
00222 intInc macro iVar
00223 incf iVar,F
00224 skipNZ
00225 incf iVar+1,F
00226 endm
00227
00228 ;
00229 ;; --------------------------------------------------------
00230 ;; Set TRM1H 8 bit clock
00231 ; TMR1H: 256 uSec tics with maximum of 1/2 rollover = 32.768 msec maximum
00232 ;; --------------------------------------------------------
00233 Set1HClock macro bClk,Value
00234 movfw TMR1H
00235 addlw Value
00236 movwf bClk
00237 endm
00238
00239 ;; --------------------------------------------------------
00240 ;; Jump to jLabel if TMR1H (low byte) < bClk
00241 ;; --------------------------------------------------------
00242 jmp1HNotYet macro bClk,jLabel
00243
00244 movfw TMR1H
00245 subwf bClk,W
00246 andlw 0x80
00247 jmpZ jLabel
00248 endm
00249
00250 ;; --------------------------------------------------------
00251 ;; Jump to jLabel if TMR1H (low byte) < bClk
00252 ;; --------------------------------------------------------
00253 jmp1HDone macro bClk,jLabel
00254
00255 movfw TMR1H
00256 subwf bClk,W
00257 andlw 0x80
00258 jmpNZ jLabel
00259 endm
00260
00261
00262 ;********************************************************************
00263 ; Begin Program Code
00264 ;********************************************************************
00265
0000 00266 ORG 0x0 ;memory @ 0x0
0000 0000 00267 nop ;nop ICD!!
0001 2907 00268 goto HardStart
MPASM 02.20.15 Intermediate CAN_REF.ASM 2-8-2000 13:27:59 PAGE 20
CAN_Ref Design
LOC OBJECT CODE LINE SOURCE TEXT
VALUE
00269
0004 00270 ORG 04h ;Interrupt Vector @ 0x4
00271 ;**********************************************************
00272 ; Interrupt service routine - must be at location 4 if page 1 is used
00273 ; Context save & restore takes ~20 instr
00274 ;**********************************************************
00275 ;; Global int bit, GIE, has been reset.
00276 ;; W saved in bIntSaveW0 or bIntSaveW1 depending on the bank selected at
00277 ;; the time the interrupt occured.
0004 00FF 00278 movwf bIntSaveW0 ; save W in either of two locations
00279 ; depending on bank currently selected
00280
00281 ;; only way to preserve Status bits (since movf sets Z) is with a
00282 ;; swapf command now
0005 0E03 00283 swapf STATUS,W ; Status to W with nibbles swapped
00284 BANK0
0006 1283 M bcf STATUS,5 ; Select page 0
0007 00A0 00285 movwf bIntSaveSt
0008 0804 00286 movfw FSR
0009 00A1 00287 movwf bIntSaveFSR ; save FSR
000A 080A 00288 movf PCLATH,W
000B 00A2 00289 movwf bIntSavPCLATH ; interrupt storage for PCLATH
000C 018A 00290 clrf PCLATH ; set to page 0
00291
00292 ;; Must determine source of interrupt
00293
00294 ;; SPI interrupt
000D 198C 00295 btfsc _SSPIF ; SPI interrupt
000E 28F9 00296 goto IntSPI
00297
00298 jmpSet _TMR1IF,jIntTimer1 ; Timer1 overflow interrupt flag
000F 180C M btfsc PIR1,TMR1IF
0010 28EE M goto jIntTimer1
00299
00300 ;; unknown
00301
00302 ;; restore registers and return
0011 00303 IntReturn
00304 BANK0
0011 1283 M bcf STATUS,5 ; Select page 0
0012 0822 00305 movf bIntSavPCLATH,W ; interrupt storage for PCLATH
0013 008A 00306 movwf PCLATH
0014 0821 00307 movf bIntSaveFSR,W ; restore FSR
0015 0084 00308 movwf FSR
0016 0E20 00309 swapf bIntSaveSt,W ; get swapped Status (now unswapped)
0017 0083 00310 movwf STATUS ; W to Status ( bank select restored )
0018 0EFF 00311 swapf bIntSaveW0,F ; swap original W in place
0019 0E7F 00312 swapf bIntSaveW0,W ; now load and unswap ( no status change)
001A 0009 00313 retfie ; return from interrupt
00314
00315
00316 ;***************** ID TABLE ****************************
00317 ; Look up ID associated with bits 0,1 in W
MPASM 02.20.15 Intermediate CAN_REF.ASM 2-8-2000 13:27:59 PAGE 21
CAN_Ref Design
LOC OBJECT CODE LINE SOURCE TEXT
VALUE
001B 0782 00318 RxIDTable addwf PCL,F ;Jump to char pointed to in W reg
00319 ;( adds 5bits from PCLATH )
001C 3400 00320 retlw 0x00 ; 0
001D 3420 00321 retlw 0x20 ; 1
001E 3410 00322 retlw 0x10 ; 2
001F 3430 00323 retlw 0x30 ; 3
0020 00324 RxIDTable_End
00325 #if ( (RxIDTable & 0xF00) != (RxIDTable_End & 0xF00) )
00326 MESSG "Warning - Table crosses page boundry in computed jump"
00327 #endif
00328
00329 ; Look up ID associated with bits 0,1 in W
0020 0782 00330 TxIDTable addwf PCL,F ;Jump to char pointed to in W reg
00331 ;( adds 5bits from PCLATH )
0021 34FF 00332 retlw 0xFF ; 0
0022 3420 00333 retlw 0x20 ; 1
0023 3410 00334 retlw 0x10 ; 2
0024 3430 00335 retlw 0x30 ; 3
0025 00336 TxIDTable_End
00337 #if ( (TxIDTable & 0xF00) != (TxIDTable_End & 0xF00) )
00338 MESSG "Warning - Table crosses page boundry in computed jump"
00339 #endif
00340
00341 ;***************** LIBRARY STORAGE & FUNCTIONS ****************************
00342
00343 #include "CanLib.asm" ; basic 2510 interface routines
00001 ;**********************************************************
00002 ;**********************************************************
00003
00004
00005 ; MCP2510 Instructions
00006 #define d2510Rd 0x03 ; MCP2510 read instruction
00007 #define d2510Wrt 0x02 ; MCP2510 write instruction
00008 #define d2510Reset 0xC0 ; MCP2510 reset instruction
00009 #define d2510RTS 0x80 ; MCP2510 RTS instruction
00010 #define d2510Status 0xA0 ; MCP2510 Status instruction
00011 #define d2510BitMod 0x05 ; MCP2510 bit modify instruction
00012
00013
00014
00015 ;**********************************************************
00016 ;*************** SPECIAL CAN MACROS ***********************
00017 ;**********************************************************
00018
00019 ; Read 2510 register Reg and return data in W.
00020 SPI_Read macro Reg
00021 movlw Reg
00022 call Rd2510Reg
00023 endm
00024
00025 ; Write literal byte to 2510 register Reg.
00026 SPI_WriteL macro Reg,LitData
00027 movlw LitData
MPASM 02.20.15 Intermediate CAN_REF.ASM 2-8-2000 13:27:59 PAGE 22
CAN_Ref Design
LOC OBJECT CODE LINE SOURCE TEXT
VALUE
00028 movwf b2510RegData
00029 movlw Reg
00030 call Wrt2510Reg
00031 endm
00032
00033 ; Write Data byte to 2510 register Reg.
00034 SPI_WriteV macro Reg,RegData
00035 movfw RegData
00036 movwf b2510RegData
00037 movlw Reg
00038 call Wrt2510Reg
00039 endm
00040
00041 ; Write W byte to 2510 register Reg.
00042 SPI_WriteW macro Reg
00043 movwf b2510RegData
00044 movlw Reg
00045 call Wrt2510Reg
00046 endm
00047
00048
00049 ; Write bits determined by Mask & Data to 2510 register Reg.
00050 SPI_BitMod macro Reg,Mask,Data
00051 movlw Mask
00052 movwf b2510RegMask
00053 movlw Data
00054 movwf b2510RegData
00055 movlw Reg
00056 call BitMod2510
00057 endm
00058
00059 ; Arm xmit buffers for xmission
00060 SPI_Rts macro Data
00061 movlw Data
00062 call Rts2510
00063 endm
00064
00065
00066 ;**********************************************************
00067 ;**********************************************************
00068 ;Support routines for communicating with 2510 chip
00069 ;**********************************************************
00070 ;**********************************************************
00071
00072 ;******************************************************
00073 ;CheckCANMsg
00074 ;
00075 ; Checks for message in Receive Buf 1. If no message pending return
00076 ; with Z flag set.
00077 ;
00078 ; If message pending:
00079 ; Load iRecID_L,iRecID_H with ID.
00080 ; Load bRecCount with number of bytes of data received.
MPASM 02.20.15 Intermediate CAN_REF.ASM 2-8-2000 13:27:59 PAGE 23
CAN_Ref Design
LOC OBJECT CODE LINE SOURCE TEXT
VALUE
00081 ; Load buffer at pRecDataBase with data
00082 ; Clear 2510 Receive Buffer 1 interrupt flag
00083 ; Set tbRxMsgPend flag and clear Z flag.
00084 ;
00085 ; NOTE: If message already pending doesn't check for new message.
00086 ;
00087 ;******************************************************/
0025 00088
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -