bits as they’re coming in; when
rxCount is zero, we are not currently
receiving a byte.
The next instruction, JNZ, will
force the program to jump to RX_Bit
when the Z flag is not set — this
happens when we are receiving
(rxCount > 0). Since the Z flag is currently set, we will fall through the JNZ
to where we load the value of 9 (start
bit plus eight data bits) into the W
register. After that, we will check the
Carry bit; if it is 1 (and it currently is),
we will skip the loading of rxCount
and load the bit timer (rx Timer). With
rx Timer loaded, we drop into RX_Bit,
where the timer is decremented and
— if not 0 — the serial routine jumps
to the label called Multiplex.
This process will repeat every
interrupt cycle until a start bit is
received. You may be wondering — as
I did — why the rxTimer gets loaded
when there is no start bit. Well, the
reason there is no bail-out on a no
start bit condition is that it actually
adds more code than simply allowing
the rxTimer to be loaded and the
routine to exit.
Now, a start bit arrives; let’s see
what happens. This time, through,
we will move 0 into the Carry bit. As
rxCount is still 0, we will not jump to
RX_Bit, but we will end up moving 9
into rxCount (via W). Now, we load
the rxTimer with 1.5 bit periods,
decrement the timer for this interrupt cycle, and exit. On the next
interrupt, we will have 9 in rxCount,
so the code will jump right to RX_Bit
after sampling the serial line and
then the rxTimer will be decremented again. This will continue until
rx Timer is 0.
At this point, we’re actually in the
middle of the first data bit (the LSB).
We will reload the rx Timer with the bit
timing and then decrement the
rxCount to account for the start bit.
The program will drop through the SZ
(skip, if zero) instruction, since
rxCount is at eight and then move the
data bit (currently sitting in Carry)
into rxByte with the RR (rotate right)
Finally, the program will drop
through another SZ instruction and
jump out of the serial routine to the
This process will continue for
eight bits. After the final bit arrives,
rxCount will be 0 and the code will
end up skipping the JMP Multiplex
instruction and move to RX_Buffer.
This code will save the incoming byte
to a 16-byte circular buffer. This will
let our foreground program handle
important business while bytes are
streaming in. That said, it’s a circular
buffer and — if we don’t pull data from
it before it fills — it can end up overwriting itself. That won’t be a problem
with our display.
The code at RX_Buffer uses indirect addressing via the FSR (File
Select Register) to update the circular
The technology builder's source for kits, components, supplies, tools, books and education.
Robot Kits For All Skill Levels
ICs, Transistors, Project Kits
Motors, Frame Components
and Scratch Builder Supplies.
BEAM Kits and Components
Order by Internet, phone, fax or mail.
180 El Camino Real
Millbrae, CA 94030
Visit our store near SFO!
Most orders ship the day received! World-wide shipping. Convenient payment options.