Note 02 of 02: 笔记 02 / 02:Common-Anode Displays and BCD Decoding共阳数码管与 BCD 译码
Following decimal digit splitting and BCD bit order into active-low LS47 outputs, common-anode LED current paths, segment resistors, and display controls.沿十进制拆位与 BCD 位序,理解 LS47 低有效输出、共阳 LED 电流路径、逐段限流和显示控制。
When the two digits read 17, it looks as if the program simply carried a number onto the breadboard. There are several layers in between: the Arduino holds an integer, the decoders receive two groups of four voltage levels, and what finally lights up is a handful of LED segments. Back when I wired the common pin to ground as the course slides showed, the display stayed dark, and the wiring that worked was found by trial and error. The reasoning behind it was never filled in.
两位数码管亮出 17,看上去就像程序把一个数搬到了面包板上。中间其实隔着好几层,Arduino 手里是一个整数,译码器收到的是两组四位电平,最后亮起来的是几段 LED。当年按课件把公共端接到地,数码管一片黑,能用的接法是靠瞎试找到的,背后的道理一直没补上。
Decimal Digits and BCD十进制数与 BCD
The project report splits the digits plainly, Num % 10 for units and (Num / 10) % 10 for tens. Feeding in 17 gives 7 and 1, which go to separate decoders. BCD spends four binary bits on each decimal digit, so the display needs two independent codes, 0001 and 0111. Written straight out in binary, the integer 17 is 10001, which is a different thing altogether from what the two digits need.
作业报告里拆位很直接,Num % 10 取个位,(Num / 10) % 10 取十位。17 代进去,个位 7、十位 1,分别送给两颗译码器。BCD 用四个二进制位表示一个十进制数字,所以这里要的是两组独立的编码,0001 和 0111。整数 17 直接按二进制写是 10001,跟两位显示要的东西压根不是一回事。
In the single-digit example, the simplest digit of all is the one that made me stop. The array stores 1 as {1, 0, 0, 0}, while written binary usually reads 0001. The pin definitions settle it. The program stores bits in A, B, C, D order with weights 1, 2, 4 and 8, whereas written binary puts the most significant bit on the left. The first array element goes to A, so the order is exactly right; it just looks reversed.
读单个位显示示例时,最简单的 1 反倒让我愣了一下。数组里写的是 {1, 0, 0, 0},平时写二进制,习惯看到的却是 0001。对一下引脚定义就明白了,程序按 A、B、C、D 的顺序存,权重依次是 1、2、4、8;平时书写则把最高位放在左边。数组第一个元素发给 A,顺序完全对得上,只是看着反过来了。
Decimal digit D C B A Array order A, B, C, D
1 0 0 0 1 1, 0, 0, 0
7 0 1 1 1 1, 1, 1, 0The example has sixteen rows of codes, yet the main loop uses % 10 to keep the index between 0 and 9. Four wires can express sixteen combinations and one decimal digit uses ten, and the remaining six cannot be assumed to show hexadecimal letters. TI's LS47 description assigns those six inputs particular patterns, while the CD4511B simply blanks any input above 9. Swapping in another decoder means checking what it shows outside 0 to 9 as well.
示例里一共写了十六行编码,主循环却用 % 10 把索引限制在 0 到 9。四根线能表示十六种组合,十进制的一位只用其中十种,剩下六种也不能想当然地当成十六进制字母。TI 的 LS47 说明给这六种输入定义了特定图形,CD4511B 遇到大于 9 的输入则直接消隐。换一颗译码器,0 到 9 之外的输入会显示成什么,也得一起查。
Active-Low Outputs低有效输出
A through D only choose the digit; the decoder's a through g outputs are what map onto the seven LED segments. With the usual segment labels, 7 lights the top segment a, upper-right b and lower-right c. On the SN54LS47, those segments light when their outputs go low. The LS47 datasheet marks its outputs active-low and open-collector, for driving common-anode displays. Why a low level should turn a segment on only makes sense along the current path.
A 到 D 只负责选数字,真正对应七段 LED 的是译码器的 a 到 g。按常用的段位标记,显示 7 要点亮顶上的 a、右上的 b 和右下的 c。对 SN54LS47 来说,这几路输出变低,对应的段才亮。LS47 数据手册把它的输出标成低有效、开集电极,用来驱动共阳数码管。低电平为什么反而点亮,得放进电流路径里看。
A common-anode display ties the anodes of all its segments together and connects that common pin to the positive supply. When a segment is selected, the matching output transistor inside the LS47 turns on, and current runs from the supply through that LED and its series resistor, into the decoder and down to ground. Pulling the output low gives the LED its forward voltage, and it lights. Walk that path once and a low level lighting a segment stops feeling backwards. Wiring the common pin to GND, as we first did, cuts the supply off at the very start of the path, so a dark display is no surprise.
共阳数码管把各段 LED 的阳极连在一起,公共端接正电源。选中某一段时,LS47 里对应的输出晶体管导通,电流从正电源出发,经过这段 LED 和串联的限流电阻,流进译码器,再回到地。输出一拉低,LED 两端就有了正向电压,于是发光。顺着这条路走一遍,低电平点亮这件事就不别扭了。当年把公共端接到 GND,这条路从起点就没了电,数码管黑着也就不奇怪了。
Open-collector operation deserves a word of its own. When the output transistor turns off, the chip merely lets go of that path to ground. The output goes high-impedance and its voltage is set by the external circuit; it does not push the pin up to the supply the way a push-pull output would. The segment-off state in the truth table, the voltage a meter reads at the pin, and whether the pin can source current are therefore three separate questions. Reading this far explained why the datasheet gives the part two identities at once, decoder and driver.
开集电极也值得单独说两句。输出晶体管关断时,芯片只是松开了这条到地的路径,输出端处于高阻,电压由外部电路决定,不会像推挽输出那样主动把引脚推到电源。所以真值表里写的熄灭、万用表在引脚上量到的电压、这个引脚能不能往外送电流,要分开理解。读到这儿,我才明白数据手册为什么给它同时安了译码器和驱动器两个身份。

Segment Current and Resistor Selection段电流与限流电阻
The course slide asks for one series resistor on every segment output. Why not a single resistor at the common pin? If all seven segments shared one, showing 1 would split the current between two branches and showing 8 between seven. As the number of lit segments changes, so does the current each one gets, and brightness starts to depend on the digit. With a resistor in each segment branch, every segment's current is limited on its own.
课件要求每个段输出各串一只限流电阻。为什么不在公共端放一只就完事?假如七段共用一只电阻,显示 1 时只有两条支路分电流,显示 8 时变成七条。亮的段数一变,每段分到的电流跟着变,数字不同,亮度也不同。电阻放到各段支路上,每段的电流才各管各的。
Estimating one segment means subtracting both the LED's forward drop and the driver's on-state low voltage from the supply. Assume a 5 V supply, an LED forward drop of 2.0 V near the target current, and 0.3 V across the driver output. Aiming for about 5 mA gives (5 − 2.0 − 0.3) / 0.005 = 540 Ω, and the common 560 Ω value gives roughly 4.8 mA under the same assumptions. These numbers only show how a value is chosen; real displays and chips need their own parameters.
估算一段时,要把 LED 的正向压降和驱动器导通后的低电平一起扣掉。假设电源 5 V,LED 在目标电流附近的正向压降 2.0 V,驱动输出压降按 0.3 V 算,想让段电流在 5 mA 左右,电阻约为 (5 − 2.0 − 0.3) / 0.005 = 540 Ω。换成常见的 560 Ω,同样假设下大约 4.8 mA。这组数只是演示怎么选值,具体的数码管和芯片还得按各自的参数算。
Worked that way, the slide's 330 Ω becomes something to question. A resistor value belongs with the supply, the current and the LED drop; keep 330 Ω and change the LED, and the current need not stay the same. When 8 lights all seven segments, the seven currents also add up at the common pin, so the load on the supply and the decoder needs checking too.
这么一算,课件里的 330 Ω 就有了可以追问的地方。电阻值要和供电、电流、LED 压降放在一起看,同样是 330 Ω,换一种 LED,电流未必一样。显示 8 时七段全亮,七路电流还要在公共端加起来,电源和译码器的负担也得一起检查。
Decoder and Display Compatibility译码器与数码管的匹配
Set the course simulation's CD4511B beside it and the difference becomes concrete. That chip supplies segment current for common-cathode LEDs: a selected output goes high, and current flows from the output through the LED and its resistor to the common cathode and ground. Feed the same digit into both chips and they want opposite common connections and opposite active levels. Both turn BCD into a seven-segment pattern, yet the LED wiring has to follow the output structure. Pairing the CD4511's wiring with LS47 hardware is exactly where the course slides went wrong.
再拿课件仿真里的 CD4511B 对照,差别就落到了实处。它给共阴 LED 提供段电流,选中的段输出高电平,电流从输出端经过 LED 和限流电阻流到公共阴极,再回到地。同一个数字送进去,两颗芯片要求的公共端接法和有效电平正好相反。它们都能把 BCD 变成七段图形,LED 怎么接,却得跟着输出结构走。课件拿 CD4511 的接法去配 LS47 的实物,问题就出在这里。
Correct data inputs are not the end of it; the test and blanking pins matter too. The LS47 controls include lamp test, blanking and ripple blanking, and they also decide what appears. Check only A through D and ignore them, and the input digit can be right while the whole display stays off. To check a single digit I would first set those pins for normal decoding from the truth table, then feed 1, 7 and 8 in turn: the two right-hand segments, then the top one added, then all seven.
四位输入对了还不算完,测试和消隐脚也得看。LS47 的控制说明里有灯测试、消隐和零消隐,这几个脚同样在决定显示什么。只查 A 到 D、忽略了它们,就可能碰上输入数字没错、整位却被关掉的情况。调单个位时,我会先按真值表把这几个脚设到正常译码的状态,再依次送 1、7、8,先看右边两段,再加上顶上一段,最后七段全亮。
A missing segment and a whole digit showing the wrong number start from different places. The first is traced along that segment's LED branch; the second begins with the BCD bit order and the decoder's control pins. Once the visible error, the pins that govern it and the path the current should take line up, finding the fault no longer depends on poking jumper wires and hoping.
缺了一段,和整位显示成了另一个数字,排查的起点不一样。前者顺着那一段的 LED 支路去查,后者先核对 BCD 位序和译码器的控制脚。看到的错误、管着它的引脚、电流该走的路,这几样能对上,就不用再靠瞎插杜邦线碰运气了。