⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uart_1.asm

📁 二轴陀螺仪IDG300源程序
💻 ASM
📖 第 1 页 / 共 4 页
字号:
 UART_1_SendData:
_UART_1_SendData:
   RAM_PROLOGUE RAM_USE_CLASS_1
   mov REG[UART_1_TX_BUFFER_REG], A
   RAM_EPILOGUE RAM_USE_CLASS_1
   ret
.ENDSECTION


.SECTION
;-----------------------------------------------------------------------------
;  FUNCTION NAME: UART_1_bReadTxStatus
;
;  DESCRIPTION:
;     Reads the Tx Status bits in the Control/Status register.
;-----------------------------------------------------------------------------
;
;  ARGUMENTS:
;     none.
;
;  RETURNS:
;     BYTE  bTxStatus - transmit status data.  Use defined masks for detecting
;           status bits (returned in A)
;
;  SIDE EFFECTS:
;    The A and X registers may be modified by this or future implementations
;    of this function.  The same is true for all RAM page pointer registers in
;    the Large Memory Model.  When necessary, it is the calling function's
;    responsibility to perserve their values across calls to fastcall16 
;    functions.
;
 UART_1_bReadTxStatus:
_UART_1_bReadTxStatus:
 bUART_1_ReadTxStatus:                           ; For backwards compatibility only
_bUART_1_ReadTxStatus:                           ; For backwards compatibility only
   RAM_PROLOGUE RAM_USE_CLASS_1
   mov A,  REG[UART_1_TX_CONTROL_REG]
   RAM_EPILOGUE RAM_USE_CLASS_1
   ret
.ENDSECTION


.SECTION
;-----------------------------------------------------------------------------
;  FUNCTION NAME: UART_1_bReadRxData
;
;  DESCRIPTION:
;     Reads the RX buffer register.  Should check the status regiser to make
;     sure data is valid.
;-----------------------------------------------------------------------------
;
;  ARGUMENTS:
;     none.
;
;  RETURNS:
;     bRxData - returned in A.
;
;  SIDE EFFECTS:
;    The A and X registers may be modified by this or future implementations
;    of this function.  The same is true for all RAM page pointer registers in
;    the Large Memory Model.  When necessary, it is the calling function's
;    responsibility to perserve their values across calls to fastcall16 
;    functions.
;
 UART_1_bReadRxData:
_UART_1_bReadRxData:
 bUART_1_ReadRxData:                             ; For backwards compatibility only
_bUART_1_ReadRxData:                             ; For backwards compatibility only
   RAM_PROLOGUE RAM_USE_CLASS_1
   mov A, REG[UART_1_RX_BUFFER_REG]
   RAM_EPILOGUE RAM_USE_CLASS_1
   ret
.ENDSECTION


.SECTION
;-----------------------------------------------------------------------------
;  FUNCTION NAME: UART_1_bReadRxStatus
;
;  DESCRIPTION:
;     Reads the RX Status bits in the Control/Status register.
;-----------------------------------------------------------------------------
;
;  ARGUMENTS:
;     none.
;
;  RETURNS:
;     BYTE  bRXStatus - transmit status data.  Use the following defined bits
;                       masks: RX_COMPLETE and RX_BUFFER_EMPTY
;           returned in A.
;
;  SIDE EFFECTS:
;    The A and X registers may be modified by this or future implementations
;    of this function.  The same is true for all RAM page pointer registers in
;    the Large Memory Model.  When necessary, it is the calling function's
;    responsibility to perserve their values across calls to fastcall16 
;    functions.
;
 UART_1_bReadRxStatus:
_UART_1_bReadRxStatus:
 bUART_1_ReadRxStatus:                           ; For backwards compatibility only
_bUART_1_ReadRxStatus:                           ; For backwards compatibility only
   RAM_PROLOGUE RAM_USE_CLASS_1
   mov A,  REG[UART_1_RX_CONTROL_REG]
   RAM_EPILOGUE RAM_USE_CLASS_1
   ret
.ENDSECTION


.SECTION
;-----------------------------------------------------------------------------
;  FUNCTION NAME: UART_1_TxIntMode
;
;  DESCRIPTION:
;     This function is used to change the TX Interrupt mode.
;-----------------------------------------------------------------------------
;
;  ARGUMENTS:
;     A => Tx Interrupt mode
;             0 => Interrupt on TX_Reg_Empty  (Default)
;             1 => Interrupt on TX Complete
;
;  RETURNS:
;     none.
;
;  SIDE EFFECTS:
;    The A and X registers may be modified by this or future implementations
;    of this function.  The same is true for all RAM page pointer registers in
;    the Large Memory Model.  When necessary, it is the calling function's
;    responsibility to perserve their values across calls to fastcall16 
;    functions.
;
 UART_1_TxIntMode:
_UART_1_TxIntMode:
   RAM_PROLOGUE RAM_USE_CLASS_1

   and  A,UART_1_INT_MODE_TX_COMPLETE
   M8C_SetBank1
   cmp  A,UART_1_INT_MODE_TX_COMPLETE
   jz   .SetTxCmpMode

   and  reg[UART_1_TX_FUNC_REG],0xEF             ; Set Interrupt on Tx_Reg_Empty
   jmp  .TxIntMode_End

.SetTxCmpMode:                                       ; Set Interrupt on TX Complete
   or   reg[UART_1_TX_FUNC_REG],0x10

.TxIntMode_End:
   M8C_SetBank0
   RAM_EPILOGUE RAM_USE_CLASS_1
   ret
.ENDSECTION

    
.SECTION
;-----------------------------------------------------------------------------
;  FUNCTION NAME: UART_1_IntCntl
;
;  DESCRIPTION:
;     This function is used to enable/disable the Rx and Tx interrupt.
;-----------------------------------------------------------------------------
;
;  ARGUMENTS:
;     A => Interrupt mask
;
;  RETURNS:
;     none.
;
;  SIDE EFFECTS:
;    The A and X registers may be modified by this or future implementations
;    of this function.  The same is true for all RAM page pointer registers in
;    the Large Memory Model.  When necessary, it is the calling function's
;    responsibility to perserve their values across calls to fastcall16 
;    functions.
;
;  THEORY of OPERATION or PROCEDURE:
;     Set or Clears the Tx/Rx user module interrupt enable mask bit in the TX
;     and RX block.
;
 UART_1_IntCntl:
_UART_1_IntCntl:
   RAM_PROLOGUE RAM_USE_CLASS_1

   push A
   and  A,UART_1_ENABLE_RX_INT
   jz   .DisRxInt
     ; Enable Rx Interrupt
   M8C_EnableIntMask UART_1_RX_INT_REG, UART_1_RX_INT_MASK
   jmp  .CheckTxInt
.DisRxInt:
     ; Disable Rx Interrupt
   M8C_DisableIntMask UART_1_RX_INT_REG, UART_1_RX_INT_MASK

.CheckTxInt:
   pop  A
   and  A,UART_1_ENABLE_TX_INT
   jz   .DisTxInt
     ; Enable Tx Interrupt
   M8C_EnableIntMask UART_1_TX_INT_REG, UART_1_TX_INT_MASK
   jmp  .End_IntCntl
.DisTxInt:
     ; Disable Tx Interrupt
   M8C_DisableIntMask UART_1_TX_INT_REG, UART_1_TX_INT_MASK

.End_IntCntl:
   RAM_EPILOGUE RAM_USE_CLASS_1
   ret
.ENDSECTION


;=============================================================================
;=============================================================================
;
;     High-Level Commands
;
;=============================================================================
;=============================================================================


;-----------------------------------------------------------------------------
;  FUNCTION NAME: UART_1_PutSHexByte
;
;  DESCRIPTION:
;     Print a byte in Hex (two characters) to the UART Tx
;-----------------------------------------------------------------------------
;
;  ARGUMENTS:
;     A  => (BYTE) Data/char to be printed
;
;  RETURNS:
;     none.
;
;  SIDE EFFECTS:
;    The A and X registers may be modified by this or future implementations
;    of this function.  The same is true for all RAM page pointer registers in
;    the Large Memory Model.  When necessary, it is the calling function's
;    responsibility to perserve their values across calls to fastcall16 
;    functions.
;
.LITERAL
UART_1_HEX_STR:
     DS    "0123456789ABCDEF"
.ENDLITERAL

.SECTION
 UART_1_PutSHexByte:
_UART_1_PutSHexByte:
   RAM_PROLOGUE RAM_USE_CLASS_1
   push  A                             ; Save lower nibble
   asr   A                             ; Shift high nibble to right
   asr   A
   asr   A
   asr   A
   and   A,0Fh                         ; Mask off nibble
   index UART_1_HEX_STR                ; Get Hex value
   call  UART_1_PutChar                ; Write data to screen
   pop   A                             ; Restore value
   and   A,0Fh                         ; Mask off lower nibble
   index UART_1_HEX_STR                ; Get Hex value
   call  UART_1_PutChar                ; Write data to screen
   RAM_EPILOGUE RAM_USE_CLASS_1
   ret
.ENDSECTION


.SECTION
;-----------------------------------------------------------------------------
;  FUNCTION NAME: UART_1_PutSHexInt
;
;  DESCRIPTION:
;     Print an Int in Hex (four characters) to UART Tx
;-----------------------------------------------------------------------------
;
;  ARGUMENTS:
;     Pointer to string
;     A  => ASB of Int
;     X  => MSB of Int
;
;  RETURNS:
;     none.
;
;  SIDE EFFECTS:
;    The A and X registers may be modified by this or future implementations
;    of this function.  The same is true for all RAM page pointer registers in
;    the Large Memory Model.  When necessary, it is the calling function's
;    responsibility to perserve their values across calls to fastcall16 
;    functions.
;

 UART_1_PutSHexInt:
_UART_1_PutSHexInt:
   RAM_PROLOGUE RAM_USE_CLASS_1
   swap  A,X
   call  UART_1_PutSHexByte            ; Print MSB
   mov   A,X                           ; Move LSB into position
   call  UART_1_PutSHexByte            ; Print LSB
   RAM_EPILOGUE RAM_USE_CLASS_1
   ret
.ENDSECTION


.SECTION
;-----------------------------------------------------------------------------
;  FUNCTION NAME: UART_1_PutChar
;
;  DESCRIPTION:
;     Send character out through UART TX port.
;-----------------------------------------------------------------------------
;
;  ARGUMENTS:
;     A has Character to send to UART Tx Port
;
;  RETURNS:
;     none
;
;  SIDE EFFECTS:
;    The A and X registers may be modified by this or future implementations
;    of this function.  The same is true for all RAM page pointer registers in
;    the Large Memory Model.  When necessary, it is the calling function's
;    responsibility to perserve their values across calls to fastcall16 
;    functions.
;

   macro InLinePutChar( Source )
.BufEmptyWaitLoop:
   tst REG[UART_1_TX_CONTROL_REG], UART_1_TX_BUFFER_EMPTY     ; Check Tx Status
   jz  .BufEmptyWaitLoop
   mov REG[UART_1_TX_BUFFER_REG], @Source        ; Write data to Tx Port
   endm

 UART_1_PutChar:
_UART_1_PutChar:
   RAM_PROLOGUE RAM_USE_CLASS_1
   InLinePutChar A
   RAM_EPILOGUE RAM_USE_CLASS_1
   ret
.ENDSECTION


.SECTION
;-----------------------------------------------------------------------------
;  FUNCTION NAME: UART_1_cGetChar
;
;  DESCRIPTION:
;     Read character from UART RX port.
;-----------------------------------------------------------------------------
;
;  ARGUMENTS:
;      none
;
;  RETURNS:
;     char that is returned from UART

⌨️ 快捷键说明

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