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

📄 rx8_1.asm

📁 单片机控制122x32液晶。液晶内部芯片包含RAM(类似于显存)
💻 ASM
📖 第 1 页 / 共 2 页
字号:
;  DESCRIPTION:
;     Read character from UART RX port.
;
;  ARGUMENTS:
;      none
;
;  RETURNS:
;     An integer value is returned.  A negative value inplies and error
;     condition, a positive value between 0 and 255 is the return character.
;
;     Error Codes:
;        0x80CC    Parity Error
;        0x40CC    Overrun Error
;        0x20CC    Framing Error
;        0x01CC    No Data available
;
;  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.
;
 RX8_1_iReadChar:
_RX8_1_iReadChar:
   RAM_PROLOGUE RAM_USE_CLASS_1

   mov  A,REG[RX8_1_CONTROL_REG]                           ; Get Status of RX
                                                           ; Mask only errors and data ready
   and  A,(RX8_1_RX_ERROR|RX8_1_RX_REG_FULL)
   push A
   and  A,RX8_1_RX_COMPLETE                                ; Check if a character is ready
   jnz  .RX_GET_DATA                                       ; Data Ready go read it.
   pop  A
   or   A,RX8_1_RX_NO_DATA                                 ; Add no data flag
   swap A,X
   jmp  End_RX8_1_iReadChar

.RX_GET_DATA:
   pop  A
   and  A,RX8_1_RX_ERROR
   swap A,X
   mov  A,REG[RX8_1_RX_BUFFER_REG]                         ; Read data first, then
                                                           ; determine if data is valid

 End_RX8_1_iReadChar:
   RAM_EPILOGUE RAM_USE_CLASS_1
   ret
.ENDSECTION



IF (RX8_1_RXBUF_ENABLE)
.SECTION
;-----------------------------------------------------------------------------
;-----------------------------------------------------------------------------
;
;     Command Buffer commands
;
;-----------------------------------------------------------------------------
;-----------------------------------------------------------------------------

;-----------------------------------------------------------------------------
;  FUNCTION NAME: RX8_1_CmdReset
;
;  DESCRIPTION:
;     Reset command string and status flags
;
;  ARGUMENTS:
;     none.
;
;  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.
;          
;    Currently only the page pointer registers listed below are modified: 
;          CUR_PP
;
;  THEORY of OPERATION or PROCEDURE:
;     Clear the command buffer, command counter, and flag.
;
 RX8_1_CmdReset:
_RX8_1_CmdReset:
   RAM_PROLOGUE RAM_USE_CLASS_4
   RAM_SETPAGE_CUR >RX8_1_aRxBuffer
   mov [RX8_1_aRxBuffer], 0x00
   RAM_SETPAGE_CUR >ptrParam
   mov [ptrParam],0x00
   RAM_SETPAGE_CUR >RX8_1_bRxCnt
   mov [RX8_1_bRxCnt], 0x00
   and [RX8_1_fStatus], 0x00
   RAM_EPILOGUE RAM_USE_CLASS_4
   ret
.ENDSECTION

.SECTION
;-----------------------------------------------------------------------------
;  FUNCTION NAME: RX8_1_bCmdCheck
;
;  DESCRIPTION:
;     Check to see if valid command in buffer.
;
;  ARGUMENTS:
;     none.
;
;  RETURNS:
;     BYTE  fStatus - Status of command receive buffer.
;                     Returns non-zero value in A if command is valid.
;
;  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.
;          
;    Currently only the page pointer registers listed below are modified: 
;          CUR_PP
;
;  THEORY of OPERATION or PROCEDURE:
;     Read the status and control register.
;
 RX8_1_bCmdCheck:
_RX8_1_bCmdCheck:
   RAM_PROLOGUE RAM_USE_CLASS_4
   RAM_SETPAGE_CUR >RX8_1_fStatus
   mov A,  [RX8_1_fStatus]
   and A, RX8_1_RX_BUF_CMDTERM                   ; Mask off Command status
   RAM_EPILOGUE RAM_USE_CLASS_4
   ret
.ENDSECTION

.SECTION
;-----------------------------------------------------------------------------
;  FUNCTION NAME: RX8_1_bErrCheck
;
;  DESCRIPTION:
;     Check to see if an error has occured since last CmdReset
;
;  ARGUMENTS:
;     none.
;
;  RETURNS:
;     BYTE  fStatus - Status of command receive buffer.
;                     Returns non-zero value in A if command is valid.
;           0x80 => Parity Error
;           0x40 => OverRun Error
;           0x20 => Framing Error
;           0x10 => Software Buffer OverRun
;
;  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.
;          
;    Currently only the page pointer registers listed below are modified: 
;          CUR_PP
;
;     Error Status is clear when read.
;
;  THEORY of OPERATION or PROCEDURE:
;     Read RX buffer error status and clear status
;
 RX8_1_bErrCheck:
_RX8_1_bErrCheck:
   RAM_PROLOGUE RAM_USE_CLASS_4
   RAM_SETPAGE_CUR >RX8_1_fStatus
   mov A,  [RX8_1_fStatus]
   and A, RX8_1_RX_BUF_ERROR                     ; Mask off Error status
   and [RX8_1_fStatus], ~RX8_1_RX_BUF_ERROR
   RAM_EPILOGUE RAM_USE_CLASS_4
   ret
.ENDSECTION

.SECTION
;-----------------------------------------------------------------------------
;  FUNCTION NAME: RX8_1_bCmdLength
;
;  DESCRIPTION:
;     Get length of command string
;
;  ARGUMENTS:
;     none.
;
;  RETURNS:
;     BYTE  bRxCnt    Returns the command length 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.
;          
;    Currently only the page pointer registers listed below are modified: 
;          CUR_PP
;
 RX8_1_bCmdLength:
_RX8_1_bCmdLength:
   RAM_PROLOGUE RAM_USE_CLASS_4
   RAM_SETPAGE_CUR >RX8_1_bRxCnt
   mov A,  [RX8_1_bRxCnt]
   RAM_EPILOGUE RAM_USE_CLASS_4
   ret
.ENDSECTION

.SECTION
;-----------------------------------------------------------------------------
;  FUNCTION NAME: RX8_1_szGetParam
;
;  DESCRIPTION:
;      Return next parameter from UART Rx buffer
;
;
;  ARGUMENTS:  none
;
;  RETURNS:
;     A => MSB of parameter address
;     X => LSB of parameter address
;
;  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.
;          
;    Currently only the page pointer registers listed below are modified:
;          CUR_PP
;          IDX_PP
;
;     The receive string is modified by placing Null characters at the end
;     of each parameter as they are recovered.
;
;  THEORY OF OPERATION:
;     This function is a stateful generator of addresses to the "parameters"
;     of an input "Command". It scans the (optional) input buffer and breaks
;     each lexically distinct element into a null-terminated string by replacing
;     delimiters with nulls, as appropriate. The state of the generator is 
;     maintained by the private variable ptrParam, which is a buffer-relative
;     offset. The generator is initialized by a call to the function
;     RX8_1_CmdReset which resets the entire buffer to the 'empty'
;     state. Typically this function, RX8_1_szGetParam, is
;     not called until the buffer has been loaded with an entire command
;     (See RX8_1_bCmdCheck).
;
;     Note, there is no special distinction between the "command" and the 
;     "parameters". The first non-delimiter character of the buffer---the first
;     character of the "command"---is also, for the purposes of this function,
;     the first "parameter" to which it returns an address.
;
;     The value of a delimiter (commonly an ascii space, 0x20 and decimal 32)
;     is determined at configuration time by a user module parameter.
;
 RX8_1_szGetParam:
_RX8_1_szGetParam:
   RAM_PROLOGUE RAM_USE_CLASS_4
   RAM_PROLOGUE RAM_USE_CLASS_3
   RAM_SETPAGE_CUR >ptrParam
   RAM_SETPAGE_IDX >RX8_1_aRxBuffer

   mov  A, <RX8_1_aRxBuffer                 ; Get address to receive buffer
   add  A, [ptrParam]                      ; Add string offset
   mov  X,A

   mov  A,[X]                              ; Get character pointed by X
   jnz  .CheckForDelim                     ; Check for Null character
   push X                                  ; Save LSB of current pointer
   jmp  .End_GetNextParam

                                            ; Check for delimiter and keep looping until
                                            ; all leading delimiters have been found.
.CheckForDelim:
    cmp  A,RX8_1_DELIMITER                  ; Check if we have a delimiter
    jnz  .ParamStartFound
    inc  X                                  ; Increment both current pointer and
    inc  [ptrParam]                         ; stored pointer.
    mov  A,[X]                              ; Get character pointed by X
    cmp  [ptrParam],(RX8_1_RX_BUFFER_SIZE -1)  ; Check if we are at the end of buffer
    jnz  .CheckForDelim
                                            ; End of string found
.EndOfString:
    push X                                  ; Save ptr
.TerminateString:
    mov  [X],0x00                           ; Make sure string is zero
    jmp  .End_GetNextParam

.ParamStartFound:
    push X                                  ; Beginning of parameter found, save pointer

.ParamLoop:
                                            ; Now loop until end of parameter found.
    inc  X                                  ; Advance pointers.
    inc  [ptrParam]
    cmp  [ptrParam],(RX8_1_RX_BUFFER_SIZE -1)  ; Check if we are at the end of buffer
    jz   .TerminateString
    mov  A,[X]                              ; Get next character
    jz   .End_GetNextParam
    cmp  A,RX8_1_DELIMITER                  ; Check if we have a delimiter
    jnz  .ParamLoop                         ; Still no delimiter, loop again

    mov  [X],0x00                           ; Replace delimiter with null for end of substring
    inc  [ptrParam]
    cmp  [ptrParam],(RX8_1_RX_BUFFER_SIZE -1)  ; Check if we are at the end of buffer
    jnz  .End_GetNextParam                  ; If not end of string leave
    mov  [ptrParam],(RX8_1_RX_BUFFER_SIZE -1)  ; Reset pointer to end of string.


.End_GetNextParam:
   pop  X
   push X
   cmp  [X],0x00
   jnz  .NotNullString
   pop  X
   mov  X,0x00
   mov  A,>RX8_1_aRxBuffer
   RAM_EPILOGUE RAM_USE_CLASS_3
   RAM_EPILOGUE RAM_USE_CLASS_4
   ret

.NotNullString:
   pop  X
   mov  A,>RX8_1_aRxBuffer                     ; Return pointer
   RAM_EPILOGUE RAM_USE_CLASS_3
   RAM_EPILOGUE RAM_USE_CLASS_4
   ret
.ENDSECTION

.SECTION
;-----------------------------------------------------------------------------
;  FUNCTION NAME: RX8_1_szGetRestOfParams
;
;  DESCRIPTION:
;      Return the rest of the UART RX buffer
;
;
;  ARGUMENTS:  none
;
;  RETURNS:
;     A => MSB of parameter
;     X => LSB of parameter
;
;  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.
;          
;    Currently only the page pointer registers listed below are modified: 
;          CUR_PP
;
 RX8_1_szGetRestOfParams:
_RX8_1_szGetRestOfParams:
   RAM_PROLOGUE RAM_USE_CLASS_4
   RAM_SETPAGE_CUR >ptrParam

    mov  A, <RX8_1_aRxBuffer                ; Get address to receive buffer
    add  A, [ptrParam]                      ; Add string offset
    mov  X,A
    mov  A,>RX8_1_aRxBuffer                 ; Return pointer

   RAM_EPILOGUE RAM_USE_CLASS_4
    ret
.ENDSECTION

ENDIF
; End of File RX8_1.asm

⌨️ 快捷键说明

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