Project 10 of 11: 项目 10 / 11:Arduino Breadboard Two-Digit Seven-Segment CounterArduino 面包板两位数码管计数器

For MEC104 Group A17, I handled most of the two-digit counter’s wiring, firmware, and debugging. Testing the display segments and measuring switch contacts resolved faults that code changes had not.我承担 MEC104 A17 组两位计数器的大部分搭建、编程与调试。数码管接法和六脚按键先后出问题,我通过逐段试灯、测量开关通断,把显示、暂停和复位调通。

Arduino Breadboard Two-Digit Seven-Segment Counter / Arduino 面包板两位数码管计数器
FIG. 01图 01Arduino Breadboard Two-Digit Seven-Segment CounterArduino 面包板两位数码管计数器

Two-Digit Counter两位计数器

MEC104 was a group project, and a friend pulled me into Group A17. I had just finished the Arduino car, so this was my second brush with embedded work. I could not draw a PCB yet and had only a hazy idea of how electronic parts worked, though my interest was strong. My entire understanding of the task was to write an Arduino counting program, flash it, and use the board as a stopwatch. Building the breadboard, looking up pins, wiring the decoders and displays, writing the Arduino program, debugging the buttons and final integration were nearly all mine; the other members handled the report, the video and the group's other business.

MEC104 是小组项目,我是被朋友拉进 A17 组的。刚做完 Arduino 小车,这是我第二次碰嵌入式,PCB 还不会画,电子元件的原理也模模糊糊,就是兴趣一直很足。对这个项目,我当时的全部理解就是写一个计数的 Arduino 程序,烧进去,当秒表用。面包板搭建、查引脚、译码器和数码管接线、Arduino 程序、按键调试和最后的联调,基本都是我做的;报告、视频和小组里的其他事情由组员负责。

Breadboard digital-clock counter prototype / 面包板上的两位数码管计数器原型
Breadboard digital-clock counter prototype面包板上的两位数码管计数器原型
Course project requirement slide / 课程项目目标页
Course project requirement slide课程项目目标页
Basic two-digit and button requirements / 两位显示与按键要求
Basic two-digit and button requirements两位显示与按键要求

Once the parts were laid out, the job clearly went well beyond one program. Beside the Arduino Nano sat two SN54LS47 decoders, two seven-segment displays and a thicket of jumper wires. The count had to be split into tens and units, each sent as four BCD bits to its own decoder, which then lit its display. The report puts the units on D9 to D12 and the tens on D5 to D8. What BCD was and how a seven-segment display worked, I learned right then from the course slides and online material, and I wrote the Arduino program while looking things up on CSDN as I went.

实物摆开以后才发现,要做的远不止一个程序。Arduino Nano 旁边是两颗 SN54LS47 译码器、两位数码管和一大片杜邦线。计数值要先拆成十位和个位,各用四位 BCD 送进一颗译码器,再由它点亮对应的数码管。报告里个位的 BCD 接在 D9 到 D12,十位接在 D5 到 D8。BCD 是什么、七段数码管怎么显示,我也是这时候边看学校发的课件、边上网查才弄懂的,Arduino 程序更是边查 CSDN 边写。

Two-digit wiring from the homework report / 作业报告里的两位数码管接线图
Two-digit wiring from the homework report作业报告里的两位数码管接线图
Digit split code from the homework report / 作业报告里的个位和十位拆分代码
Digit split code from the homework report作业报告里的个位和十位拆分代码

Common-Anode and Common-Cathode Wiring数码管的共阳与共阴接法

With the digit-splitting code written, the displays refused to cooperate. The course slides showed a common-cathode arrangement with the common pin on GND. Wired that way, the displays either stayed completely dark or lit up in gibberish, nothing like normal behaviour. That held us up for a long time. We asked the TA, who could not explain it either and may not have realized that the slides and the parts we had been given did not match.

拆位程序写好了,数码管却不配合。课上 PPT 给的是共阴接法,公共端接 GND。我们照着接,数码管要么一片黑,要么亮出一堆乱码,完全不是正常的样子。这件事卡了我们很久。去问 TA,TA 也说不出个所以然,可能他也不知道 PPT 和发下来的器件根本对不上。

In the end I found it by trial and error, poking jumper wires around the breadboard. A seven-segment display is really just a few LEDs arranged in a fixed shape, and whichever segments light make the digit. Moving wires segment by segment and trying high and low levels, I gradually worked out that our displays needed a common-anode connection with the common pin on VCC; the slides' common-cathode wiring simply did not work with our parts. When the pattern finally showed itself, even I thought it was pretty amazing.

最后是我在面包板上拿杜邦线瞎插瞎试摸出来的。七段数码管说到底就是几个 LED 摆成固定的形状,哪几段亮,就显示哪个数字。我一段一段换线、试高低电平,慢慢发现手里这套显示要按共阳接,公共端得接 VCC,PPT 那套共阴接法放到我们的器件上就是不灵。摸出这个规律的时候,我自己都觉得挺神奇。

Rather than go back to the TA, we took it straight to the professor, who picked up the microphone and told the whole class; several other groups were stuck at exactly the same point. To an experienced hardware engineer, common anode versus common cathode is probably the first thing to suspect once something looks off. To a room of students who had only just learned to push jumper wires into a breadboard, it was an enormous problem, and searching online turned up nothing, because it is too basic for anyone to bother writing about.

我们没再回去找 TA,直接找了任课老师。老师拿起麦克风跟全班讲了这件事,好几个组其实也卡在同一个地方。对成熟的硬件工程师来说,共阳共阴大概是一看不对劲就会想到的小事;可对一群刚学会往面包板上插杜邦线的学生来说,这就是天大的问题,网上还搜不到答案,太基础了,没人会专门写。

At the time I still could not explain the decoder's output structure. The SN54LS47 datasheet in this archive is one I found later. According to TI's LS47 documentation, its outputs are active-low and open-collector, designed for common-anode displays, while the CD4511 in the course simulation drives common-cathode ones. The current path behind that is worked through in Common-Anode Displays and BCD Decoding.

当时的我还解释不清译码器的输出结构。现在归档里这份 SN54LS47 数据手册,是我后来才找到的。按 TI 的 LS47 资料,它的输出低有效、开集电极,本来就是给共阳数码管用的;课件仿真里的 CD4511 驱动的则是共阴数码管。这背后的电流路径,放在了共阳数码管与 BCD 译码里细讲。

Six-Pin Latching Switches六脚自锁按键

With the displays working, the two six-pin latching switches gave me another round of grief. There was no datasheet, and we did not know then that a part number could be looked up on sites such as Semiee or LCSC, so we guessed. Presses that did nothing, readings that jumped about, one press registering twice: we ran into all of them. However many times the code changed, the same hardware question remained. Which of these six pins actually connect, before and after the button is pressed?

显示调通了,两个六脚自锁按键又把我折腾了一阵。老师没给数据手册,我们那时也不知道可以拿型号去半导小芯、立创商城这类网站上查,只能硬猜。按下去没反应、读数乱跳、按一次响应两次,这几种情况都碰上过。代码改了一遍又一遍,绕不开的始终是一个硬件问题:按下前后,这六只脚里到底哪几只是通的。

Nobody knew, so I borrowed a multimeter from the teacher, set it to continuity, measured pin pair after pin pair, and drew out the internal connections before and after pressing. Following that drawing, I wired pause and reset to D2 and D3, and both buttons worked in the end. The display polarity had been stumbled on by poking wires; this time the answer came from measuring. Contacts, pull-ups and debouncing get a closer look in Latching Switches and Counter Control.

大家都不知道,我就找老师借了一个万用表,拨到通断档,一对一对地量,把按下前和按下后的内部连接画了出来。照着这张图,我把暂停和复位接到 D2 和 D3,两个按键最后都能正常用。数码管的接法是瞎插碰出来的,这一回是量出来的。触点、上下拉和消抖这些,在自锁按键与计数控制里有更细的推演。

Switch logic code from the homework report / 作业报告里的开关逻辑代码
Switch logic code from the homework report作业报告里的开关逻辑代码

Demonstration and Assessment演示与验收

Assessment required two versions demonstrated separately: one counting to our group number 17 and going back to 00, the other running to 99 before rolling over to 00. I changed the threshold, flashed each version in turn, and the teacher checked them one by one. By today's standards that code is full of holes, bare-metal polling with blocking delay() calls everywhere, frankly pretty rough. It ran, though, and in class both digits, pause and reset all worked.

考核要分别演示两个版本,一个计到我们的组号 17 回到 00,另一个计到 99 再回到 00。我改阈值,分别烧录,老师一个一个验。那份代码现在看漏洞百出,裸机轮询,阻塞式的 delay() 用得到处都是,写得挺拉的。不过它确实能跑,课堂上两位显示、暂停和复位都工作正常。

We demonstrated to the TA. Because of the display episode, the professor already knew our group, the check went quickly, and we came away with full marks. I am genuinely proud of that one.

验收是给 TA 演示的。因为数码管那件事,老师早就认识我们组了,验得很快,最后拿了满分。拿到这个满分,我是真的挺骄傲的。

Development notes开发笔记

Debugging records and technical notes tied to the decisions and artifacts on this project page.与这个项目页面中的设计决策和工程材料直接关联的调试记录与技术笔记。

2 notes2 篇
  1. 01Latching Switches and Counter Control自锁按键与计数控制Studying latching contacts, input bias, debouncing, state changes, and elapsed-time counting to define predictable pause and reset behaviour.从自锁触点和输入上下拉,研究消抖、状态变化与计数时序,理清暂停和复位怎样按预期响应。
  2. 02Common-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 电流路径、逐段限流和显示控制。

Public Project Files公开项目资料

Uploaded evidence served from the public asset folder. Use the file index to preview documents, source code, media, PDFs, and downloadable artifacts without leaving the page.这里列出已经上传到公开目录的项目证据。可以在左侧索引里选择文件,在右侧直接预览文档、源码、媒体、PDF 和可下载附件。

16 files16 个文件

Related media相关媒体

Board photos, schematic sheets, videos, and test captures that show this project at specific stages.展示这个项目具体阶段的板卡照片、原理图分页、视频和测试截图。

Open in media archive在媒体库中查看