多个LED使用少量GPIO引脚在瑞萨微控制器中控制

huangapple go评论76阅读模式
英文:

Multiple LED control with few GPIO pins in Renesas microcontroller

问题

我需要通过4个GPIO引脚控制12个LED灯。我在网上阅读了一些资料,看到可以使用Charlieplexing方法以较少的GPIO引脚来控制LED灯。但是在这种方法中,是否可能使两个或更多的LED灯同时发光呢?这12个LED灯分为4组(每组3个LED灯),每组一次点亮一个LED灯。

如果有人使用过这种方法或其他方法,请提供一些关于如何实施的指导。我会尝试的。谢谢。

英文:

I need to control 12 leds through 4 GPIO pins. I did some reading online and saw we can use Charlieplexing method to control leds with fewer gpio pins. But is it possible to make two or more leds to glow at the same time in this method. Those 12 leds are grouped into 4 groups(3 leds in a group) and 1 led would be lit in each group at a time.

Anybody used this method or any other method please provide some guidance on how to go about this implementation. I'll try it. Thanks.

答案1

得分: 1

你可以通过使用具有锁存输出的外部移位寄存器(例如MC74HCT595A)和电阻来实现这一点。 GPIO引脚可以提供数据、移位时钟和锁存时钟。 此外,移位寄存器可以级联,以便您可以超过12个LED,如果愿意的话。 请确保所选移位寄存器的逻辑家族与您的MCU的逻辑家族匹配。

英文:

You can accomplish this by using external shift registers with latched outputs (e.g. MC74HCT595A) and resistors. The GPIO pins can provide the data, shift clock, and latch clock. Also, the shift registers can be daisy chained so that you can go beyond 12 LEDs if you wish. Be sure that the logic family of the shift registers chosen matches that of your MCU.

答案2

得分: 1

你可以通过使用4个GPIO来同时点亮多个LED(不考虑电流限制问题 - 硬件问题),但不能以任意组合方式点亮。

但是,如果你成功地每次只点亮一个LED,你可以通过在快速循环中依次点亮多个LED来愚弄用户。在任何给定的时刻,只有一个LED是开启的,但人眼会持续看到它亮约1/20秒。

每毫秒(或类似时间间隔)运行一个中断,使用一个12位掩码指示哪些LED需要点亮。中断处理程序不断“旋转”GPIO以触碰每一行和列的每一种组合,同时在内部寄存器中旋转一个位(1000b,0100b,0010b,0001b,然后重新加载1000)。当内部寄存器与LED掩码的AND结果不为零时,必须保持GPIO配置处于活动状态,否则关闭GPIO。

更新:忘记提到,保持LED开启的时间如此短,将使它们比正常情况下更暗淡。你可以通过允许更多电流(不超过安全限制),和/或选择更亮的LED来部分纠正这一点。

英文:

You can turn on more than one led, using 4 GPIOs (let's alone the current limiting problems - hardware problem), but not in any combination.

BUT: if you manage to turn on any single led at a time, you can fool the user by turning on multiple leds, one after the other, in a quick loop. At any given moment only a LED is on, but the human eye continues to see it lit for about 1/20th of second.

Have a interrupt run every ms (or so), and a mask of 12 bit indicating which leds have to be on. The interrupt handler continuosly "rotates" the GPIOs in order to touch every combination of rows and columns, and in the same time rotates a bit in an internal register (1000b, 0100b, 0010b 0001b, then reload 1000). When the AND of the internal register and the LEDs mask is not zero, the GPIO configuration must be left active, otherwise set the GPIO to off.

Update: forgot to mention, keeping the LEDS on for so short time, will make them less bright than normal. You can partly correct this by allowing more current (up to a safe limit), and/or by choosing brighter LEDs...

huangapple
  • 本文由 发表于 2023年1月6日 14:36:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/75027729.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定