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

📄 lcd99.pas

📁 本文介绍MGLS-l2864液晶显示模块的功能、原理及开发步骤。MGLS-12864液晶显示模块内置有HD61202液晶显示控制驱动器
💻 PAS
📖 第 1 页 / 共 3 页
字号:
    else
    begin
      { Normal segments do use gaps }
      HG := fGapY;
      VG := fGapX;
    end;
    VH := fSegmentSize;
    HW := fSegmentSize;
    VW := SegmentSpaceX - (2 * VG);
    HH := (SegmentSpaceY div 2) - (2 * HG);
    { Draw the decimal points }
    for DigitNumber := 1 to fDigitNum do
      if (tmp3[DigitNumber] <> tmp4[DigitNumber]) or (not SkipSome) then
      begin
        if tmp3[DigitNumber] = '.' then
        begin
          Brush.Color := fOnColor;
          Pen.Color := fOnColor;
        end
        else
        begin
          Brush.Color := fOffColor;
          Pen.Color := fOffColor;
        end;
        { Make sure the decimal point size matches the segment size }
        if fSegmentSize > (Spacing - 2) then Temp := Spacing - 2
          else Temp := fSegmentSize;
        DrawX := (((DigitNumber - 1) * (SegmentSpaceX + Spacing)) + Spacing)
          - ((Spacing + Temp) div 2);
        if fDotDisplay then
          Ellipse(DrawX,SegmentSpaceY - Temp,DrawX + Temp,SegmentSpaceY)
        else
          Rectangle(DrawX,SegmentSpaceY - Temp,DrawX + Temp,SegmentSpaceY);
      end;
    { Here we see how much delay time is left }
    Speed := (Speed - Integer(GetTickCount - FirstTickCount)) div 7;
    if Speed < 0 then Speed := 0;
    DelayCorrection := 0;
    repeat
      { Now we start the delay count.  The reason for this is that some
        of the delay time can be spent updating the actual segments, so
        a delay of 1000 MUST last 1 second.  The delay is equally divided
        by 8, as there are 8 segments to update }
      FirstSegmentTickCount := GetTickCount;
      { Continue the animation }
      Inc(AnimationCount);
      if Animation <> 0 then
        SegmentNo := LCDAnimationData[Animation,AnimationCount]
      else
        SegmentNo := LCDAnimationData[3,AnimationCount];
      for DigitNumber := 1 to fDigitNum do
        if (tmp[DigitNumber] <> tmp2[DigitNumber]) or (not SkipSome) then
        begin
          { Reset the digit index }
          AValue := 8;
          { Get the current digit details }
          if tmp[DigitNumber] = ' ' then
          begin
            AValue := 8;
            DigitOn := False;
          end
          else
          begin
            { Convert the letters, numbers and minus sign
              to the correct digit index }
            case tmp[DigitNumber] of
              '-': AValue := 10;
              ':': AValue := 11;
              '0'..'9': AValue := StrToInt(tmp[DigitNumber]);
              'A'..'Z': AValue := Ord(tmp[DigitNumber]) - 53;
            end;
            DigitOn := true;
          end;
          { Set the color }
          if (DigitOn) and (LCDDisplayData[AValue,SegmentNo] = 1) then
            SColor := fOnColor
          else
            SColor := fOffColor;
          { Now we set the positions and draw the segment }
          DrawX := Spacing + ((DigitNumber - 1) * (SegmentSpaceX + Spacing));
          case SegmentNo of
            1,7: begin
                   { Top and bottom segments }
                   Inc(DrawX,VG);
                   if SegmentNo = 1 then
                   begin
                     DrawY := 0;
                     DrawVerticalSegment(DrawX,DrawY,VW,VH,SColor);
                   end
                   else
                   begin
                     DrawY := SegmentSpaceY;
                     DrawVerticalSegment(DrawX,DrawY,VW,-(VH),SColor);
                   end;
                 end;
            4: begin
                 { Centre segment }
                 Inc(DrawX,VG);
                 DrawY := (SegmentSpaceY div 2) - (VH div 2);
                 DrawCenterSegment(DrawX,DrawY,VW,VH,SColor);
               end;
            2,5: begin
                   { Left segments }
                   if SegmentNo = 2 then DrawY := HG else
                   begin
                     if fDotDisplay then
                       DrawY := (SegmentSpaceY div 2) - (VH div 2)
                     else
                       DrawY := (SegmentSpaceY div 2) + HG;
                   end;
                   DrawHorizontalSegment(DrawX,DrawY,HW,HH,SColor);
                 end;
            3,6: begin
                   { Right segments }
                   Inc(DrawX,SegmentSpaceX);
                   if SegmentNo = 3 then DrawY := HG else
                   begin
                     if fDotDisplay then
                       DrawY := (SegmentSpaceY div 2) - (VH div 2)
                     else
                       DrawY := (SegmentSpaceY div 2) + HG;
                   end;
                   DrawHorizontalSegment(DrawX,DrawY,-(HW),HH,SColor);
                 end;
            8: begin
                 { Colon }
                 Inc(DrawX,(SegmentSpaceX - (VW div 3)) div 2);
                 DrawColon(DrawX,(SegmentSpaceY div 2)-((HH div 3) * 2),
                             DrawX,(SegmentSpaceY div 2)+(HH div 3),
                             (VW div 3),(HH div 3),SColor);
               end;
          end;
        end;
      { Now we wait for the rest of the delay to complete if there is
        an animation }
      if (Animation <> 0) and (Speed>0) then
        begin
         { Draw what we've achieved so far if double buffering }
         if fDoBuffer then
           Canvas.CopyRect(ClientRect,fWorkCanvas,ClientRect);
         { Delay & process messages up until last segment }
         if AnimationCount < 8 then
         begin
           SegmentDelay:= Speed - DelayCorrection;
           repeat
             { Process messages if not in design mode }
             if not (csDesigning in ComponentState) then
               Application.ProcessMessages;
             DelayTicks := GetTickCount - FirstSegmentTickCount;
           until DelayTicks >= SegmentDelay;
           { Trim back delay speed to compensate for over long delays }
           DelayCorrection := DelayTicks-SegmentDelay;
           if DelayCorrection > Speed then
              DelayCorrection := Speed;
          end;
        end
    until AnimationCount = 8;
  end;
end;

procedure SplitValue(AValue: String; var Value, Dots: String);
var
  Count: Integer;
  Dot: Boolean;
begin
  Count := 1;
  Value := '';
  Dots := '';
  Dot := False;
  while Count <= length(AValue) do
  begin
    if AValue[Count] <> '.' then
    begin
      if not Dot then
        Dots := Dots + ' '
      else
        Dot := False;
      Value := Value + AValue[Count];
    end
    else
    begin
      Dots := Dots + '.';
      if Dot then
        Value := Value + ' '
      else
        Dot := True;
    end;
    Inc(Count);
  end;
end;

begin
  { Exit if the control is already painting }
  if fIsPainting then Exit;
  { Set the painting flag }
  fIsPainting := True;
  FirstTickCount := GetTickCount;
  PaintStart := GetTickCount;
  { Set working canvas to default; }
  fWorkCanvas := Canvas;
  { Get double buffer status }
  fDoBuffer := fDoubleBuffer;
  { Disable animation in design mode if preview off }
  if csDesigning in ComponentState then
    fIsChanging:=fPreview;
  { Attempt to create bitmap for double buffer if required }
  if fDoBuffer then
  begin
    try
      if fBufferBM = nil then
        fBufferBM := TBitMap.Create;
      { Set working canvas to bitmap }
      fWorkCanvas := fBufferBM.Canvas;
      { Set bitmap size to match client area }
      fBufferBM.Width := ClientWidth;
      fBufferBM.Height := ClientHeight;
    except
      { Set to normal draw if an error occurs }
      fBufferBM.Free;
      fBufferBM := nil;
      fDoBuffer := False;
      fWorkCanvas := Canvas;
    end;
  end;
  with fWorkCanvas do
  begin
    { Fill control background }
    Brush.Color := Color;
    Brush.Style := bsSolid;
    FillRect(ClientRect);
    { Select the animation to use }
    AnimationNo := 0;
    case fAnimation of
      anSpiral: AnimationNo := 1;
      anUp: AnimationNo := 2;
      anDown: AnimationNo := 3;
      anLeft: AnimationNo := 4;
      anRight: AnimationNo := 5;
      anRandom: AnimationNo := Random(5)+1;
    end;
    { Update the display.  Tmp is the used string, which is
      compared with tmp2 }
    if fValue = '' then
    begin
      { Clear the display }
      SplitValue('',tmp,tmp3);
      SplitValue(fOldValue,tmp2,tmp4);
      while length(tmp) < fDigitNum do tmp := ' ' + tmp;
      while length(tmp2) < fDigitNum do tmp2 := ' ' + tmp2;
      while length(tmp3) < fDigitNum do tmp3 := ' ' + tmp3;
      while length(tmp4) < fDigitNum do tmp4 := ' ' + tmp4;
      if fIsChanging then
        DrawDigit(AnimationNo,fAnimationDelay,False)
      else
        DrawDigit(0,0,False);
    end
    else
    begin
      { We start counting the whole delay here, as time can be wasted
        drawing the display.  A delay of 1000 MUST last around 1 second }
      { Here, we draw over the old value, but first we need
        to quickly redraw the old value incase the component
        is blank and is using an animation }
      SplitValue(fOldValue,tmp,tmp3);
      SplitValue('',tmp2,tmp4);
      while length(tmp) < fDigitNum do tmp := ' ' + tmp;
      while length(tmp2) < fDigitNum do tmp2 := ' ' + tmp2;
      while length(tmp3) < fDigitNum do tmp3 := ' ' + tmp3;
      while length(tmp4) < fDigitNum do tmp4 := ' ' + tmp4;
      DrawDigit(0,0,False);
      { Now draw the new value }
      SplitValue(fValue,tmp,tmp3);
      SplitValue(fOldValue,tmp2,tmp4);
      while length(tmp) < fDigitNum do tmp := ' ' + tmp;
      while length(tmp2) < fDigitNum do tmp2 := ' ' + tmp2;
      while length(tmp3) < fDigitNum do tmp3 := ' ' + tmp3;
      while length(tmp4) < fDigitNum do tmp4 := ' ' + tmp4;
      { Here we see how much delay time is left }
      tmpDelay := fAnimationDelay - Integer(GetTickCount-FirstTickCount);
      if tmpDelay < 0 then tmpDelay := 0;
      if fIsChanging then
        DrawDigit(AnimationNo,tmpDelay,True)
      else
        DrawDigit(0,0,True);
    end;
    { Store the value that we just used }
    if fValue = '' then fOldValue := '' else
      fOldValue := fValue;
  end;
  { Copy from buffer to screen & free memory if double buffering }
  if fDoBuffer then
  begin
     Canvas.CopyRect(ClientRect,fWorkCanvas,ClientRect);
     { Get rid of bitmap }
     fBufferBM.Free;
     fBufferBM := nil;
  end;
  { Disable animation }
  fIsChanging:=false;
  { Allow drawing }
  fIsPainting:=false;
  { Set paint duration value }
  fPaintDuration:=GetTickCount - PaintStart;
end;

procedure Register;
begin
  RegisterComponents('Standard', [TLCD99]);
end;

end.

⌨️ 快捷键说明

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