chinese直男口爆体育生外卖, 99久久er热在这里只有精品99, 又色又爽又黄18禁美女裸身无遮挡, gogogo高清免费观看日本电视,私密按摩师高清版在线,人妻视频毛茸茸,91论坛 兴趣闲谈,欧美 亚洲 精品 8区,国产精品久久久久精品免费

電子發(fā)燒友App

硬聲App

掃碼添加小助手

加入工程師交流群

0
  • 聊天消息
  • 系統(tǒng)消息
  • 評論與回復
登錄后你可以
  • 下載海量資料
  • 學習在線課程
  • 觀看技術(shù)視頻
  • 寫文章/發(fā)帖/加入社區(qū)
會員中心
創(chuàng)作中心

完善資料讓更多小伙伴認識你,還能領(lǐng)取20積分哦,立即完善>

3天內(nèi)不再提示
創(chuàng)作
電子發(fā)燒友網(wǎng)>電子資料下載>電子資料>為Raspberry Pi創(chuàng)建七段顯示驅(qū)動程序

為Raspberry Pi創(chuàng)建七段顯示驅(qū)動程序

2023-07-10 | zip | 0.03 MB | 次下載 | 免費

資料介紹

描述

背景

這篇博文旨在作為我深入研究在 Raspberry Pi 上使用 Windows IoT 進行軟件和硬件開發(fā)的一系列博文中的第一篇。

介紹

在 Raspberry Pi 上做任何其他事情之前,我決定開始的第一個任務(wù)是顯示輸出,這樣我就可以看到我的應(yīng)用程序完成的任何處理的結(jié)果。七段顯示器是顯示基本數(shù)字輸出的一種簡單方式,無論是溫度、濕度還是計時器。

七段顯示器可以有一個或多個數(shù)字,并帶有共陽極或共陰極電路。共陽極顯示器的每個段都有一個共享輸入,每個段都有自己的輸出,而共陰極顯示器的每個段都有一個單獨的輸入和一個公共輸出。

具有多于一個數(shù)字的顯示器,每個數(shù)字將有一個陽極或一個陰極,但段輸入/輸出是共享的。由于一次只能顯示一個數(shù)字,要顯示多位數(shù)字,每個數(shù)字及其段必須非??焖俚卮蜷_和關(guān)閉,給人眼的印象是所有需要的數(shù)字都在連續(xù)顯示。

下面的解決方案是使用 4 位 7 段共陰極顯示器編寫的,但該庫是有意編寫的,以允許它通過 GPIO 輸出用于任意位數(shù)的 7 段共陰極顯示器。

先決條件

  • 運行 Windows IoT 的樹莓派。
  • 8 x 220 歐姆電阻器
  • 7段共陰極顯示。我在這個演示中使用了 5641AS,但任何都可以工作,只需相應(yīng)地更改引腳即可。
  • 面包板。
  • 連接線。

熔化圖

?
poYBAGOjshqAAYnWAADogLMOmpA049.jpg
?

七段顯示圖

編寫此代碼時使用的顯示器是 5641AS,它有 12 個引腳,從左下角逆時針方向排列。數(shù)據(jù)表可以在谷歌上找到,但引腳布局如下:

  • 小數(shù)點
  • C
  • G
  • 數(shù)字 4
  • 數(shù)字 3
  • 數(shù)字 2
  • F
  • 一種
  • 數(shù)字 1

代碼

GitHub [上面的鏈接] 上提供了完整的解決方案,但可以分為 3 個主要部分,初始化、構(gòu)建輸出和顯示輸出。

初始化

要設(shè)置顯示器,我們需要知道哪些輸出引腳將驅(qū)動段,哪些將驅(qū)動顯示器。雖然段數(shù)是固定的(7 或 8,包括小數(shù)點),但顯示屏上可用的位數(shù)可能會有所不同,具體取決于所使用的顯示屏。在此示例中,我們有 4 位數(shù)字,因此我們需要提供 4 個額外的 pin 號碼并對其進行初始化。

這些段是顯式傳遞的,并且任何剩余的引腳都假定為每個顯示器一個,通過 params 參數(shù)傳遞。每個顯示鏈接輸出引腳和段輸出都設(shè)置為高電平,這意味著沒有電壓差,也沒有電流流過。因此,所有顯示都將關(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)建輸出

為了為消費者提供一種設(shè)置要顯示的值的簡便方法,我們將在庫中完成這項工作。假設(shè)我們要顯示 1234 整數(shù),那么我們需要將單個數(shù)字拆分為一個由單個數(shù)字組成的數(shù)組,數(shù)組的長度小于或等于我們可以顯示的位數(shù),這取決于我們是否're 顯示前導零。

在下面的代碼中,我們首先運行一些檢查以確保我們有一個有效的數(shù)字來顯示,并且有足夠的數(shù)字來顯示它。然后我們通過 %10 [模數(shù)] 計算將它分解成單獨的數(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ù)字以欺騙眼睛認為所有顯示器同時打開,我們必須創(chuàng)建一個永久循環(huán),其唯一工作是依次打開和關(guān)閉每個顯示器。這是通過“開始”方法完成的,該方法只是啟動一個循環(huán),并顯示先前計算的數(shù)組中的數(shù)字。如果數(shù)組更新,顯示會自動更新。


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è)置為低,允許電流流動個位數(shù)。這輪流通過每個數(shù)字依次打開和關(guān)閉每個數(shù)字。這種情況發(fā)生的速度比眼睛能察覺的要快,給人的印象是所有數(shù)字都同時打開。

 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)的完整代碼清單可通過頁面頂部的鏈接獲得。

?

未來發(fā)展

目前,輸出僅限于完整的正整數(shù)。未來的改進可能包括顯示小數(shù)或負數(shù),或一些字母數(shù)字字符(例如用于溫度顯示的 C 或 F)。


WINDOWS Raspberry Pi IOT 面包板
加入交流群
微信小助手二維碼

掃碼添加小助手

加入工程師交流群

下載該資料的人也在下載 下載該資料的人還在閱讀
更多 >

評論

查看更多

下載排行

本周

  1. 1矽力杰 Silergy SY7215A 同步升壓調(diào)節(jié)器 規(guī)格書 Datasheet 佰祥電子
  2. 1.12 MB  |  5次下載  |  免費
  3. 2HT81696H 內(nèi)置升壓的30W立體聲D類音頻功放數(shù)據(jù)手冊
  4. 1.21 MB   |  1次下載  |  免費
  5. 3HTA6863 3W超低噪聲超低功耗單聲道D類音頻功率放大器數(shù)據(jù)手冊
  6. 0.87 MB   |  次下載  |  免費
  7. 4南芯 Southchip SC8802C 充電控制器 規(guī)格書 Datasheet 佰祥電子
  8. 88.16 KB  |  次下載  |  免費
  9. 5矽力杰 Silergy SY7065 同步升壓轉(zhuǎn)換器 規(guī)格書 Datasheet 佰祥電子
  10. 910.67 KB  |  次下載  |  免費
  11. 6矽力杰 Silergy SY7066 同步升壓轉(zhuǎn)換器 規(guī)格書 Datasheet 佰祥電子
  12. 989.14 KB  |  次下載  |  免費
  13. 7WD6208A產(chǎn)品規(guī)格書
  14. 631.24 KB  |  次下載  |  免費
  15. 8NB685 26 V,12 A,低靜態(tài)電流,大電流 同步降壓變換器數(shù)據(jù)手冊
  16. 1.64 MB   |  次下載  |  2 積分

本月

  1. 1EMC PCB設(shè)計總結(jié)
  2. 0.33 MB   |  12次下載  |  免費
  3. 2PD取電芯片 ECP5702規(guī)格書
  4. 0.88 MB   |  5次下載  |  免費
  5. 3矽力杰 Silergy SY7215A 同步升壓調(diào)節(jié)器 規(guī)格書 Datasheet 佰祥電子
  6. 1.12 MB  |  5次下載  |  免費
  7. 4氮化鎵GaN FET/GaN HEMT 功率驅(qū)動電路選型表
  8. 0.10 MB   |  3次下載  |  免費
  9. 5PD取電芯片,可取5/9/12/15/20V電壓ECP5702數(shù)據(jù)手冊
  10. 0.88 MB   |  3次下載  |  免費
  11. 6SY50655 用于高輸入電壓應(yīng)用的偽固定頻率SSR反激式穩(wěn)壓器英文資料
  12. 1.01 MB   |  3次下載  |  免費
  13. 7怎么為半導體測試儀選擇精密放大器
  14. 0.65 MB   |  2次下載  |  免費
  15. 8SY52341 次級側(cè)同步整流英文手冊
  16. 0.94 MB   |  2次下載  |  免費

總榜

  1. 1matlab軟件下載入口
  2. 未知  |  935137次下載  |  10 積分
  3. 2開源硬件-PMP21529.1-4 開關(guān)降壓/升壓雙向直流/直流轉(zhuǎn)換器 PCB layout 設(shè)計
  4. 1.48MB  |  420064次下載  |  10 積分
  5. 3Altium DXP2002下載入口
  6. 未知  |  233095次下載  |  10 積分
  7. 4電路仿真軟件multisim 10.0免費下載
  8. 340992  |  191469次下載  |  10 積分
  9. 5十天學會AVR單片機與C語言視頻教程 下載
  10. 158M  |  183360次下載  |  10 積分
  11. 6labview8.5下載
  12. 未知  |  81606次下載  |  10 積分
  13. 7Keil工具MDK-Arm免費下載
  14. 0.02 MB  |  73832次下載  |  10 積分
  15. 8LabVIEW 8.6下載
  16. 未知  |  65991次下載  |  10 積分