資料介紹
描述
背景
這篇博文旨在作為我深入研究在 Raspberry Pi 上使用 Windows IoT 進行軟件和硬件開發的一系列博文中的第一篇。
介紹
在 Raspberry Pi 上做任何其他事情之前,我決定開始的第一個任務是顯示輸出,這樣我就可以看到我的應用程序完成的任何處理的結果。七段顯示器是顯示基本數字輸出的一種簡單方式,無論是溫度、濕度還是計時器。
七段顯示器可以有一個或多個數字,并帶有共陽極或共陰極電路。共陽極顯示器的每個段都有一個共享輸入,每個段都有自己的輸出,而共陰極顯示器的每個段都有一個單獨的輸入和一個公共輸出。
具有多于一個數字的顯示器,每個數字將有一個陽極或一個陰極,但段輸入/輸出是共享的。由于一次只能顯示一個數字,要顯示多位數字,每個數字及其段必須非常快速地打開和關閉,給人眼的印象是所有需要的數字都在連續顯示。
下面的解決方案是使用 4 位 7 段共陰極顯示器編寫的,但該庫是有意編寫的,以允許它通過 GPIO 輸出用于任意位數的 7 段共陰極顯示器。
先決條件
熔化圖

七段顯示圖
編寫此代碼時使用的顯示器是 5641AS,它有 12 個引腳,從左下角逆時針方向排列。數據表可以在谷歌上找到,但引腳布局如下:
- 乙
- 丁
- 小數點
- C
- G
- 數字 4
- 乙
- 數字 3
- 數字 2
- F
- 一種
- 數字 1
代碼
GitHub [上面的鏈接] 上提供了完整的解決方案,但可以分為 3 個主要部分,初始化、構建輸出和顯示輸出。
初始化
要設置顯示器,我們需要知道哪些輸出引腳將驅動段,哪些將驅動顯示器。雖然段數是固定的(7 或 8,包括小數點),但顯示屏上可用的位數可能會有所不同,具體取決于所使用的顯示屏。在此示例中,我們有 4 位數字,因此我們需要提供 4 個額外的 pin 號碼并對其進行初始化。
這些段是顯式傳遞的,并且任何剩余的引腳都假定為每個顯示器一個,通過 params 參數傳遞。每個顯示鏈接輸出引腳和段輸出都設置為高電平,這意味著沒有電壓差,也沒有電流流過。因此,所有顯示都將關閉。 ?
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);
}
構建輸出
為了為消費者提供一種設置要顯示的值的簡便方法,我們將在庫中完成這項工作。假設我們要顯示 1234 整數,那么我們需要將單個數字拆分為一個由單個數字組成的數組,數組的長度小于或等于我們可以顯示的位數,這取決于我們是否're 顯示前導零。
在下面的代碼中,我們首先運行一些檢查以確保我們有一個有效的數字來顯示,并且有足夠的數字來顯示它。然后我們通過 %10 [模數] 計算將它分解成單獨的數字。
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();
}
顯示輸出
為了以足夠快的速度在輸出顯示器上顯示數字以欺騙眼睛認為所有顯示器同時打開,我們必須創建一個永久循環,其唯一工作是依次打開和關閉每個顯示器。這是通過“開始”方法完成的,該方法只是啟動一個循環,并顯示先前計算的數組中的數字。如果數組更新,顯示會自動更新。
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);
}
設置顯示功能關閉所有顯示[設置為高],然后根據數字將顯示特定數字所需的段設置為高/低,然后將顯示引腳設置為低,允許電流流動個位數。這輪流通過每個數字依次打開和關閉每個數字。這種情況發生的速度比眼睛能察覺的要快,給人的印象是所有數字都同時打開。
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 });
}
包括演示應用程序在內的完整代碼清單可通過頁面頂部的鏈接獲得。
未來發展
目前,輸出僅限于完整的正整數。未來的改進可能包括顯示小數或負數,或一些字母數字字符(例如用于溫度顯示的 C 或 F)。
- 在HLS的七段顯示器上顯示光傳感器的輸出
- Arduino七段計數器
- 七段顯示器開源分享
- Snap Circuits七段顯示器
- 使用ATmega328的七段顯示驅動程序
- 帶LED的七段顯示器
- Arduino七段時鐘開源分享
- 4511 7位七段顯示模塊
- 定制設計的七段顯示器
- 【51單片機】七段數碼管顯示實驗+詳細講解
- 采用74LS192計數芯片實現七段共陰極數碼管顯示的資料說明 92次下載
- 使用51單片機驅動七段LED數碼管的代碼免費下載
- 七段數碼管顯示的C51程序免費下載
- 七段顯示器控制電路四位數_使用譯碼器驅動 148次下載
- 7446/7447中文資料 (七段顯示器譯碼器/驅動器IC)
- 七段LED顯示器的工作原理與驅動方法 1968次閱讀
- 怎么編寫Framebuffer驅動程序 590次閱讀
- Intel Xe驅動代碼嚴重缺乏測試 964次閱讀
- 自動刪除SDK/Vitis下驅動程序的舊版本的Linux腳本 620次閱讀
- bcd七段閃現譯碼器電路原理 1.9w次閱讀
- 七段計數器電路圖 5584次閱讀
- digilent七段顯示器簡介 1861次閱讀
- 七段數碼管驅動方式_七段數碼管怎么接 1.7w次閱讀
- 七段LED數碼管顯示原理 4.1w次閱讀
- 七段數碼管的引腳圖及數碼管的使用條件和注意事項說明 3.7w次閱讀
- 一文了解Raspberry Pi 4各項性能跑分 3w次閱讀
- 淺談電腦驅動程序的工作原理 詳解電腦驅動程序意義 3w次閱讀
- 7段數碼管顯示的VHDL設計(兩款設計方案) 2.1w次閱讀
- Xilinx設備的驅動程序 8200次閱讀
- PCI驅動程序開發實例 6831次閱讀
下載排行
本周
- 1DD3118電路圖紙資料
- 0.08 MB | 1次下載 | 免費
- 2AD庫封裝庫安裝教程
- 0.49 MB | 1次下載 | 免費
- 3PC6206 300mA低功耗低壓差線性穩壓器中文資料
- 1.12 MB | 1次下載 | 免費
- 4網絡安全從業者入門指南
- 2.91 MB | 1次下載 | 免費
- 5DS-CS3A P00-CN-V3
- 618.05 KB | 1次下載 | 免費
- 6海川SM5701規格書
- 1.48 MB | 次下載 | 免費
- 7H20PR5電磁爐IGBT功率管規格書
- 1.68 MB | 次下載 | 1 積分
- 8IP防護等級說明
- 0.08 MB | 次下載 | 免費
本月
- 1貼片三極管上的印字與真實名稱的對照表詳細說明
- 0.50 MB | 103次下載 | 1 積分
- 2涂鴉各WiFi模塊原理圖加PCB封裝
- 11.75 MB | 89次下載 | 1 積分
- 3錦銳科技CA51F2 SDK開發包
- 24.06 MB | 43次下載 | 1 積分
- 4錦銳CA51F005 SDK開發包
- 19.47 MB | 19次下載 | 1 積分
- 5PCB的EMC設計指南
- 2.47 MB | 16次下載 | 1 積分
- 6HC05藍牙原理圖加PCB
- 15.76 MB | 13次下載 | 1 積分
- 7802.11_Wireless_Networks
- 4.17 MB | 12次下載 | 免費
- 8蘋果iphone 11電路原理圖
- 4.98 MB | 6次下載 | 2 積分
總榜
- 1matlab軟件下載入口
- 未知 | 935127次下載 | 10 積分
- 2開源硬件-PMP21529.1-4 開關降壓/升壓雙向直流/直流轉換器 PCB layout 設計
- 1.48MB | 420064次下載 | 10 積分
- 3Altium DXP2002下載入口
- 未知 | 233089次下載 | 10 積分
- 4電路仿真軟件multisim 10.0免費下載
- 340992 | 191390次下載 | 10 積分
- 5十天學會AVR單片機與C語言視頻教程 下載
- 158M | 183342次下載 | 10 積分
- 6labview8.5下載
- 未知 | 81588次下載 | 10 積分
- 7Keil工具MDK-Arm免費下載
- 0.02 MB | 73815次下載 | 10 積分
- 8LabVIEW 8.6下載
- 未知 | 65989次下載 | 10 積分
評論