Home

Z80  Programming VI-b

UART Terminal String and Echo Test

Page a    Page b

Quick Summary:

The label "RS232_Echo" contained the string we wished to send out the UART to our PC's terminal screen (Tera Term terminal emulation software). You can see it at the bottom of the adjacent screenshot.

We used the UART_PRNT_STR function to print the string. It depended upon UART_TX to send each character but first it had to check if the 16550 UART was ready to send by using the function UART_TX_READY.

Once every character including the Carriage Return ($0D) and Line Feed ($0A) had been sent, the UART_PRNT_STR was finished and the program fell through to the next line of code.

 

Send a character, echo a character

ECHO is the label we see adjacent in line 59. The first line below this loop (there is a "JP ECHO" in line 62) is "CALL UART_RX", followed by "CALL UART_TX". We're already familiar with the latter so let's focus briefly on the former.

 

The user will at some undetermined time, press a key. That will invoke the send function discussed above. If local echo is enabled on the PC terminal as it usually is, then it will send the bits of the echoed character back to your Z80 system's UART.  Line 60 shows the UART_RX call being made; this takes us to line 120. In line 121, the UART_RX_RDY call is made to line 107. The return addresses for both CALLs have been saved on the stack as has Register pair "AF" in line 108.

In line 110, the contents of UART5 are checked again as they were in the UART_TX_RDY function but this time we're looking at bit 0 instead of bit 5. If it's a zero, we loop. If it's a one it's because there is now a character in the receive buffer from the echoing PC terminal.

In line 113, we "POP AF" and return to the UART_RX function at the line following the CALL of line 121. Line 122 indicates the contents of the receive buffer, UART0, are now available (8 bits have been assembled from the 10 bits, including Start and Stop bits, put on the wire) and are transferred to Register A.

 

Do we really know if UART_RX is working properly?

Not really. The received character is not echoed back to the user screen. It's just as well or typing one character on your keyboard would be an endless stream of characters to the screen.

 

How can we really tell if UART_RX is working? In a later exercise involving either the ROM Monitor or ROM BIOS, we'll put the Z80 in receive mode, startup a file transfer process on the PC terminal emulation software, and download a standalone program we wrote to run in RAM. If the download succeeds and we are able to run the program, we can be certain the UART_RX function is working properly.

 

Home