sendword.s

来自「dsPIC对于交流感应电机矢量控制的应用笔记的源代码(中文)」· S 代码 · 共 72 行

S
72
字号
;*******************************************************************
; Routines: SendWord
;
;*******************************************************************

; Common to all routines in file

          .include "general.inc"

          .extern _SendWord

;*******************************************************************
; SendWord
;  
;Description:        
;
;Functional prototype:
; 
; void SendWord( short S, short Shiftleft, short Sync )
;
;*******************************************************************
;
;=================== CODE =====================
          .section  .text

          .global   _SendWord

_SendWord:
          btsc      U1STAbits,#UTXBF    ; buffer full
          bra       _SendWord

          sl        w0,w1,w0            ; shift w0 left by w1

     ;; w0 = 15b 14b 13b 12b 11b 10b 9b 8b 7b 6b 5b 4b 3b 2b 1b 0b 
          lsr       w0,w0               ; shift w0  right by 1

     ;; 0 15b 14b 13b 12b 11b 10b 9b 8b 7b 6b 5b 4b 3b 2b 1b 

          btsc      w2,#0
          bset      w0,#15

     ;; w0 = f 15b 14b 13b 12b 11b 10b 9b 8b 7b 6b 5b 4b 3b 2b 1b 
     ;; where f = Sync &1

     ;; split into two bytes with flag in upper bit of each

          lsr       w0,#8,w1            ; shift w0 right by 8 into w1

     ;; w1 = 0 0 0 0 0 0 0 0 f 15b 14b 13b 12b 11b 10b 9b

          mov       w1,_U1TXREG
          
jSendWord1:
          btsc      U1STAbits,#UTXBF    ; buffer full
          bra       jSendWord1

     ;; w0 = f 15b 14b 13b 12b 11b 10b 9b 8b 7b 6b 5b 4b 3b 2b 1b 

          lsr       w0,w1               ; shift w0 right by 1 into w1

     ;; w1 = 0 f 15b 14b 13b 12b 11b 10b 9b 8b 7b 6b 5b 4b 3b 2b

          and       #0x007F,w1

     ;; lower byte = 0 8b 7b 6b 5b 4b 3b 2b

          mov       w1,_U1TXREG

          return

          .end

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?