问题描述
嘿,
我对TM1637控制器的4位LED显示屏存在一些问题。  ;
https://www.amazon.de/gp/product/B06X952QXS/
数据表: http://olimex.cl/website_MCI/static/documents/Datasheet_TM1637.pdf
在我的研究过程中,我发现了一些Python和C ++类来控制TM1637,但是我想使用C#,因为它也应该是带有C#的
。
https://raspberrytips.nl/files/tm1637.py
http://www.instructables.com/id/Capacitance-Meter-With-TM1637-Using-Arduino/
tm1637在5V和GND上运行。对于DIO,我使用GPIO 24和CLK GPIO 23.
Hey,
I have some issues with the TM1637 controller for a 4 Digit LED Display.
https://www.amazon.de/gp/product/B06X952QXS/
Datasheet: http://olimex.cl/website_MCI/static/documents/Datasheet_TM1637.pdf
During my research I found some Python and C++ classes to control the TM1637, but I want to use C#, since it should be possible with C# as well.
https://raspberrytips.nl/files/tm1637.py
http://www.instructables.com/id/Capacitance-Meter-With-TM1637-Using-Arduino/
The tm1637 is running on 5V and GND. For DIO I am using GPIO 24 and for CLK GPIO 23.
我正在使用Raspberry Pi 3和Windows IoT Extension for UWP Version 10.0.14393.0。
该类创建时使用:
tm1637 tm = new tm1637(23,24,5);
显示数字:
tm.startDisplay(1000);
但显示器没有任何反应。它不会显示任何内容。我现在已经没有想法如何让这个控制器运行
。另外一双眼睛找到了代码中的错误?
我使用Task.Delay手动降低数据速率,因为TM1637只能处理150kHz。
这是我的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.Devices.Gpio;
namespace display
{
class tm1637
{
int brightnes;
private GpioPin clkPin;
private GpioPin dataPin;
byte[] LEDDIGITS =
{
// 0 1 2 3 4 5 6 7 8 9
0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90
};
private byte[] LEDCHARS =
{
// A b C d E F -
0x8C, 0xBF, 0xC6, 0xA1, 0x86, 0xFF, 0xbf
};
public tm1637(int pinClock, int pinData, int brightnes)
{
this.brightnes = brightnes;
var gpio = GpioController.GetDefault();
clkPin = gpio.OpenPin(pinClock);
clkPin.SetDriveMode(GpioPinDriveMode.Output);
dataPin = gpio.OpenPin(pinData);
dataPin.SetDriveMode(GpioPinDriveMode.Output);
clkPin.Write(GpioPinValue.Low);
dataPin.Write(GpioPinValue.Low);
}
public async void startDisplay(int number)
{
await startDisp();
await writeByte(0x40);
await stopDisp();
await startDisp();
await writeByte(0xc0);
var numStr = number.ToString();
for(int i = 0; i < numStr.Length; i++)
{
var pos = numStr[numStr.Length - i - 1] - '0';
await writeByte(LEDDIGITS[pos]);
}
await stopDisp();
await startDisp();
await writeByte((byte)(0x88 + this.brightnes));
await stopDisp();
}
public async Task startDisp()
{
clkPin.Write(GpioPinValue.High);
dataPin.Write(GpioPinValue.High);
await Task.Delay(5);
clkPin.Write(GpioPinValue.Low);
dataPin.Write(GpioPinValue.Low);
await Task.Delay(5);
}
public async Task stopDisp()
{
clkPin.Write(GpioPinValue.Low);
dataPin.Write(GpioPinValue.Low);
await Task.Delay(5);
clkPin.Write(GpioPinValue.High);
dataPin.Write(GpioPinValue.High);
await Task.Delay(5);
}
public async Task writeByte(byte input)
{
for (int i = 0; i < 8; i++)
{
clkPin.Write(GpioPinValue.Low);
await Task.Delay(5);
if((input & (1 << i)) >> i == 1)
dataPin.Write(GpioPinValue.High);
else
dataPin.Write(GpioPinValue.Low);
await Task.Delay(5);
clkPin.Write(GpioPinValue.High);
await Task.Delay(5);
}
clkPin.Write(GpioPinValue.Low);
dataPin.Write(GpioPinValue.High);
await Task.Delay(5);
clkPin.Write(GpioPinValue.High);
//Ignore ACK
dataPin.SetDriveMode(GpioPinDriveMode.Input);
await Task.Delay(5);
dataPin.SetDriveMode(GpioPinDriveMode.Output);
dataPin.Write(GpioPinValue.Low);
}
}
}
推荐答案
如果您有逻辑分析仪或示波器,那么确保您确实获得预期的速度&波形。
If you have a logic analyzer, or a scope, it's be worth ensuring that you're actually getting the expected speeds & waveforms.
Windows物联网项目经理Tony Goodhew
Tony Goodhew, Program Manager, Windows IoT
这篇关于使用TM1637和C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!