📄 uartasm_mcu.asm
字号:
.title " test vc5402'uart"
.global _pllx100, _init_start,_pc_uartint,_start_uart,_u_printf
.global _pllx10, _key_input,_mcu_uartint
.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
; /* MCU UART USE 15C550 , it BASE ADDRESS IS 0A000h */
uart_data .set 0a000h ;uart RBR,THR(DLAB=0);DLL(DLAB=1) register address
uart_ier .set 0a001h ;uart IER(DLAB=0);DLM(DLAB=1) register address
uart_iir .set 0a002h ;uart IIR,FCR register address
uart_lcr .set 0a003h ;uart LCR register address
uart_mcr .set 0a004h ;uart MCR register address
uart_lsr .set 0a005h ;uart LSR register address
uart_msr .set 0a006h ;uart MSR register address
uart_scr .set 0a007h ;uart SCR register address
.text
;/*------------------------------------------------------------------------
; The following codes switch to 100MHz clock !
;-------------------------------------------------------------------------*/
_pllx100: ; change PLL is x10, CLK=100MHz
pshm ah
pshm al
stm #0,58h
wait_pll:
ldm 58h,a
and #1,a
bc wait_pll,aneq
stm #77ffh,58h ; switch pll*8 -> 160M clk
rpt #100
nop
popm al
popm ah
ret
;/*------------------------------------------------------------------------
; The following codes switch to 10MHz clock !
;-------------------------------------------------------------------------*/
_pllx10: ; change PLL is x1, CLK=10MHz
pshm ah
pshm al
stm #0,58h
wait_pll1:
ldm 58h,a
and #1,a
bc wait_pll1,aneq
stm #17ffh,58h ; switch pll*1 -> 10M clk
rpt #100
nop
popm al
popm ah
ret
;/*------------------------------------------------------------------------
; The following codes init UART and same important regs !
;-------------------------------------------------------------------------*/
_init_start:
ssbx intm ; close all int ! (ssbx intm)
pshm st1
pshm st0
call _pllx10 ; 10MHz
rsbx cpl ; CPL=0,USE dp !
stm #10h,36h ; stop TIMER1 !
stm #10h,tcr ; stop TIMER0 !
stm #0ffffh,prd ;
stm #0fh,tcr ; TIMER0 start, each about 10HZ(for 100MIPS) ....
; stm #0ffh,sp ; sp= 0x0ff
ld #0,dp ; dp=0
stm #3fa0h,pmst ; vector table start: 0x3f80
stm #0ffffh,ifr ; clear all int !
ldm imr,a
and #0fff5h,a
stlm a,imr ; close INT1
stm #0f994h,swwsr ; program(xpa=1,0-3fffff) 4 waits, D0-D2
; data(0x8000-0xffff) 4 waits, D9-D11
; IO (0x0 - 0xffff) 7 waits , D12-D14
stm #0,swcr
nop
stm #0,temp
portw temp,0c000h ; close all LED!
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 !
; for C call ! CPL=1
;-------------------------------------------------------------------------*/
_start_uart:
frame -1
nop
ssbx intm ; close all interrupt
ldm imr,a ; IMR -> A
or #2h,a ; enable INT1 !
stlm a,imr
; st #0h,0h
; portw 0h,uart_data ;enable receive,send ints
frame 1
__ret:
rete ; return and enable all interrupt
.end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -