首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Delphi -7段显示

Delphi -7段显示
EN

Stack Overflow用户
提问于 2021-04-01 22:17:01
回答 1查看 159关注 0票数 2

我在试着解决一个问题。我想在7段显示器上显示多个I/O函数(write_byte())。我使用的是PCF8574 iic。我尝试将两个I/O函数添加到一起,但一次只有一个段变为红色。我如何才能让多个数据段同时变红并保持一段时间呢?

以下是我的代码

代码语言:javascript
复制
unit check;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, i2cUsb, Vcl.StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);

  private
    { private-declarationen }
  public
    { public-declarationen }
  end;

var
  Form1: TForm1;
  board, slave : Ti2cUsb;
  var1:integer;
  i: integer;

implementation
{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin

board := Ti2cUsb.Create;
slave := Ti2cUsb.Create;
//Comport Number COM4
var1 := board.Init(4);
Sleep(1000);
board.relais_on;
Sleep(1000);
board.relais_off;

end;

procedure TForm1.Button2Click(Sender: TObject);

begin

board.start_iic(False,64,'w');
{
// 7 Segment off:
board.wr_byte_iic($FF);
//all 7 Segments:
board.wr_byte_iic($7F);
board.wr_byte_iic($BF);
board.wr_byte_iic($DF);
board.wr_byte_iic($EF);
board.wr_byte_iic($F7);
board.wr_byte_iic($FB);
board.wr_byte_iic($FD);
board.wr_byte_iic($FE);
}

// Display off
        board.wr_byte_iic($FF);
        sleep(5000);


//number 0:
      board.wr_byte_iic($7F);
      board.wr_byte_iic($BF);
      board.wr_byte_iic($DF);
      board.wr_byte_iic($F7);
      board.wr_byte_iic($FB);
      board.wr_byte_iic($FD);
      sleep(5000);

//number 1:
      board.wr_byte_iic($DF);
      board.wr_byte_iic($F7);
      sleep(5000);


//number 2:
      board.wr_byte_iic($BF);
      board.wr_byte_iic($DF);
      board.wr_byte_iic($FE);
      board.wr_byte_iic($FD);
      board.wr_byte_iic($FB);
      sleep(5000);

//number 3:
      board.wr_byte_iic($BF);
      board.wr_byte_iic($DF);
      board.wr_byte_iic($FE);
      board.wr_byte_iic($F7);
      board.wr_byte_iic($FB);
      sleep(5000);

//number 4:
      board.wr_byte_iic($7F);
      board.wr_byte_iic($FE);
      board.wr_byte_iic($DF);
      board.wr_byte_iic($F7);
      board.wr_byte_iic($EF);
      sleep(5000);

//number 5:
      board.wr_byte_iic($BF);
      board.wr_byte_iic($7F);
      board.wr_byte_iic($FE);
      board.wr_byte_iic($F7);
      board.wr_byte_iic($FB);
      sleep(5000);

//number 6:
      board.wr_byte_iic($EF);
      board.wr_byte_iic($BF);
      board.wr_byte_iic($7F);
      board.wr_byte_iic($FD);
      board.wr_byte_iic($FB);
      board.wr_byte_iic($F7);
      board.wr_byte_iic($FE);
      sleep(5000);

//number 7:
      board.wr_byte_iic($BF);
      board.wr_byte_iic($DF);
      board.wr_byte_iic($F7);
      sleep(5000);

//number 8:
      board.wr_byte_iic($FF);
      board.wr_byte_iic($7F);
      board.wr_byte_iic($BF);
      board.wr_byte_iic($DF);
      board.wr_byte_iic($F7);
      board.wr_byte_iic($FB);
      board.wr_byte_iic($FD);
      board.wr_byte_iic($FE);
      sleep(5000);

//number 9:
      board.wr_byte_iic($EF);
      board.wr_byte_iic($FE);
      board.wr_byte_iic($7F);
      board.wr_byte_iic($BF);
      board.wr_byte_iic($DF);
      board.wr_byte_iic($F7);
      board.wr_byte_iic($FB);
      sleep(5000);

// Display off
      board.wr_byte_iic($FF);



end;

end.

提前感谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-04-01 23:34:32

当您尝试写入多个段时,每次写入都会替换先前写入的内容。你需要计算出与你想要显示的段的组合相对应的数字,然后写一次组合的数字。

有许多方法可以做到这一点。我想我会这样做:

代码语言:javascript
复制
implementation
  const      ALL_OFF   = $ff;
  const      SEGMENT_1 = $20;      // ONE bit only set, the bit that needs to
  const      SEGMENT_2 = $08;      //     turned off for that segment

procedure SetNumberOne();
var
  ByteToWrite: Byte;
begin
  ByteToWrite := ALL_OFF Xor (SEGMENT_1 Or SEGMENT_2);
  board.wr_byte_iic(ByteToWrite);
end;

因此,您可以使用常量标记需要关闭的位,将这些常量Or在一起以获得正确的位组合,然后使用$FF关闭与您要显示的段相对应的位。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66906199

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档