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

📄 uart.asm

📁 带触摸按键的高端电磁炉设计 该方案采用CYPRESS的新器件CY8C22545,是一款专门针对中高端的家电触摸产品设计。除了集成触摸按键功能外
💻 ASM
📖 第 1 页 / 共 4 页
字号:
 UART_SendData:
_UART_SendData:
   RAM_PROLOGUE RAM_USE_CLASS_1
   mov REG[UART_TX_BUFFER_REG], A
   RAM_EPILOGUE RAM_USE_CLASS_1
   ret
.ENDSECTION


.SECTION
;-----------------------------------------------------------------------------
;  FUNCTION NAME: UART_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_bReadTxStatus:
_UART_bReadTxStatus:
 bUART_ReadTxStatus:                             ; For backwards compatibility only
_bUART_ReadTxStatus:                             ; For backwards compatibility only
   RAM_PROLOGUE RAM_USE_CLASS_1
   mov A,  REG[UART_TX_CONTROL_REG]
   RAM_EPILOGUE RAM_USE_CLASS_1
   ret
.ENDSECTION


.SECTION
;-----------------------------------------------------------------------------
;  FUNCTION NAME: UART_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_bReadRxData:
_UART_bReadRxData:
 bUART_ReadRxData:                               ; For backwards compatibility only
_bUART_ReadRxData:                               ; For backwards compatibility only
   RAM_PROLOGUE RAM_USE_CLASS_1
   mov A, REG[UART_RX_BUFFER_REG]
   RAM_EPILOGUE RAM_USE_CLASS_1
   ret
.ENDSECTION


.SECTION
;-----------------------------------------------------------------------------
;  FUNCTION NAME: UART_bReadRxStatus
;
;  DESCRIPTION:
;     Reads the RX Status bits in the Control/Status register.
;-----------------------------------------------------------------------------
;
;  ARGUMENTS:
;     none.
;
;  RETURNS:
;     BYTE  bRXStatus - receive 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_bReadRxStatus:
_UART_bReadRxStatus:
 bUART_ReadRxStatus:                             ; For backwards compatibility only
_bUART_ReadRxStatus:                             ; For backwards compatibility only
   RAM_PROLOGUE RAM_USE_CLASS_1
   mov A,  REG[UART_RX_CONTROL_REG]
   RAM_EPILOGUE RAM_USE_CLASS_1
   ret
.ENDSECTION


.SECTION
;-----------------------------------------------------------------------------
;  FUNCTION NAME: UART_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_TxIntMode:
_UART_TxIntMode:
   RAM_PROLOGUE RAM_USE_CLASS_1

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

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

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

.TxIntMode_End:
   M8C_SetBank0
   RAM_EPILOGUE RAM_USE_CLASS_1
   ret
.ENDSECTION

    
.SECTION
;-----------------------------------------------------------------------------
;  FUNCTION NAME: UART_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_IntCntl:
_UART_IntCntl:
   RAM_PROLOGUE RAM_USE_CLASS_1

   push A
   and  A,UART_ENABLE_RX_INT
   jz   .DisRxInt
     ; Enable Rx Interrupt
   M8C_EnableIntMask UART_RX_INT_REG, UART_RX_INT_MASK
   jmp  .CheckTxInt
.DisRxInt:
     ; Disable Rx Interrupt
   M8C_DisableIntMask UART_RX_INT_REG, UART_RX_INT_MASK

.CheckTxInt:
   pop  A
   and  A,UART_ENABLE_TX_INT
   jz   .DisTxInt
     ; Enable Tx Interrupt
   M8C_EnableIntMask UART_TX_INT_REG, UART_TX_INT_MASK
   jmp  .End_IntCntl
.DisTxInt:
     ; Disable Tx Interrupt
   M8C_DisableIntMask UART_TX_INT_REG, UART_TX_INT_MASK

.End_IntCntl:
   RAM_EPILOGUE RAM_USE_CLASS_1
   ret
.ENDSECTION


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


;-----------------------------------------------------------------------------
;  FUNCTION NAME: UART_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_HEX_STR:
     DS    "0123456789ABCDEF"
.ENDLITERAL

.SECTION
 UART_PutSHexByte:
_UART_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_HEX_STR                  ; Get Hex value
   call  UART_PutChar                  ; Write data to screen
   pop   A                             ; Restore value
   and   A,0Fh                         ; Mask off lower nibble
   index UART_HEX_STR                  ; Get Hex value
   call  UART_PutChar                  ; Write data to screen
   RAM_EPILOGUE RAM_USE_CLASS_1
   ret
.ENDSECTION


.SECTION
;-----------------------------------------------------------------------------
;  FUNCTION NAME: UART_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_PutSHexInt:
_UART_PutSHexInt:
   RAM_PROLOGUE RAM_USE_CLASS_1
   swap  A,X
   call  UART_PutSHexByte              ; Print MSB
   mov   A,X                           ; Move LSB into position
   call  UART_PutSHexByte              ; Print LSB
   RAM_EPILOGUE RAM_USE_CLASS_1
   ret
.ENDSECTION


.SECTION
;-----------------------------------------------------------------------------
;  FUNCTION NAME: UART_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_TX_CONTROL_REG], UART_TX_BUFFER_EMPTY     ; Check Tx Status
   jz  .BufEmptyWaitLoop
   mov REG[UART_TX_BUFFER_REG], @Source          ; Write data to Tx Port
   endm

 UART_PutChar:
_UART_PutChar:
   RAM_PROLOGUE RAM_USE_CLASS_1
   InLinePutChar A
   RAM_EPILOGUE RAM_USE_CLASS_1
   ret
.ENDSECTION


.SECTION
;-----------------------------------------------------------------------------
;  FUNCTION NAME: UART_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 + -