Delphi - 7段显示

Delphi - 7 Segment Display

我正在尝试解决一个问题。我想在 7 段显示器上显示多个 I/O 函数 (write_byte())。我正在使用 PCF8574 iic。我尝试将两个 I/O 函数加在一起,但一次只有一个段变红。我怎样才能做到这一点,多个段同时变红并保持红色一段时间?

这是我的代码

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(F);
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(F);
      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(F);
      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(F);
      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(F);
      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(F);
      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(F);
      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.

提前致谢!

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

有多种方法可以做到这一点。我想我会做这样的事情:


implementation
  const      ALL_OFF   = $ff;
  const      SEGMENT_1 = ;      // ONE bit only set, the bit that needs to
  const      SEGMENT_2 = ;      //     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这些一起得到正确的位组合,然后Xor用$FF关闭对应的位您要显示的细分。