NivaarExam PrepOfficial exam papers ↗

22-Elec-A4 Digital Systems and Computers · December 2019

Question 5 of 6: Serial character echo with case swap; TxD waveforms

Nivaar worked solution (AI-drafted; not reviewed by a licensed engineer)

Notes on this paper

National Exams — December 2019 · 16-Elec-A4 Digital Systems & Computers. Closed book · 3 hours · one of two approved calculators. Six questions; any five constitute a complete paper and all questions are worth 12 marks. All six are solved here as a study resource.

Reference texts: M. M. Mano & M. D. Ciletti, Digital Design (6th ed.); J. F. Wakerly, Digital Design: Principles and Practices (5th ed.); R. J. Tocci, N. S. Widmer & G. L. Moss, Digital Systems: Principles and Applications (12th ed.); Motorola/Freescale M68HC11 Reference Manual; V. C. Hamacher, Z. G. Vranesic & S. G. Zaky, Computer Organization (5th ed.).

Check — figure readings. The two circuit figures are redrawn below from the printed paper. Readings used below: Q1’s second and fifth product terms are $A\overline{B}C$ and $\overline{A}\,\overline{B}C\overline{D}$; Q2(a) asks for 8:1-multiplexer realizations and gives $ABC=011$ and $111$ as don’t-cares for $f_1$; Q3’s gates are three-input ANDs and flip-flop $B$ is wired as a toggle ($R_B=B$, $S_B=\overline{B}$), so the circuit is a binary up/down counter; Q4’s flip-flop clock is taken from decoder output ̅Y2 (third output down), not ̅Y0. Each correction is explained in the relevant answer.

Question 5: Serial character echo with case swap; TxD waveforms (12 marks)

Question text not reproduced: the examination questions are © Engineers and Geoscientists BC. Open the official past paper (linked at the top of this page) to read the question, then follow the worked solution below.

Given. 9600-baud, already-initialized async serial port; a blocking receive routine inchar ($FFCD_{16}$) returning the char in ACCA; interrupt-driven transmit; received character ‘U’ $=55_{16}$, its lowercase ‘u’ $=75_{16}$.

Find. (a) the program algorithm; (b) the two TxD waveforms with full labels and scales.

Approach (part a). Case is a single ASCII bit: letters differ between upper- and lowercase only in bit 5 ($20_{16}$), so an $\text{EOR }\#20_{16}$ toggles case in one instruction. Receive by polling via inchar, toggle case, then hand the byte to an interrupt-driven transmit routine.

  1. Receive. $\text{JSR}$ inchar — blocks until RDRF (receive-data-ready) is set, returning the character in ACCA ($=55_{16}$ for ‘U’).
  2. Convert case. $\text{EORA }\#20_{16}$ flips bit 5: $55_{16}\;(0101\,0101)\;\oplus\;20_{16}=75_{16}\;(0111\,0101)=$ ‘u’. (For a lowercase input the same XOR maps it back to uppercase.) Store the byte in a one-character buffer.
  3. Arm the transmit interrupt. Set the transmit-interrupt-enable bit in CR (enable TDRE / TIE). With the global interrupt mask cleared, the CPU may continue other work.
  4. Transmit ISR. When TDR is empty the port raises its TDRE flag → interrupt. The service routine reads the buffered ‘u’, writes it to TDR (which serializes start + 8 data + stop at 9600 baud), then clears TIE so no further transmit interrupt occurs for this single character, and returns ($\text{RTI}$).

Part (b) — the transmitted frame. Because the program echoes the converted character, the byte on TxD is ‘u’ $=75_{16}=0111\,0101$. In an 8-N-1 async frame the line idles high, drops for one START bit, then sends the eight data bits least-significant first ($d_0\!\dots\!d_7 = 1,0,1,0,1,1,1,0$), then one STOP (high) bit. Each bit lasts $1/9600 = 104.2\ \mu\text{s}$.

(i) TxD at board (CMOS logic) - transmitting 'u' = 75h+5 V (mark/1)0 V (space/0)idle1idle1START0d01d10d21d30d41d51d61d70STOP1idle1|<-- 104.2 us/bit (9600 baud) -->|Idle = HIGH; START = 1 low bit; 8 data LSB-first (75h); STOP = 1 high bit.
Figure 5.1 — (i) TxD at the board (CMOS): idle/mark $=+5$ V, space $=0$ V; frame for ‘u’ $=75_{16}$, LSB first.
(ii) Same 'u' stream on RS-232 cable (after drivers)+12 V (space/0)-12 V (mark/1)idle0idle0START1d00d11d20d31d40d50d60d71STOP0idle0|<-- 104.2 us/bit (9600 baud) -->|RS-232 inverts and shifts levels: mark(1)=-12 V, space(0)=+12 V.
Figure 5.2 — (ii) same frame on the RS-232 cable: drivers invert and shift levels — mark(1)$=-12$ V, space(0)$=+12$ V.

The two waveforms carry identical timing and identical bit meanings; only the electrical convention differs. On the board a logic 1 is $+5$ V and the idle line sits high; the RS-232 driver inverts the logic and uses bipolar levels, so a mark(1) becomes $-12$ V and a space(0) becomes $+12$ V — the idle line therefore sits at $-12$ V and the START bit swings positive.

Question 5 results
ItemResult
(a) case toggle$\text{EORA }\#20_{16}$ (flip ASCII bit 5); interrupt-driven TDR write
transmitted byte‘u’ $=75_{16}=0111\,0101$
(b) frameSTART(0) + $d_0..d_7$(1,0,1,0,1,1,1,0) + STOP(1), 104.2 µs/bit
board / cable levelsCMOS: 1$=+5$ V; RS-232: 1$=-12$ V (inverted, bipolar)