Home

Z80  Programming VI

 

UART Terminal String and Echo Test

Page a    Page b

Overview:

In this section, we're going to look at setting up a few procedures/functions/routines we can call upon whenever we need serial I/O performed.

 

Before we get started you'll notice there is a new statement highlighted in the adjacent screenshot of RS232_String_Echo.asm. The "#define" statement reads "When you see EQU, replace it with .equ". That will allow us to use "EQU" instead of ".EQU" throughout our code. There are much more important uses for "#define" but now you've got some exposure to its usefulness.

You may also notice that numbers like "08" are showing as "08h" instead of "$08". TASM doesn't seem to care, so if the assembler is happy, we're happy.

We're showing only the relevant portions of the code (some screenshot portions have been stitched together).

Our code will start at address $0000 as shown by the assembler directive ".ORG $0000".

Lines 29 to 32 show a few variables we have setup such as the start of ROM and the end of RAM.

 

Some new pointers:

In line 35, we are telling the assembler where to locate the Stack Pointer - at address $FFFF. What do you think would happen if instead of writing "LD SP, RAM_END" we inadvertently coded "LD SP, ROM_END"?

Would the file assemble?  Yes.  Would it run? No.  The Assembler is not responsible for ensuring everything is in the correct location; that's where you come in. 

Imagine if you had a "PUSH AF" statement in your code. Instead of the contents of register AF being saved temporarily at locations $FFFF and $FFFE in RAM, the processor would try to write the contents into ROM at $7FFF and $7FFE. This is impossible, of course, unless you had wired your system to write to the EEPROM or replaced the EEPROM with an NVRAM, or both. So when the CPU later tries to POP AF off the stack, it would not exist which would most likely make your program crash or act weirdly compared to what you expected.

Time to initialize:

In the previous coding segment we examined the UART Initialization in some detail. We'll quickly review that now.

Starting in line 40, we are initializing the 16550 UART. Sending $80 is the same as sending 1000 0000 in binary. Bit 7 is set to a one which enables the DLAB in UART3, the Line Control Register. We send $000C to the DLAB (UART0 and UART1) to set the baud rate to 9600bps in lines 43 to 46, and in lines 47 to 48 we set the serial line protocol to 8-N-1 for byte framing. This also resets the DLAB flag so now UART0 register has finished its participation in the UART initialization procedure and will be used for its primary function of sending and receiving data.

NEXT PAGE  =>

 

TOP

 

Home