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

📄 uart_1.asm

📁 二轴陀螺仪IDG300源程序
💻 ASM
📖 第 1 页 / 共 4 页
字号:
;
;  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.
;
;    Program flow will stay in this function until a character is received.
;    If the watchdog timer is used, care must be taken to make sure that
;    the delay between characters is less than the watchdog timeout.
;
 UART_1_cGetChar:
_UART_1_cGetChar:
   RAM_PROLOGUE RAM_USE_CLASS_1
   tst REG[UART_1_RX_CONTROL_REG],UART_1_RX_REG_FULL    ; Check if a character is ready
   jz  UART_1_cGetChar                              ; If not loop
   mov A, REG[UART_1_RX_BUFFER_REG]                 ; Get character
   RAM_EPILOGUE RAM_USE_CLASS_1
   ret
.ENDSECTION


.SECTION
;-----------------------------------------------------------------------------
;  FUNCTION NAME: UART_1_cReadChar
;
;  DESCRIPTION:
;     Read character from UART RX port.
;-----------------------------------------------------------------------------
;
;  ARGUMENTS:
;      none
;
;  RETURNS:
;     char that is returned from UART
;
;  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.
;
;    A valid 0x00 character will be ignored, since a 0x00 return value
;    implies a valid character or an error condition occured.
;
 UART_1_cReadChar:
_UART_1_cReadChar:
   RAM_PROLOGUE RAM_USE_CLASS_1
   mov  A,REG[UART_1_RX_CONTROL_REG]                       ; Get Status of RX
   push A
   and  A,UART_1_RX_COMPLETE                               ; Check if a character is ready
   jnz  .RX_DATA_RDY                                       ; Data Ready go read it.
   pop  A
   jmp  .RX_NO_VALID_CHAR

.RX_DATA_RDY:
   mov  A,REG[UART_1_RX_BUFFER_REG ]          
   swap A,X                                                ; determine if data is valid

   pop  A                                                  ; Check for errors
   and  A,(UART_1_RX_PARITY_ERROR | UART_1_RX_FRAMING_ERROR)
   jnz  .RX_NO_VALID_CHAR                                  ; No character, exit
   swap A,X                                                ; Put data in A and exit
   RAM_EPILOGUE RAM_USE_CLASS_1
   ret

.RX_NO_VALID_CHAR:
   mov A,0x00                                              ; Zero out character

 End_UART_1_cReadChar:
   RAM_EPILOGUE RAM_USE_CLASS_1
   ret
.ENDSECTION


.SECTION
;-----------------------------------------------------------------------------
;  FUNCTION NAME: UART_1_iReadChar
;
;  WARNING WARNING WARNING  Negative return value not correct!!!!  We may want
;  to just set a value in the upper byte if error conditions exists.
;
;  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.
;
 UART_1_iReadChar:
_UART_1_iReadChar:
   RAM_PROLOGUE RAM_USE_CLASS_1
   mov  A,REG[UART_1_RX_CONTROL_REG]                       ; Get Status of RX
                                                           ; Mask only errors and data ready
   and  A,(UART_1_RX_ERROR|UART_1_RX_REG_FULL)
   push A
   and  A,UART_1_RX_COMPLETE                               ; Check if a character is ready
   jnz  .RX_GET_DATA                                       ; Data Ready go read it.
   pop  A
   or   A,UART_1_RX_NO_DATA                                ; Add no data flag
   swap A,X
   jmp  End_UART_1_iReadChar

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

 End_UART_1_iReadChar:
   RAM_EPILOGUE RAM_USE_CLASS_1
   ret
.ENDSECTION


.SECTION
;-----------------------------------------------------------------------------
;  FUNCTION NAME: UART_1_PutString
;
;  DESCRIPTION:
;     Send String out through UART TX port.
;-----------------------------------------------------------------------------
;
;  ARGUMENTS:
;     Pointer to String
;     A has MSB of string address
;     X has LSB of string address
;
;  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: 
;          IDX_PP
;
 UART_1_PutString:
_UART_1_PutString:
   RAM_PROLOGUE RAM_USE_CLASS_3
   RAM_SETPAGE_IDX A
.PutStringLoop:
   mov   A,[X]                                   ; Get value pointed to by X
   jz    End_PutString                           ; Check for end of string
   call  UART_1_PutChar                          ; Send character to Tx port
   inc   X                                       ; Advance pointer to next character
   jmp   .PutStringLoop                          ; Get next character

End_PutString:
   RAM_EPILOGUE RAM_USE_CLASS_3
   ret
.ENDSECTION
    
.SECTION
;-----------------------------------------------------------------------------
;  FUNCTION NAME: UART_1_Write
;
;  DESCRIPTION:
;     Send String of length X to serial port
;-----------------------------------------------------------------------------
;
;  ARGUMENTS:
;     Pointer to String
;     [SP-5] Count of characters to send
;     [SP-4] has MSB of string address
;     [SP-3] has LSB of string address
;
;  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: 
;          IDX_PP
;
CNT_LEN:    equ -5                               ; Length of data to send
STR_MSB:    equ -4                               ; MSB pointer of string 
STR_LSB:    equ -3                               ; LSB pointer of string 

 UART_1_Write:
_UART_1_Write:
   RAM_PROLOGUE RAM_USE_CLASS_3
   RAM_SETPAGE_IDX2STK                           ; Refer indexed addrs to the stack
   mov   X, SP                                   ; Establish the frame pointer 

.NextByteLoop:
   mov   A, [X+CNT_LEN]                          ; End of the string?
   jz    .End_Write                              ;   Yes, prepare to exit
   dec   [X+CNT_LEN]                             ; Decrement counter

   IF SYSTEM_LARGE_MEMORY_MODEL
   mov   A, [X+STR_MSB]                          ; Load pointer to char to send
   ENDIF

   mov   X, [X+STR_LSB]                          ; Load pointer to char to send
   RAM_SETPAGE_IDX A                             ; switch index pages
   mov   A, [X]                                  ; Grab the data
   InlinePutChar A                               ; Put data in empty TX buf reg
   mov   X, SP                                   ; Recover frame pointer
   RAM_SETPAGE_IDX2STK                           ; Prepare for stack access
   inc   [X+STR_LSB]                             ; Point to next byte, but do not
   jmp   .NextByteLoop                           ;    cross RAM page boundary!

.End_Write:
   RAM_EPILOGUE RAM_USE_CLASS_3
   ret
.ENDSECTION
    

.SECTION
;-----------------------------------------------------------------------------
;  FUNCTION NAME: UART_1_CWrite
;
;             WARNING WARNING NOT COMPLETE
;
;  DESCRIPTION:
;     Send String of length X to serial port
;-----------------------------------------------------------------------------
;
;  ARGUMENTS:
;     [SP-4] MSB of Count of character to send
;     [SP-3] LSB of Count of character to send
;     [SP-2] has MSB of string address
;     [SP-1] has LSB of string address
;
;  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.
;
CLEN_MSB:   equ -6           ; MSB Length of data to send
CLEN_LSB:   equ -5           ; LSB Length of data to send
CSTR_MSB:   equ -4           ; MSB pointer of string
CSTR_LSB:   equ -3           ; LSB pointer of string

 UART_1_CWrite:
_UART_1_CWrite:
   RAM_PROLOGUE RAM_USE_CLASS_2
   mov   X,SP
.CW_Loop:
   cmp   [X+CLEN_MSB],0x00                  ; Check for zero counter
   jnz   .CW_WRITEIT
   cmp   [X+CLEN_LSB],0x00
   jz    .End_CWrite                        ; Leave if done

.CW_WRITEIT:                                
   push  X                                  ; Save frame pointer
   mov   A,[X+CSTR_MSB]
   mov   X,[X+CSTR_LSB]
   romx                                     ; Get character from ROM
   InlinePutChar A                          ; Put data in empty TX buf reg
   pop   X                                  ; Restore frame pointer
   add   [X+CSTR_LSB],1                     ; Increment the string pointer
   adc   [X+CSTR_MSB],0
   sub   [X+CLEN_LSB],0x01                  ; Dec the counter
   sbb   [X+CLEN_MSB],0x00
   jmp   .CW_Loop

.End_CWrite:
   RAM_EPILOGUE RAM_USE_CLASS_2
   ret
.ENDSECTION


.SECTION
;-----------------------------------------------------------------------------
;  FUNCTION NAME: UART_1_CPutString
;
;  DESCRIPTION:
;     Send String out through UART TX port.
;-----------------------------------------------------------------------------
;
;  ARGUMENTS:
;     Pointer to String
;     A has MSB of string address
;     X has LSB of string address
;
;  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_CPutString:
_UART_1_CPutString:
   RAM_PROLOGUE RAM_USE_CLASS_1
   push  A                                       ; Store ROM pointer
   push  X
   romx                                          ; Get character from ROM
   jz    .End_CPutString
   call  UART_1_PutChar                          ; Print character
   pop   X
   pop   A
   inc   X                                       ; Inc LSB of pointer
   jnc   UART_1_CPutString                       ; Check for carry
   inc   A                                       ; Inc MSB of pointer
   jmp   UART_1_CPutString


.End_CPutString:
   add   SP, -2
   RAM_EPILOGUE RAM_USE_CLASS_1
   ret
.ENDSECTION


.SECTION
;-----------------------------------------------------------------------------
;  FUNCTION NAME: UART_1_PutCRLF
;
;  DESCRIPTION:
;     Send a CR and LF
;-----------------------------------------------------------------------------
;

⌨️ 快捷键说明

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