⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lcd99.pas

📁 本文介绍MGLS-l2864液晶显示模块的功能、原理及开发步骤。MGLS-12864液晶显示模块内置有HD61202液晶显示控制驱动器
💻 PAS
📖 第 1 页 / 共 3 页
字号:
unit Lcd99;

{  LCD display component written by Jonathan Hosking, October 2000.

   Get future component updates from the following address
   Website: http://www.the-hoskings.freeserve.co.uk/

   Send any bugs, suggestions, etc to the following Email
   Email: jonathan@the-hoskings.freeserve.co.uk

   Thanks to Jean Pierre for helping with the drawing routines
   Email: jean-pierre.cocatrix@vx.cit.alcatel.fr

   Thanks to Daniel Szasz for implementing support for colon characters
   Email: daniel@mindcti.com

   Thanks to Alan Warriner for implementing double buffering, the
   animation preview feature, and improving the animation delays
   Email: alan.warriner@bigfoot.com

   Thanks to Mike Heydon for implementing the numeric value routines
   and OnChange event.
   Email: mheydon@eoh.co.za  }

interface

uses
  {$IFDEF WIN32} Windows, {$ELSE} WinTypes, WinProcs, {$ENDIF}
  Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Menus;

type
  TLCDScale = 1..100;
  TLCDAnimation = (anNone, anSpiral, anUp, anDown, anLeft, anRight, anRandom);
  TLCDAbout = (abNone,abAbout);
  TLCDChangeProc = procedure(Sender: TObject; OldValue, NewValue: string) of object;
  TLCD99 = class(TCustomControl)
  private
    { Private declarations }
    fAbout: TLCDAbout;
    fAnimation: TLCDAnimation;
    fAnimationDelay: Integer;
    fBufferBM: TBitmap;
    fDigitNum: Integer;
    fDigitSpacing: Integer;
    fDoBuffer:Boolean;
    fDotDisplay: Boolean;
    fDotSpacing: Integer;
    fDoubleBuffer: Boolean;
    fGapX: Integer;
    fGapY: Integer;
    fIsChanging: Boolean;
    fIsPainting: Boolean;
    fOffColor: TColor;
    fOldValue: String;
    fOnChange: TLCDChangeProc;
    fOnColor: TColor;
    fPaintDuration: {$IFDEF WIN32}DWord{$ELSE}Longint{$ENDIF};
    fPreview: Boolean;
    fSegmentSize: Integer;
    fValue: String;
    fWorkCanvas: TCanvas;
    procedure SetAnimation(Val: TLCDAnimation);
    procedure SetAnimationDelay(Val: Integer);
    procedure SetDigitNum(Val: Integer);
    procedure SetDigitSpacing(Val: Integer);
    procedure SetDotDisplay(Val: Boolean);
    procedure SetDotSpacing(Val: Integer);
    procedure SetDoubleBuffer(Val: Boolean);
    procedure SetGapX(Val: Integer);
    procedure SetGapY(Val: Integer);
    procedure SetOffColor(Val: TColor);
    procedure SetOnColor(Val: TColor);
    procedure SetSegmentSize(Val: Integer);
    procedure SetPreview(Val: Boolean);
    procedure SetValue(Val: String);
    procedure ShowAbout(Val: TLCDAbout);
    procedure WMEraseBkgnd(var Message: TWMEraseBkgnd); message wm_EraseBkgnd;
  protected
    { Protected declarations }
    procedure Paint; override;
  public
    { Public declarations }
    constructor Create(AOwner: TComponent); override;
    procedure SetNumericValue(NewValue: Integer);
    function GetNumericValue: Integer;
  published
    { Published declarations }
    property About: TLCDAbout read fAbout write ShowAbout default abNone;
    property Align;
    property Animation: TLCDAnimation read fAnimation write SetAnimation default anNone;
    property AnimationDelay: Integer read fAnimationDelay write SetAnimationDelay default 0;
    property Color;
    property DigitNum: Integer read fDigitNum write SetDigitNum default 1;
    property DigitSpacing: Integer read fDigitSpacing write SetDigitSpacing default 5;
    property DotDisplay: Boolean read fDotDisplay write SetDotDisplay default False;
    property DotSpacing: Integer read fDotSpacing write SetDotSpacing default 2;
    property DoubleBuffer: Boolean read fDoubleBuffer write SetDoubleBuffer default True;
    property DragCursor;
    property DragMode;
    property Enabled;
    property GapX: Integer read fGapX write SetGapX default 2;
    property GapY: Integer read fGapY write SetGapY default 2;
    property IsPainting: Boolean read fIsPainting;
    property OffColor: TColor read fOffColor write SetOffColor default clBlack;
    property OnColor: TColor read fOnColor write SetOnColor default clLime;
    property PaintDuration: {$IFDEF WIN32}DWord{$ELSE}Longint{$ENDIF} read fPaintDuration;
    property ParentShowHint;
    property PopupMenu;
    property Preview: Boolean read fPreview write SetPreview default False;
    property SegmentSize: Integer read fSegmentSize write SetSegmentSize default 2;
    property ShowHint;
    property Value: String read fValue write SetValue;
    property Visible;
    property OnChange: TLCDChangeProc read fOnChange write fOnChange;
    property OnClick;
    property OnDblClick;
    property OnDragDrop;
    property OnDragOver;
    property OnEndDrag;
    property OnMouseDown;
    property OnMouseMove;
    property OnMouseUp;
  end;

procedure Register;

implementation

{ TLCD99 }

const
  CopyRightStr: PChar = 'TLCD Component v1.8 (15/10/2000)'+#13+#13+
    'By Jonathan Hosking'+#13+#13+
    'Compiled in '+
    {$IFDEF VER80}  'Delphi 1.0' {$ENDIF}
    {$IFDEF VER90}  'Delphi 2.0' {$ENDIF}
    {$IFDEF VER100} 'Delphi 3.0' {$ENDIF}
    {$IFDEF VER120} 'Delphi 4.0' {$ENDIF}
    {$IFDEF VER130} 'Delphi 5.0' {$ENDIF}
    {$IFDEF VER93}  'C++Builder 1.0' {$ENDIF}
    {$IFDEF VER110} 'C++Builder 3.0' {$ENDIF}
    {$IFDEF VER125} 'C++Builder 4.0' {$ENDIF};

  { ---1---    This next array stores the digits (0 - 36)
    |     |    and the segments (1 - 7).  The diagram on
    2  8  3    the left shows the layout of the segments.
    |     |    A 1 enables the segment, while a 0 will
    ---4---    turn the segment off.  An 8 will display
    |     |    a colon.
    5  8  6
    |     |
    ---7--- }

  LCDDisplayData: Array[0..37,1..8] of integer =
                    { Numbers, minus sign and colon }
                    ((1,1,1,0,1,1,1,0),(0,0,1,0,0,1,0,0),(1,0,1,1,1,0,1,0),
                    (1,0,1,1,0,1,1,0),(0,1,1,1,0,1,0,0),(1,1,0,1,0,1,1,0),
                    (1,1,0,1,1,1,1,0),(1,0,1,0,0,1,0,0),(1,1,1,1,1,1,1,0),
                    (1,1,1,1,0,1,1,0),(0,0,0,1,0,0,0,0),(0,0,0,0,0,0,0,1),
                    { Letters of the alphabet }
                    (1,1,1,1,1,1,0,0),(0,1,0,1,1,1,1,0),(1,1,0,0,1,0,1,0),
                    (0,0,1,1,1,1,1,0),(1,1,0,1,1,0,1,0),(1,1,0,1,1,0,0,0),
                    (1,1,0,1,1,1,1,0),(0,1,0,1,1,1,0,0),(0,0,1,0,0,1,0,0),
                    (0,0,1,0,0,1,1,0),(0,1,1,1,1,1,0,0),(0,1,0,0,1,0,1,0),
                    (0,0,0,1,1,1,0,0),(0,0,0,1,1,1,0,0),(0,0,0,1,1,1,1,0),
                    (1,1,1,1,1,0,0,0),(1,1,1,1,0,1,0,0),(0,0,0,1,1,0,0,0),
                    (1,1,0,1,0,1,1,0),(0,1,0,1,1,0,0,0),(0,1,1,0,1,1,1,0),
                    (0,1,1,0,1,1,1,0),(0,1,1,0,1,1,1,0),(0,1,1,1,1,1,0,0),
                    (0,1,1,1,0,1,0,0),(1,0,1,1,1,0,1,0));

  { This array stores the animation details, starting at anSpiral }
  LCDAnimationData: Array[1..5,1..8] of integer =
                      ((8,4,2,1,3,6,7,5),(7,6,5,8,4,3,2,1),
                      (1,2,3,8,4,5,6,7),(6,3,7,8,4,1,5,2),
                      (2,5,1,8,4,7,3,6));

var
  CopyRightPtr: Pointer;

{ Thanks to Mike Heydon for this routine }
procedure TLCD99.SetNumericValue(NewValue: Integer);
begin
  Value := IntToStr(NewValue);
  Invalidate;
end;

{ Thanks to Mike Heydon for this routine }
function TLCD99.GetNumericValue: Integer;
begin
  Result := StrToIntDef(Value, 0);
end;

constructor TLCD99.Create(AOwner: TComponent);
begin
  { Setup the control }
  Inherited Create(AOwner);
  ControlStyle:=ControlStyle+[csOpaque];
  CopyRightPtr := @CopyRightStr;
  Color := clBlack;
  fAbout := abNone;
  fAnimation := anNone;
  fAnimationDelay := 0;
  fBufferBM := nil;
  fDigitNum := 4;
  fDigitSpacing := 5;
  fDotDisplay := False;
  fDotSpacing := 2;
  fDoubleBuffer := True;
  fGapX := 2;
  fGapY := 2;
  fIsChanging := False;
  fIsPainting := False;
  fOffColor := clBlack;
  fOnColor := clLime;
  fPaintDuration := 0;
  fPreview := False;
  fSegmentSize := 2;
  fOldValue := '';
  fValue := '';
  Width := 92;
  Height := 34;
end;

procedure TLCD99.SetAnimation(Val: TLCDAnimation);
begin
  { The control doesn't need updating here }
  if fAnimation <> Val then
    fAnimation := Val;
end;

procedure TLCD99.SetAnimationDelay(Val: Integer);
begin
  { The control doesn't need updating here }
  if fAnimationDelay <> Val then
    fAnimationDelay := Val;
end;

procedure TLCD99.SetDigitNum(Val: Integer);
begin
  if fDigitNum <> Val then
  begin
    fDigitNum := Val;
    Invalidate;
  end;
end;

procedure TLCD99.SetDigitSpacing(Val: Integer);
begin
  if fDigitSpacing <> Val then
  begin
    fDigitSpacing := Val;
    Invalidate;
  end;
end;

procedure TLCD99.SetDotDisplay(Val: Boolean);
begin
  if fDotDisplay <> Val then
  begin
    fDotDisplay := Val;
    Invalidate;
  end;
end;

procedure TLCD99.SetDotSpacing(Val: Integer);
begin
  if fDotSpacing <> Val then
  begin
    fDotSpacing := Val;
    Invalidate;
  end;
end;

procedure TLCD99.SetDoubleBuffer(Val: Boolean);
begin
  if fDoubleBuffer <> Val then
  begin
    fDoubleBuffer := Val;
    Invalidate;
  end;
end;

procedure TLCD99.SetGapX(Val: Integer);
begin
  if fGapX <> Val then
  begin
    fGapX := Val;
    Invalidate;
  end;
end;

procedure TLCD99.SetGapY(Val: Integer);
begin
  if fGapY <> Val then
  begin
    fGapY := Val;
    Invalidate;
  end;
end;

procedure TLCD99.SetOffColor(Val: TColor);
begin
  if fOffColor <> Val then
  begin
    fOffColor := Val;
    Invalidate;
  end;
end;

procedure TLCD99.SetOnColor(Val: TColor);
begin
  if fOnColor <> Val then

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -