|
Z80 Build From Scratch |
|
| PAGE 13: UART Config 2 | |
|
Examine a Sketch: We'll start by looking at the code found in DPz80_RS232-Terminal-Echo-Test.asm The UART-specific EQUates for the UART registers and functions are defined in lines 6 to 15. Lines 26 to 40 show us the bit-level breakdown of the registers. Line 32 shows the LCR, the Line Control Register, UART_R3. LCR is an 8-bit register and its bit 7 has a special name and purpose: it's called the DLAB bit or Divisor Latch Access Bit. The DLAB itself, a 16-bit register, is composed of the DLM and DLL. Initially during configuration, the DLAB bit is set to a 1 so that the DLL (least significant byte) and DLM (most significant byte) can be used to set the baud rate. Once the baud rate config is completed during UART Init, the DLAB is set to 0 so the Tx and Rx buffers can be used to move an internal byte to external bits, or the reverse action of assembling external bits to an internal byte. AT that time the DLAB is no longer needed for configuration. (Reminder: Z80 command, destination, source.) In line 43+ of the code you can see $80 being loaded into the LCR (UART_R3) via the OUT instruction: address $03 (UART_R3) is put on the Address bus with IORQ asserted and $80 is sent on the Data bus. This will cause the UART to go into configuration mode and the DLAB will be temporarily enabled. In line 47, $60 is sent to address $00 (UARTbase + 0, DLAB DLL) and $00 is sent to address $01 (UARTbase + 1, DLAB DLM), thus the DLAB (DLM + DLL) contains $0060. As the comments in line 50 indicate, we have set the baud rate to 1200bps. If we had used a smaller value, the baud rate would have been higher but we want you to see the characters you type being echoed back to the terminal screen hence the reason for the slower speed. The final part of the UART initialization is to set the line protocol. Doing so will also reset the DLAB flag, concluding initialization. The value $03 from the LCR table means 8N1 or 8 bits Data, no Parity, one Stop bit. Lines 45+ were used to initialize the UART. Line 58 simply clears the Z80 accumulator, register A.
(Click to enlarge)
|
![]() |
Updated 2025-11-27