Read the prelude to this article.
Update (31 Dec 2009, 10:41AM) Corrected the schematic illustration showing how to connect a decoder to LEDs. The LEDs were connected backwards, oops!
Update (21 Feb 2008, 10:07PM) In an earlier draft, I noted that the two endcars were treated completely differently. This, as I quickly realized, is not true. The instructions for both endcars are almost exactly the same. My mistake!
I’ve got my DZ163 back from repair by Digitrax, and soon I will be re-installing it into my KIHA110. I haven’t yet tried to wire it up to the headlights/taillights yet, and since there are others who are interested in understanding how this works, I offer first some preparatory remarks on the process.

DC headlight circuit
This is the basic circuit used by most headlights. The circles with the triangles in them are light-emitting diodes (LEDs); the squiggly thing is a resistor, and the parallel lines with the plus sign represents a battery—in our case, the power provided over the rails.
The resistor is there because most LEDs really want less than 12v, which is what N-gauge throttles provide at max speed. If the resistor weren’t there, the LED would glow much brighter…and burn out pretty quickly.
Diodes are like one-way gates: They allow current to flow in one direction only. And the light-emitting variety only light when current is passing the right way. Notice that the two diodes are pointed in opposite directions. This is so that when the train is moving forwards, current only flows through the headlight, and when the train is moving in reverse, current only flows through the taillight.

Headlight On
Here, the train is moving forwards—the current is flowing clockwise, with the arrow, lighting the headlight, and…

Taillight On
Here the train is moving in reverse—the current is flowing counter-clockwise. In each case, only the one light lights up. On the opposite end, the circuit is the same, but the two LEDs are reversed, so that the opposing taillight comes on when the train is moving forwards, and the opposing headlight comes on when the train is moving backwards.
You should see why both lights always come on when put on DCC powered track: Being an AC voltage, current alternately flows clockwise then counter-clockwise very rapidly, providing power to both with each cycle, just not at the same time.
We’d like more control! Here is the simplest way to insert a two function function-only DCC decoder into this diagram. The decoder has a white wire for F0f (function zero, forward), a yellow wire for F0r (function zero, reverse), one blue common source, a red wire for the right-hand side pickup, and a black wire for the left-hand side pickup. (This is Digitrax’s color scheme, at least; I don’t know off the top of my head if these colors are part of the NMRA standard, so be sure to read your decoder’s manual!)

Lights Wired for DCC
Above shows how this decoder is shoe-horned into our schematic diagram. Notice first and foremost that the headlight has been reversed! This is because the function outputs of the decoder are always at ground, and the blue common is always at +12V. So we have to turn the LED around! The key point to remember is that the function leads always get wired to the LED cathode (the lead with the larger electrode; see below).
But the basic procedure is to isolate the lights from the track power, just as you would isolate the motor. But leave that resistor intact! We need that to keep from burning the LEDs out. Once the lights are isolated, we wire white F0f to the headlight input, the yellow F0r to the taillight, and the blue common return to the other side of the common resistor (and the red and black leads to the wheel pickups, just as usual). On the rear endcar, the wiring will be slightly different: white F0f will go to the taillight, and yellow F0r will go to the headlight. This way, the taillights will come on in the rear endcar when the train is moving forwards, and the headlights will come on in the rear endcar when the train is moving backward.
So, how does this translate from the realm of abstract diagrams to the world of circuit boards? Here is the circuit-board from my KIHA 110 (shamelessly ripped from Kato Japan, and modified to remove their bad advice). The actual circuit-board is much messier than this very neat diagram lets on.

Kato 6018 Lightboard
But that doesn’t look anything like the schematic up top, does it? The big gray areas on the left and right have brass pickups soldered to them; these pickups contact brass strips in the body of the loco, which in turn brush against pickups in the trucks. At the top is the headlight LED, and at the bottom is the taillight LED. Note that these are actually on the other side of the board—I’ve ‘bent’ them into view for this diagram. The box with the number is the little resistor.

Flow of Current in 6018 while Moving Forward
Above, as in the schematic diagrams, we’re running current through the board, as though it were in a train, on the tracks, and being run forward. Current from the tracks enters through the pad on the left, runs through the one-way gate of the headlight LED, through the resistor, then out the pad on the right, returning to the tracks.

Flow of Current in 6018 while Moving Backward
And again above, as in the schematic diagrams, we’re running current through the board, as though it were in a train, on the tracks, and being run backward. Current from the tracks enters through the pad on the right, runs through the resistor, then through the one-way gate of the taillight LED, and out the pad on the left, returning to the tracks. We should see now how we will wire our decoder to this board.

6018 Modified for DCC
Not shown is where the red and black leads go. I will just solder them directly to the brass strips that run through the frame. This is easiest, and it leaves more space on the circuit-board for us to work with. This may not always be an option, however. Also not shown is that we remove the brass strips soldered onto the left and right pads; this will effectively isolate the board from the track. We then use a small saw to cut the left pad into two. Make sure the two pads don’t touch anywhere! Then, and this is very important! we remove the taillight, rotate it 180º, and put it back in! That is, we put what was the left lead into the right hole, and vice-versa. The key point to remember is that the function leads always get wired to the LED cathode (the lead with the larger electrode), as shown above. Then solder wires to the pads as shown.
Then, just repeat the same process for the other endcar, swapping white F0f for yellow F0r (as mentioned above).
Well, that’s the theory! Next time, the practice!
Continue to Part 2.
This is a fantastic post! I am re-reading your posts on this series in anticipation of my 787′s conversion to DCC!