資料介紹
描述
背景
這篇博文旨在作為我深入研究在 Raspberry Pi 上使用 Windows IoT 進(jìn)行軟件和硬件開(kāi)發(fā)的一系列博文中的第一篇。
介紹
在 Raspberry Pi 上做任何其他事情之前,我決定開(kāi)始的第一個(gè)任務(wù)是顯示輸出,這樣我就可以看到我的應(yīng)用程序完成的任何處理的結(jié)果。七段顯示器是顯示基本數(shù)字輸出的一種簡(jiǎn)單方式,無(wú)論是溫度、濕度還是計(jì)時(shí)器。
七段顯示器可以有一個(gè)或多個(gè)數(shù)字,并帶有共陽(yáng)極或共陰極電路。共陽(yáng)極顯示器的每個(gè)段都有一個(gè)共享輸入,每個(gè)段都有自己的輸出,而共陰極顯示器的每個(gè)段都有一個(gè)單獨(dú)的輸入和一個(gè)公共輸出。
具有多于一個(gè)數(shù)字的顯示器,每個(gè)數(shù)字將有一個(gè)陽(yáng)極或一個(gè)陰極,但段輸入/輸出是共享的。由于一次只能顯示一個(gè)數(shù)字,要顯示多位數(shù)字,每個(gè)數(shù)字及其段必須非常快速地打開(kāi)和關(guān)閉,給人眼的印象是所有需要的數(shù)字都在連續(xù)顯示。
下面的解決方案是使用 4 位 7 段共陰極顯示器編寫(xiě)的,但該庫(kù)是有意編寫(xiě)的,以允許它通過(guò) GPIO 輸出用于任意位數(shù)的 7 段共陰極顯示器。
先決條件
- 運(yùn)行 Windows IoT 的樹(shù)莓派。
- 8 x 220 歐姆電阻器。
- 7段共陰極顯示。我在這個(gè)演示中使用了 5641AS,但任何都可以工作,只需相應(yīng)地更改引腳即可。
- 面包板。
- 連接線。
熔化圖
七段顯示圖
編寫(xiě)此代碼時(shí)使用的顯示器是 5641AS,它有 12 個(gè)引腳,從左下角逆時(shí)針?lè)较蚺帕小?/font>數(shù)據(jù)表可以在谷歌上找到,但引腳布局如下:
- 乙
- 丁
- 小數(shù)點(diǎn)
- C
- G
- 數(shù)字 4
- 乙
- 數(shù)字 3
- 數(shù)字 2
- F
- 一種
- 數(shù)字 1
代碼
GitHub [上面的鏈接] 上提供了完整的解決方案,但可以分為 3 個(gè)主要部分,初始化、構(gòu)建輸出和顯示輸出。
初始化
要設(shè)置顯示器,我們需要知道哪些輸出引腳將驅(qū)動(dòng)段,哪些將驅(qū)動(dòng)顯示器。雖然段數(shù)是固定的(7 或 8,包括小數(shù)點(diǎn)),但顯示屏上可用的位數(shù)可能會(huì)有所不同,具體取決于所使用的顯示屏。在此示例中,我們有 4 位數(shù)字,因此我們需要提供 4 個(gè)額外的 pin 號(hào)碼并對(duì)其進(jìn)行初始化。
這些段是顯式傳遞的,并且任何剩余的引腳都假定為每個(gè)顯示器一個(gè),通過(guò) params 參數(shù)傳遞。每個(gè)顯示鏈接輸出引腳和段輸出都設(shè)置為高電平,這意味著沒(méi)有電壓差,也沒(méi)有電流流過(guò)。因此,所有顯示都將關(guān)閉。 ?
public Display(int segA, int segB, int segC, int segD, int segE, int segF, int segG, params int[] displayPins)
{
this.Displays = new GpioPin[displayPins.Length];
for (int i = 0; i < displayPins.Length; i++)
{
GpioPin pin = GpioController.GetDefault().OpenPin(displayPins[i]);
pin.Write(GpioPinValue.High);
pin.SetDriveMode(GpioPinDriveMode.Output);
this.Displays[i] = pin;
}
this.SetupOutputPin(ref this.PinSegA, segA);
this.SetupOutputPin(ref this.PinSegB, segB);
this.SetupOutputPin(ref this.PinSegC, segC);
this.SetupOutputPin(ref this.PinSegD, segD);
this.SetupOutputPin(ref this.PinSegE, segE);
this.SetupOutputPin(ref this.PinSegF, segF);
this.SetupOutputPin(ref this.PinSegG, segG);
this.cts = new CancellationTokenSource();
this.token = new CancellationToken();
}
private void SetupOutputPin(ref GpioPin pin, int pinNo)
{
pin = GpioController.GetDefault().OpenPin(pinNo);
pin.Write(GpioPinValue.High);
pin.SetDriveMode(GpioPinDriveMode.Output);
}
構(gòu)建輸出
為了為消費(fèi)者提供一種設(shè)置要顯示的值的簡(jiǎn)便方法,我們將在庫(kù)中完成這項(xiàng)工作。假設(shè)我們要顯示 1234 整數(shù),那么我們需要將單個(gè)數(shù)字拆分為一個(gè)由單個(gè)數(shù)字組成的數(shù)組,數(shù)組的長(zhǎng)度小于或等于我們可以顯示的位數(shù),這取決于我們是否're 顯示前導(dǎo)零。
在下面的代碼中,我們首先運(yùn)行一些檢查以確保我們有一個(gè)有效的數(shù)字來(lái)顯示,并且有足夠的數(shù)字來(lái)顯示它。然后我們通過(guò) %10 [模數(shù)] 計(jì)算將它分解成單獨(dú)的數(shù)字。
public void DisplayNumber(int number, bool displayLeadingZero = true)
{
this.displayNo = number;
this.displayLeadingZero = displayLeadingZero;
if (this.displayNo < 0)
{
throw new ArgumentOutOfRangeException("Number cannot be negative");
}
int checkMax = 1;
for(int i = 0; i < this.DisplayDigits.Length; i++)
{
checkMax = checkMax * 10;
}
if(number >= checkMax)
{
throw new ArgumentException("Cannot display numbers greater than " + (checkMax - 1).ToString());
}
if (this.displayNo == 0)
{
this.Blank();
if(this.DisplayDigits.Length > 0)
{
this.DisplayDigits[0] = 0;
}
}
else
{
List<int> listOfInts = new List<int>();
while (this.displayNo > 0)
{
listOfInts.Add(this.displayNo % 10);
this.displayNo = this.displayNo / 10;
}
if (displayLeadingZero)
{
while (listOfInts.Count < this.Displays.Length)
{
listOfInts.Add(0);
}
}
else
{
while (listOfInts.Count < this.Displays.Length)
{
listOfInts.Add(10);
}
}
this.DisplayDigits = listOfInts.ToArray();
}
顯示輸出
為了以足夠快的速度在輸出顯示器上顯示數(shù)字以欺騙眼睛認(rèn)為所有顯示器同時(shí)打開(kāi),我們必須創(chuàng)建一個(gè)永久循環(huán),其唯一工作是依次打開(kāi)和關(guān)閉每個(gè)顯示器。這是通過(guò)“開(kāi)始”方法完成的,該方法只是啟動(dòng)一個(gè)循環(huán),并顯示先前計(jì)算的數(shù)組中的數(shù)字。如果數(shù)組更新,顯示會(huì)自動(dòng)更新。
private void Start()
{
if (running)
{
return;
}
running = true;
Task.Factory.StartNew(() =>
{
while (!this.cts.IsCancellationRequested)
{
if (this.DisplayDigits == null)
{
this.Blank();
}
int[] arrDigs = this.DisplayDigits;
for (int i = 0; i < arrDigs.Length; i++)
{
this.SetDisplay(this.Displays[i], arrDigs[i]);
}
}
}, token);
}
設(shè)置顯示功能關(guān)閉所有顯示[設(shè)置為高],然后根據(jù)數(shù)字將顯示特定數(shù)字所需的段設(shè)置為高/低,然后將顯示引腳設(shè)置為低,允許電流流動(dòng)個(gè)位數(shù)。這輪流通過(guò)每個(gè)數(shù)字依次打開(kāi)和關(guān)閉每個(gè)數(shù)字。這種情況發(fā)生的速度比眼睛能察覺(jué)的要快,給人的印象是所有數(shù)字都同時(shí)打開(kāi)。
private void SetDisplay(GpioPin displayPin, int value)
{
this.ClearDisplay();
switch (value)
{
case 0:
this.SetHigh(new GpioPin[] { this.PinSegA, this.PinSegB, this.PinSegC, this.PinSegD, this.PinSegE, this.PinSegF });
this.SetLow(new GpioPin[] { this.PinSegG });
break;
case 1:
this.SetHigh(new GpioPin[] { this.PinSegB, this.PinSegC });
this.SetLow(new GpioPin[] { this.PinSegA, this.PinSegD, this.PinSegE, this.PinSegF, this.PinSegG });
break;
case 2:
this.SetHigh(new GpioPin[] { this.PinSegA, this.PinSegB, this.PinSegD, this.PinSegE, this.PinSegG });
this.SetLow(new GpioPin[] { this.PinSegC, this.PinSegF });
break;
case 3:
this.SetHigh(new GpioPin[] { this.PinSegA, this.PinSegB, this.PinSegC, this.PinSegD, this.PinSegG });
this.SetLow(new GpioPin[] { this.PinSegE, this.PinSegF });
break;
case 4:
this.SetHigh(new GpioPin[] { this.PinSegB, this.PinSegC, this.PinSegF, this.PinSegG });
this.SetLow(new GpioPin[] { this.PinSegA, this.PinSegD, this.PinSegE });
break;
case 5:
this.SetHigh(new GpioPin[] { this.PinSegA, this.PinSegC, this.PinSegD, this.PinSegF, this.PinSegG });
this.SetLow(new GpioPin[] { this.PinSegB, this.PinSegE });
break;
case 6:
this.SetHigh(new GpioPin[] { this.PinSegA, this.PinSegC, this.PinSegD, this.PinSegE, this.PinSegF, this.PinSegG });
this.SetLow(new GpioPin[] { this.PinSegB });
break;
case 7:
this.SetHigh(new GpioPin[] { this.PinSegA, this.PinSegB, this.PinSegC });
this.SetLow(new GpioPin[] { this.PinSegD, this.PinSegE, this.PinSegF, this.PinSegG });
break;
case 8:
this.SetHigh(new GpioPin[] { this.PinSegA, this.PinSegB, this.PinSegC, this.PinSegD, this.PinSegE, this.PinSegF, this.PinSegG });
break;
case 9:
this.SetHigh(new GpioPin[] { this.PinSegA, this.PinSegB, this.PinSegC, this.PinSegD, this.PinSegF, this.PinSegG });
this.SetLow(new GpioPin[] { this.PinSegE });
break;
case 10: // Clear Display
this.SetLow(new GpioPin[] { this.PinSegA, this.PinSegB, this.PinSegC, this.PinSegD, this.PinSegE, this.PinSegF, this.PinSegG });
break;
default:
this.SetLow(new GpioPin[] { this.PinSegA, this.PinSegB, this.PinSegC, this.PinSegD, this.PinSegE, this.PinSegF, this.PinSegG });
break;
}
this.SetLow(new GpioPin[] { displayPin });
}
包括演示應(yīng)用程序在內(nèi)的完整代碼清單可通過(guò)頁(yè)面頂部的鏈接獲得。
未來(lái)發(fā)展
目前,輸出僅限于完整的正整數(shù)。未來(lái)的改進(jìn)可能包括顯示小數(shù)或負(fù)數(shù),或一些字母數(shù)字字符(例如用于溫度顯示的 C 或 F)。
- 在HLS的七段顯示器上顯示光傳感器的輸出
- Arduino七段計(jì)數(shù)器
- 七段顯示器開(kāi)源分享
- Snap Circuits七段顯示器
- 使用ATmega328的七段顯示驅(qū)動(dòng)程序
- 帶LED的七段顯示器
- Arduino七段時(shí)鐘開(kāi)源分享
- 4511 7位七段顯示模塊
- 定制設(shè)計(jì)的七段顯示器
- 【51單片機(jī)】七段數(shù)碼管顯示實(shí)驗(yàn)+詳細(xì)講解
- 采用74LS192計(jì)數(shù)芯片實(shí)現(xiàn)七段共陰極數(shù)碼管顯示的資料說(shuō)明 92次下載
- 使用51單片機(jī)驅(qū)動(dòng)七段LED數(shù)碼管的代碼免費(fèi)下載
- 七段數(shù)碼管顯示的C51程序免費(fèi)下載
- 七段顯示器控制電路四位數(shù)_使用譯碼器驅(qū)動(dòng) 148次下載
- 7446/7447中文資料 (七段顯示器譯碼器/驅(qū)動(dòng)器IC)
- 七段LED顯示器的工作原理與驅(qū)動(dòng)方法 1968次閱讀
- 怎么編寫(xiě)Framebuffer驅(qū)動(dòng)程序 590次閱讀
- Intel Xe驅(qū)動(dòng)代碼嚴(yán)重缺乏測(cè)試 964次閱讀
- 自動(dòng)刪除SDK/Vitis下驅(qū)動(dòng)程序的舊版本的Linux腳本 620次閱讀
- bcd七段閃現(xiàn)譯碼器電路原理 1.9w次閱讀
- 七段計(jì)數(shù)器電路圖 5584次閱讀
- digilent七段顯示器簡(jiǎn)介 1861次閱讀
- 七段數(shù)碼管驅(qū)動(dòng)方式_七段數(shù)碼管怎么接 1.7w次閱讀
- 七段LED數(shù)碼管顯示原理 4.1w次閱讀
- 七段數(shù)碼管的引腳圖及數(shù)碼管的使用條件和注意事項(xiàng)說(shuō)明 3.7w次閱讀
- 一文了解Raspberry Pi 4各項(xiàng)性能跑分 3w次閱讀
- 淺談電腦驅(qū)動(dòng)程序的工作原理 詳解電腦驅(qū)動(dòng)程序意義 3w次閱讀
- 7段數(shù)碼管顯示的VHDL設(shè)計(jì)(兩款設(shè)計(jì)方案) 2.1w次閱讀
- Xilinx設(shè)備的驅(qū)動(dòng)程序 8200次閱讀
- PCI驅(qū)動(dòng)程序開(kāi)發(fā)實(shí)例 6831次閱讀
下載排行
本周
- 1山景DSP芯片AP8248A2數(shù)據(jù)手冊(cè)
- 1.06 MB | 532次下載 | 免費(fèi)
- 2RK3399完整板原理圖(支持平板,盒子VR)
- 3.28 MB | 339次下載 | 免費(fèi)
- 3TC358743XBG評(píng)估板參考手冊(cè)
- 1.36 MB | 330次下載 | 免費(fèi)
- 4DFM軟件使用教程
- 0.84 MB | 295次下載 | 免費(fèi)
- 5元宇宙深度解析—未來(lái)的未來(lái)-風(fēng)口還是泡沫
- 6.40 MB | 227次下載 | 免費(fèi)
- 6迪文DGUS開(kāi)發(fā)指南
- 31.67 MB | 194次下載 | 免費(fèi)
- 7元宇宙底層硬件系列報(bào)告
- 13.42 MB | 182次下載 | 免費(fèi)
- 8FP5207XR-G1中文應(yīng)用手冊(cè)
- 1.09 MB | 178次下載 | 免費(fèi)
本月
- 1OrCAD10.5下載OrCAD10.5中文版軟件
- 0.00 MB | 234315次下載 | 免費(fèi)
- 2555集成電路應(yīng)用800例(新編版)
- 0.00 MB | 33566次下載 | 免費(fèi)
- 3接口電路圖大全
- 未知 | 30323次下載 | 免費(fèi)
- 4開(kāi)關(guān)電源設(shè)計(jì)實(shí)例指南
- 未知 | 21549次下載 | 免費(fèi)
- 5電氣工程師手冊(cè)免費(fèi)下載(新編第二版pdf電子書(shū))
- 0.00 MB | 15349次下載 | 免費(fèi)
- 6數(shù)字電路基礎(chǔ)pdf(下載)
- 未知 | 13750次下載 | 免費(fèi)
- 7電子制作實(shí)例集錦 下載
- 未知 | 8113次下載 | 免費(fèi)
- 8《LED驅(qū)動(dòng)電路設(shè)計(jì)》 溫德?tīng)栔?/a>
- 0.00 MB | 6656次下載 | 免費(fèi)
總榜
- 1matlab軟件下載入口
- 未知 | 935054次下載 | 免費(fèi)
- 2protel99se軟件下載(可英文版轉(zhuǎn)中文版)
- 78.1 MB | 537798次下載 | 免費(fèi)
- 3MATLAB 7.1 下載 (含軟件介紹)
- 未知 | 420027次下載 | 免費(fèi)
- 4OrCAD10.5下載OrCAD10.5中文版軟件
- 0.00 MB | 234315次下載 | 免費(fèi)
- 5Altium DXP2002下載入口
- 未知 | 233046次下載 | 免費(fèi)
- 6電路仿真軟件multisim 10.0免費(fèi)下載
- 340992 | 191187次下載 | 免費(fèi)
- 7十天學(xué)會(huì)AVR單片機(jī)與C語(yǔ)言視頻教程 下載
- 158M | 183279次下載 | 免費(fèi)
- 8proe5.0野火版下載(中文版免費(fèi)下載)
- 未知 | 138040次下載 | 免費(fèi)
評(píng)論
查看更多