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

📄 sci.asm

📁 Texas-Instrument C2000 Series DSP example programs
💻 ASM
字号:
;-----------------------------------------------------------------------------
;  Name:                SCI.ASM
;  Project:             C240HW.LIB
;  Originator:          Simor Balazs
;  Description:         Provides functions for initializing and serving 
;                       SCI Unit
;
;  Function List:       void SCI_Init(unsigned fdiv);
;                       int kbhit(void);
;                       int SCI_Getc(void);
;                       int SCI_Sendc(int ch);
;                       int SCI_Rdy_to_Send(void);
;
;  Status:
;  Target:              TMS320C240
;  History:
;-----------------------------------------------------------------------------


;Registers of the SCI Unit
SCICCR          .set    7050h
SCICTL1         .set    7051h
SCIHBAUD        .set    7052h
SCILBAUD        .set    7053h
SCICTL2         .set    7054h
SCIRXST         .set    7055h
SCIRXEMU        .set    7056h
SCIRXBUF        .set    7057h
SCITXBUF        .set    7059h
SCIPC2          .set    705Eh
SCIPRI          .set    705Fh


        .text
;-----------------------------------------------------------------------------
; void SCI_Init(unsigned fdiv);
;
; Arguments:    fdiv = 1e7/BaudRate/8 - 1
;               E.g: for 9600 Baud, fdiv=129. (ex.ly: 9615 Baud)
;
; Return Value:  none
;
;-----------------------------------------------------------------------------
        .globl _SCI_Init
_SCI_Init:
        ldp     #0e0h                   ;Point at the SCI Registers
        splk    #00010011b,SCICTL1      ;Activating SW RESET

        splk    #00010111b,SCICCR       ;8bits, 1stop, no parity
        mar     *-
        lacc    *+                      ; sending frequency divider (fdiv) to UART
        sacl    SCILBAUD
        sfl
        sach    SCIHBAUD,7              ;high side of ACC

        splk    #0, SCICTL2             ;TX and RX interrupts disabled
        splk    #00110010b, SCIPC2      ;Configuring the TX and RX pins
        splk    #0, SCIPRI

        splk    #00110011b,SCICTL1      ;Deactivating SW RESET

        ret                                                               



;-----------------------------------------------------------------------------
; int kbhit(void);
;
; Arguments: none
;
; Return Value: 0 if no character
;               1 if character available  
;
;-----------------------------------------------------------------------------
       .globl _kbhit
_kbhit:
        ldp     #0e0h                   ; Point at the SCI Registers
        bit     SCIRXST, 9              ; checking RXRDY (data ready bit)
        bcnd    avail, tc
        lacc    #0                      ; status: no character
        ret
avail:
        lacc    #1                      ; character available
        ret



;-----------------------------------------------------------------------------
; int SCI_Getc(void);
;
; Arguments: none
;
; Return Value: received character  
;               -1 if error
;
;-----------------------------------------------------------------------------
        .globl _SCI_Getc
_SCI_Getc:
        ldp     #0e0h           ;Point at the SCI Registers
        setc    sxm
        bit     SCIRXST, 9      ; checking RXRDY (data ready bit)
        bcnd    ok, tc
        lacc    #0ffffh         ; status: error
        ret
ok:
        lacc    SCIRXBUF
        and     #255
        ret


;-----------------------------------------------------------------------------
; int SCI_Sendc(int ch);
;
; Arguments:    character to be sent
;
; Return Value:  0 if successful
;               -1 if error
;
;-----------------------------------------------------------------------------
        .globl _SCI_Sendc
_SCI_Sendc:
        ldp     #0e0h           ;Point at the SCI Registers
        setc    sxm
        bit     SCICTL2, 8
        bcnd    ok2, tc
        lacc    #0ffffh         ;status: error (not ready)
        ret
ok2:
        mar    *-
        lacc   *+
        sacl    SCITXBUF        ;sending character to output
        lacc    #0              ;status: OK
        ret



;-----------------------------------------------------------------------------
;int SCI_Rdy_to_Send(void);
;
; Arguments:    none
;
; Return Value:  0 if not ready
;                1 if ready
;
;-----------------------------------------------------------------------------
        .globl _SCI_Rdy_to_Send
_SCI_Rdy_to_Send:
        ldp     #0e0h           ;Point at the SCI Registers
        bit     SCICTL2, 8
        bcnd    ok3, tc
        lacc    #0              ;status: error (not ready)
        ret
ok3:
        lacc    #1              ;status: OK
        ret





⌨️ 快捷键说明

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