问题:我使用ARM汇编语言对LPC2104微处理器进行编程,我只是试图制作一个接收UART输入并将其传回的程序。它只是从内存中传输一个字符串就可以了,但我通过添加一个接收子程序并将内存中的字符串带走来修改它。问题必须在于接收子程序,因为我甚至无法输入UART1。我还没有编辑" loop"的内容。正确的,所以现在就忽视这一点。这是我在ARM组装或微处理器上工作的第一个学期,所以请向外行解释。
这是我的代码:
AREA uartdemo, CODE, READONLY
pinsel0 EQU 0xE002C000; controls function of pins
u0start EQU 0xE000C000; start of UART0 registers
lcr0 EQU 0xC; line control register for UART0
lsr0 EQU 0x14; line status register for UART0
ramstart EQU 0x40000000; start of onboard RAM for 2104
stackstart EQU 0x40000200; start of stack
ENTRY
start
LDR sp, =stackstart; set up stack pointer
BL UARTConfig; initialize/configure UART0
loop
BLNE Receive; receive character from UART
BLNE Transmit; send character to UART
BNE loop; continue if not a '0'
done B done; otherwise, we are done
; subroutine UARTConfig
; Configures the I/O pins first.
; Then sets up the UART control register.
; Parameters set to 8 bits, no parity, and 1 stop bit.
; Registers used:
; r5 - scratch register
; r6 - scratch register
; inputs: none
; outputs: none
UARTConfig
PUSH {r5, r6, lr};
LDR r5, =pinsel0; base address of register
LDR r6, [r5]; get contents
BIC r6, r6, #0xf; clear out lower nibble
ORR r6, r6, #0x5; sets P0.0 to Tx0 and P0.1 to Rx0
STR r6, [r5]; r/modify/w back to register
LDR r5, =u0start;
MOV r6, #0x83; set 8 bits, no parity, 1 stop bit
STRB r6, [r5, #lcr0]; write control byte to LCR
MOV r6, #0x61; 9600 baud @ 15MHz VPB clock
STRB r6, [r5]; store control byte
MOV r6, #3; set DLAB = 0
STRB r6, [r5, #lcr0]; Tx and Rx buffers set up
POP {r5, r6, pc};
; subroutine Transmit
; Puts one byte into the UART for transmitting
; Registers used:
; r5 - scratch register
; r6 - scratch register
; inputs: r0 - byte to transmit
; outputs: none
Transmit
PUSH {r5, r6, lr};
LDR r5, =u0start;
wait LDRB r6, [r5, #lsr0]; get status of buffer
TST r6, #0x20; buffer empty?
BEQ wait; spin until buffer is empty
STRB r0, [r5];
POP {r5, r6, pc};
; subroutine Receive
; Takes one byte from the UART for transmitting
; Registers used:
; r5 - scratch register
; r6 - scratch register
; inputs: r0 - byte to transmit X
; outputs: none X
Receive
PUSH {r5, r6, lr};
LDR r5, =u0start;
wait2 LDRB r6, [r5, #lsr0]; get status of buffer
TST r6, #0x00; buffer empty?
BEQ wait2; spin until buffer is empty
STRB r0, [r5];
POP {r5, r6, pc};
END