; Filename: RS232Eric.s ; Author: ECE 353 staff ; Description: solution for RS232 to Upper Echo Problem ARM EXPORT __main EXPORT Globals EXPORT DisplayPrompt INCLUDE aduc7026.inc AREA FLASH, CODE, READONLY __main ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Setup for external Cystal and 20.89MHz operation ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; LDR R1, =PLL_MMR_BASE MOV R0, #0xAA ;key1 STR R0, [R1, #PLLKEY1] MOV R0, #0x01 ;external oscillator, using PLL STR R0, [R1, #PLLCON] MOV R0, #0x55 ;key2 STR R0, [R1, #PLLKEY2] MOV R0, #0x01 ;key1 STR R0, [R1, #POWKEY1] MOV R0, #0x01 ;active, CD=1 (20.89MHz) STR R0, [R1, #POWCON] MOV R0, #0xF4 ;key2 STR R0, [R1, #POWKEY2] ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Setup USART for 38400, 8-data, no parity ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; LDR R7, =(GPIO_MMR_BASE) MOV R1, #0x11 ;; setup P0.0 and P0.1 STRB R1, [R7,#GP1CON] ;; for UART functions LDR R7, =(UART_MMR_BASE) MOV R1, #0x87 STRB R1, [R7,#COMCON0] MOV R1, #0x04 ;; 2-Stop bits, no loop back mode STRB R1, [R7,#COMCON1] MOV R1, #0 STRB R1, [R7,#COMDIV1] ;; ensure high divisor zeroed MOV R1, #0x11 STRB R1, [R7,#COMDIV0] ;; set for 38,400 baud MOV R1, #0x07 STRB R1, [R7,#COMCON0] ;; clear bit[7] so can access RX/TX MOV R1, #0x01 STRB R1, [R7,#COMIEN0] ;; only interrupt for receive ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Setup USART to interrupt in IRQ ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; LDR R7, =(IRQCON_MMR_BASE) MOV R1, #0x4000 ;; Enable USART to interrupt STR R1, [R7,#IRQEN] ;; as an IRQ event BL DisplayPrompt ;; Put up prompt first time main_loop B main_loop ; loop forever DisplayPrompt ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Description: Displays promp stored in Flash as string ;; ;; Also sends a newline and carriage return. ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; PUSH {R5-R7,LR} ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; LDR R7, =(UART_MMR_BASE) LDR R6, =(Prompt) PrmptLoop LDRB R5, [R6],#1 ;; load character of prompt string CMP R5, #0 ;; is it the null character? BEQ DnePrmpt ;; if so we are done with prompt STR R5, [R7,#COMTX] ;; write byte to terminal WaitTX LDR R5, [R7,#COMSTA0] ;; start polling bit[6] of status TST R5, #0x40 ;; is bit[6] set yet? BEQ WaitTX ;; if not keep waiting for TX to complete B PrmptLoop ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; DnePrmpt POP {R5-R7,PC} Prompt DCB "\nDumb Terminal>\0" ALIGN AREA SRAM, DATA Globals SPACE 4 ; END