URL
https://opencores.org/ocsvn/uart6551/uart6551/trunk
Subversion Repositories uart6551
[/] [uart6551/] [trunk/] [trunk/] [software/] [uart6551demo.asm] - Rev 13
Go to most recent revision | Compare with Previous | Blame | View Log
XON equ $11XOFF equ $13LEDS equ $FFDC0600UART equ $FFDC0A00code 18 bitsorg $FFFC0000start:ldi $sp,#$80000-4 ; setup system mode stack pointer; Switch to user mode.0004:eret; When an ECALL instruction is executed it'll start here.bra .0004;------------------------------------------------------------------------------; User mode code starts here;------------------------------------------------------------------------------org $FFFC0100ldi $sp,#$80000-1028 ; setup user mode stack pointeradd $t0,$x0,#$AB ; turn on the LEDstt $t0,LEDScall SerialInitldi $t2,#16 ; send an XON just in caseldi $a0,#XON.0004:call SerialPutCharsub $t2,$t2,#1bne $t2,$x0,.0004ldi $a0,#'A' ; Try sending the letter 'A'call SerialPutChar.0002:ldi $a0,#msgStart ; spit out a startup messagecall SerialPutString; Now a loop to recieve and echo back characters.0003:call SerialPeekCharblt $v0,$x0,.0003mov $a0,$v0call SerialPutCharbra .0003;------------------------------------------------------------------------------; SerialPeekChar;; Check the serial port status to see if there's a char available. If there's; a char available then return it.;; Modifies:; $t0; Returns:; $v0 = character or -1;------------------------------------------------------------------------------SerialPeekChar:ldb $t0,UART+4and $t0,$t0,#8 ; look for Rx not emptybeq $t0,$x0,.0001ldb $v0,UARTret.0001:ldi $v0,#-1ret;------------------------------------------------------------------------------; SerialPutChar; Put a character to the serial transmitter. This routine blocks until the; transmitter is empty.;; Parameters:; $a0 = character to put; Modifies:; $t0;------------------------------------------------------------------------------SerialPutChar:.0001:ldb $t0,UART+4 ; wait until the uart indicates tx emptyand $t0,$t0,#16 ; bit #4 of the status regbeq $t0,$x0,.0001 ; branch if transmitter is not emptystb $a0,UART ; send the byteret;------------------------------------------------------------------------------; SerialPutString; Put a string of characters to the serial transmitter. Calls the; SerialPutChar routine, so this routine also blocks if the transmitter is not; empty.;; Parameters:; $a0 = pointer to null terminated string to put; Modifies:; $t0 and $t1; Stack Space:; 2 words;------------------------------------------------------------------------------SerialPutString:sub $sp,$sp,#8 ; save link registerstt $ra,[$sp]stt $a0,4[$sp] ; and argumentmov $t1,$a0 ; t1 = pointer to string.0001:ldb $a0,[$t1]add $t1,$t1,#1 ; advance pointer to next bytebeq $a0,$x0,.done ; branch if donecall SerialPutChar ; output characterbra .0001.done:ldt $ra,[$sp] ; restore return addressldt $a0,4[$sp] ; and argumentadd $sp,$sp,#8ret;------------------------------------------------------------------------------; Initialize serial port.;; Modifies:; $t0;------------------------------------------------------------------------------SerialInit:ldi $t0,#$0B ; dtr,rts active, rxint disabled, no paritystt $t0,UART+8ldi $t0,#$08070012 ; reset the fifo'sstt $t0,UART+12ldi $t0,#$08010012 ; baud 115200, 1 stop bit, 8 bit, internal baud genstt $t0,UART+12ret;------------------------------------------------------------------------------; Message strings;------------------------------------------------------------------------------msgStart:db "uart6551 Demo Starting.",13,10,0
Go to most recent revision | Compare with Previous | Blame | View Log
