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

📄 uartasm.asm

📁 TMS320VC5402的串口应用实例,汇编语言写,是DSP入门学习的好帮手.
💻 ASM
字号:
     .title " test vc5402'uart"
     .global _pllx100, _init_start,_pc_uartint,_start_uart,_u_printf
     .mmregs

swcr      .set      2bh


temp 		.set 	60h
counter_rx 	.set 	61h		; is counter equal to 0, then
counter_tx 	.set 	62h		; stop uart int !
ptr_rx_data	.set 	63h
ptr_tx_data	.set 	64h
rx_temp    	.set 	65h
counter_error .set 	66h

; /*  PC UART USE 15C550 , it BASE ADDRESS IS 0B000h   */
uart_data .set 0b000h     ;uart RBR,THR(DLAB=0);DLL(DLAB=1) register address
uart_ier .set 0b001h     ;uart IER(DLAB=0);DLM(DLAB=1) register address
uart_iir .set 0b002h     ;uart IIR,FCR register address
uart_lcr .set 0b003h     ;uart LCR register address
uart_mcr .set 0b004h     ;uart MCR register address
uart_lsr .set 0b005h     ;uart LSR register address
uart_msr .set 0b006h     ;uart MSR register address
uart_scr .set 0b007h     ;uart SCR register address


     .text
;/*------------------------------------------------------------------------
;  The following codes switch to 100MHz clock !
;-------------------------------------------------------------------------*/
_pllx100:				; change PLL is x10, CLK=100MHz
     stm  #0,58h
wait_pll:
     ldm  58h,a
     and  #1,a
     bc   wait_pll,aneq
     stm  #97ffh,58h      ; switch pll*10 -> 100M clk

     rpt  #100
     nop
     ret
;/*------------------------------------------------------------------------
;  The following codes init UART and same important regs !
;-------------------------------------------------------------------------*/
_init_start:
     ssbx intm           ; close all int ! (ssbx intm)

     pshm st1
     pshm st0
     
     rsbx cpl			; CPL=0,USE dp !
     stm  #10h,26h       ; stop TIMER0 !
     stm  #10h,36h       ; stop TIMER1 !
;     stm  #0ffh,sp       ; sp= 0x0ff
     ld   #0,dp          ; dp=0 
     stm  #2020h,pmst    ; vector table start: 0x2000
     stm  #0ffffh,ifr    ; clear all int !
     ldm  imr,a
     and  #0fffeh,a
     stlm a,imr          ; close  INT0
     stm  #02492h,swwsr  ; all 7 waits !
     stm  #0,swcr
     nop

testuart:                 ;test the function of UART
     stm  #08bh,temp
     portw temp,uart_lcr  ;set LCR_D7=1 to set baudrate register
     nop
     nop
     stm  #24,temp
     portw temp,uart_data ;set DLL=24(baudrate=9600,primaryF=3.6864M)
     nop
     nop
     stm #0,temp
     portw temp,uart_iir    ;set DLM=0 (baudrate=9600,primaryF=3.6864M)
     nop
     nop
     stm #03h,temp
     portw temp,uart_lcr    ;set LCR_D7=0 and line control
     nop
     nop
     portr uart_iir,temp    ;to clear iir
     portr uart_lsr,temp    ;to clear lsr
     nop
     stm #03h,temp
     portw temp,uart_ier    ;enable receive,send ints
     nop
     nop
     
     stm #0,counter_tx     ;init counter_tx
     stm #0,counter_rx     ;init counter_rx
     stm #0,counter_error     ;init counter_error

     popm st0
     popm st1
     ret

;/*------------------------------------------------------------------------
;  The following codes set IMR to start UART int !
;-------------------------------------------------------------------------*/
_start_uart:
     ssbx intm			; close all interrupt
     ldm  imr,a    		; IMR -> A
     or   #1h,a			; enable INT0 !
     stlm a,imr

;     stm #0,temp       ;init tx_data
;     portw *(temp),uart_data
     
;     rsbx intm
     
__ret:
     rete				; return and enable all interrupt
;/*------------------------------------------------------------------------
;  The following codes used for INT0 !
;-------------------------------------------------------------------------*/
_pc_uartint:
     pshm  st0
     pshm  st1
     pshm  ah
     pshm  al
     pshm  ar0
     
     rsbx  cpl			; cpl=0,use DP
     ld #0,dp
     nop
     nop
read_iir:
     portr uart_iir,temp    ;to clear iir
     andm  #07h,temp
     ld    temp,a
     sub   #04h,a
     bc    receive_int,aeq
     ld    temp,a
     sub   #02h,a
     bc    transmit_int,aeq
     b     quit_int

receive_int:
     ld   counter_rx,a
     bc   end_int, aeq			; if counter_rx==0, return!
     sub  #1,a
     stl  a, counter_rx  		; save counter of rev data 
     portr uart_data,rx_temp	; read uart data
     ld    ptr_rx_data,a
     nop
     nop
     stlm  a,ar0
     nop
     nop
     ld    rx_temp,a
     nop
     nop
     stl   a,*ar0+				; save uart data to buffer
     nop
     nop
     ldm   ar0,a
     nop
     nop
     stlm  a,ptr_rx_data      ; save buffer address
     b     quit_int

end_int:
     ldm  imr,a
     and  #0fffeh,a
     stlm a,imr          ; close  INT0

quit_int:
     popm ar0
     popm al
     popm ah
     popm st1
     popm st0
     rete      

transmit_int:
     ld   counter_tx,a
     bc   end_int, aeq			; if counter_rx==0, return!
     sub  #1,a
     stl  a, counter_tx  		; save counter of rev data 
     ld    ptr_tx_data,a
     nop
     nop
     stlm  a,ar0
     nop
     nop
     portw *ar0+,uart_data  	; write uart data
     nop
     nop
     ldm   ar0,a
     nop
     nop
     stlm  a,ptr_tx_data      ; save buffer address
     b     quit_int


;/*------------------------------------------------------------------------
;  The following codes used for send a string !
;-------------------------------------------------------------------------*/
_u_printf:
    frame  -1
    nop
    
    
    
wait_send:    
    ld *(counter_tx),b
    nop
    nop
    bc  wait_send,bneq		; wait for last sending to end !
    
    stlm   a,ptr_tx_data      ; save first para to buf addr
    mvdk   2h,counter_tx
    nop
    nop
    
    call   _start_uart        ; enable int mask !
    
    frame  1
    ret
    


    .end

⌨️ 快捷键说明

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