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

📄 morphlcd.ctl

📁 串口通讯。上位机实例.提供了良好的界面。对初学者很有参考性
💻 CTL
📖 第 1 页 / 共 5 页
字号:

'  segment 1 (top)
   DisplaySegment LCD(), HORIZONTAL_HEXAGONAL_SEGMENT, _
                  OffsetX + HalfSegmentWidth + SegmentGap, _
                  OffsetY, _
                  Mid(DisplayPattern(Digit), 1, 1)

'  segment 2 (top right)
   DisplaySegment LCD(), VERTICAL_HEXAGONAL_SEGMENT, _
                  OffsetX + SegmentHeight + DoubleSegmentGap, _
                  OffsetY + HalfSegmentWidth + SegmentGap, _
                  Mid(DisplayPattern(Digit), 2, 1)

'  segment 3 (bottom right)
   DisplaySegment LCD(), VERTICAL_HEXAGONAL_SEGMENT, _
                  OffsetX + SegmentHeight + DoubleSegmentGap, _
                  OffsetY + SegmentHeight + HalfSegmentWidth + TripleSegmentGap, _
                  Mid(DisplayPattern(Digit), 3, 1)

'  segment 4 (bottom)
   DisplaySegment LCD(), HORIZONTAL_HEXAGONAL_SEGMENT, _
                  OffsetX + HalfSegmentWidth + SegmentGap, _
                  OffsetY + (2 * SegmentHeight) + QuadrupleSegmentGap, _
                  Mid(DisplayPattern(Digit), 4, 1)

'  segment 5 (bottom left)
   DisplaySegment LCD(), VERTICAL_HEXAGONAL_SEGMENT, _
                  OffsetX, _
                  OffsetY + SegmentHeight + HalfSegmentWidth + TripleSegmentGap, _
                  Mid(DisplayPattern(Digit), 5, 1)

'  segment 6 (top left)
   DisplaySegment LCD(), VERTICAL_HEXAGONAL_SEGMENT, _
                  OffsetX, _
                  OffsetY + HalfSegmentWidth + SegmentGap, _
                  Mid(DisplayPattern(Digit), 6, 1)

'  segment 7 (center)
   DisplaySegment LCD(), HORIZONTAL_HEXAGONAL_SEGMENT, _
                  OffsetX + HalfSegmentWidth + SegmentGap, _
                  OffsetY + SegmentHeight + DoubleSegmentGap, _
                  Mid(DisplayPattern(Digit), 7, 1)

End Sub

Private Sub DisplayTrapezoidalSegmentDigit(ByVal strDigit As String, ByRef LCD() As Long, _
                                           ByVal OffsetX As Long, ByVal OffsetY As Long, _
                                           ByVal SegmentHeight As Long, ByVal SegmentWidth As Long, _
                                           ByVal SegmentGap As Long, ByVal DigWidth As Long, _
                                           ByVal DigHeight As Long)

'*************************************************************************
'* displays a trapezoidal-segment display digit according to pattern.    *
'*************************************************************************

   Dim Digit As Long    ' the display pattern index of the current digit to draw.
   Dim r As Long        ' bitblt function call return.

'  used to avoid unnecessary recalculations of segment gap multiples.  Just a speed
'  tweak for situations where the display must be updated quickly (as in a counter).
   Dim DoubleSegmentGap    As Long
   Dim TripleSegmentGap    As Long
   Dim QuadrupleSegmentGap As Long

   DoubleSegmentGap = 2 * SegmentGap
   TripleSegmentGap = 3 * SegmentGap
   QuadrupleSegmentGap = 4 * SegmentGap

'  blit the appropriate portion of the background over the digit position to 'erase' old digit.
   r = BitBlt(hdc, OffsetX, OffsetY, DigWidth, DigHeight, VirtualDC_BG, OffsetX, OffsetY, vbSrcCopy)

'  get the appropriate segment display pattern for the digit.
   Digit = GetDisplayPatternIndex(strDigit)
   If Digit = -1 Then
      Exit Sub
   End If

'  segment 1 (top)
   DisplaySegment LCD(), HORIZONTAL_DOWNWARD_TRAPEZOIDAL_SEGMENT, _
                  OffsetX + SegmentGap, _
                  OffsetY, _
                  Mid(DisplayPattern(Digit), 1, 1)

'  segment 2 (top right)
   DisplaySegment LCD(), VERTICAL_LEFTWARD_TRAPEZOIDAL_SEGMENT, _
                  OffsetX + SegmentHeight + DoubleSegmentGap - SegmentWidth, _
                  OffsetY + SegmentGap, _
                  Mid(DisplayPattern(Digit), 2, 1)

'  segment 3 (bottom right)
   DisplaySegment LCD(), VERTICAL_LEFTWARD_TRAPEZOIDAL_SEGMENT, _
                  OffsetX + SegmentHeight + DoubleSegmentGap - SegmentWidth, _
                  OffsetY + SegmentHeight + TripleSegmentGap, _
                  Mid(DisplayPattern(Digit), 3, 1)

'  segment 4 (bottom)
'  note:  for some reason if I don't subtract 1 from the x offset in gradient segment
'  mode, it displays 1 pixel too far to the right.  I know, it's a cheesy kluge fix.
   DisplaySegment LCD(), HORIZONTAL_UPWARD_TRAPEZOIDAL_SEGMENT, _
                  OffsetX + SegmentGap, _
                  OffsetY + (2 * SegmentHeight) + QuadrupleSegmentGap - SegmentWidth, _
                  Mid(DisplayPattern(Digit), 4, 1)
'                  OffsetX SegmentGap, _
'                  OffsetY + (2 * SegmentHeight) + TripleSegmentGap, _
'                  Mid(DisplayPattern(Digit), 4, 1)

'  segment 5 (bottom left)
   DisplaySegment LCD(), VERTICAL_RIGHTWARD_TRAPEZOIDAL_SEGMENT, _
                  OffsetX, _
                  OffsetY + SegmentHeight + TripleSegmentGap, _
                  Mid(DisplayPattern(Digit), 5, 1)

'  segment 6 (top left)
   DisplaySegment LCD(), VERTICAL_RIGHTWARD_TRAPEZOIDAL_SEGMENT, _
                  OffsetX, _
                  OffsetY + SegmentGap, _
                  Mid(DisplayPattern(Digit), 6, 1)

'  segment 7 (middle)
   DisplaySegment LCD(), HORIZONTAL_HEXAGONAL_SEGMENT, _
                  OffsetX + SegmentGap, _
                  OffsetY + SegmentHeight + DoubleSegmentGap - (SegmentWidth \ 2), _
                  Mid(DisplayPattern(Digit), 7, 1)

End Sub

Private Sub DisplayRectangularSegmentDigit(ByVal strDigit As String, ByRef LCD() As Long, _
                                           ByVal OffsetX As Long, ByVal OffsetY As Long, _
                                           ByVal SegmentHeight As Long, ByVal SegmentWidth As Long, _
                                           ByVal SegmentGap As Long, ByVal DigWidth As Long, _
                                           ByVal DigHeight As Long)

'*************************************************************************
'* displays a rectangular-segment display digit according to pattern.    *
'*************************************************************************

   Dim Digit As Long    ' the display pattern index of the current digit to draw.
   Dim r     As Long    ' bitblt function call return.

'  used to avoid unnecessary recalculations of segment gap multiples.  Just a speed
'  tweak for situations where the display must be updated quickly (as in a counter).
   Dim DoubleSegmentGap    As Long
   Dim TripleSegmentGap    As Long
   Dim QuadrupleSegmentGap As Long
   Dim DoubleSegmentWidth  As Long

   DoubleSegmentGap = 2 * SegmentGap
   TripleSegmentGap = 3 * SegmentGap
   QuadrupleSegmentGap = 4 * SegmentGap
   DoubleSegmentWidth = 2 * SegmentWidth

'  blit the appropriate portion of the background over the digit position to 'erase' old digit.
   r = BitBlt(hdc, OffsetX, OffsetY, DigWidth, DigHeight, VirtualDC_BG, OffsetX, OffsetY, vbSrcCopy)

'  get the appropriate segment display pattern for the digit.
   Digit = GetDisplayPatternIndex(strDigit)
   If Digit = -1 Then
      Exit Sub
   End If

'  segment 1 (top)
   DisplaySegment LCD(), HORIZONTAL_RECTANGULAR_SEGMENT, _
                  OffsetX + SegmentWidth + SegmentGap - 1, _
                  OffsetY, _
                  Mid(DisplayPattern(Digit), 1, 1)

'  segment 2 (top right)
   DisplaySegment LCD(), VERTICAL_RECTANGULAR_SEGMENT, _
                  OffsetX + SegmentWidth + SegmentHeight + DoubleSegmentGap - 2, _
                  OffsetY + SegmentWidth + SegmentGap - 1, _
                  Mid(DisplayPattern(Digit), 2, 1)

'  segment 3 (bottom right)
   DisplaySegment LCD(), VERTICAL_RECTANGULAR_SEGMENT, _
                  OffsetX + SegmentWidth + SegmentHeight + DoubleSegmentGap - 2, _
                  OffsetY + SegmentHeight + DoubleSegmentWidth + TripleSegmentGap - 3, _
                  Mid(DisplayPattern(Digit), 3, 1)

'  segment 4 (bottom)
   DisplaySegment LCD(), HORIZONTAL_RECTANGULAR_SEGMENT, _
                  OffsetX + SegmentWidth + SegmentGap - 1, _
                  OffsetY + (2 * SegmentHeight) + DoubleSegmentWidth + QuadrupleSegmentGap - 4, _
                  Mid(DisplayPattern(Digit), 4, 1)

'  segment 5 (bottom left)
   DisplaySegment LCD(), VERTICAL_RECTANGULAR_SEGMENT, _
                  OffsetX, _
                  OffsetY + SegmentHeight + DoubleSegmentWidth + TripleSegmentGap - 3, _
                  Mid(DisplayPattern(Digit), 5, 1)

'  segment 6 (top left)
   DisplaySegment LCD(), VERTICAL_RECTANGULAR_SEGMENT, _
                  OffsetX, _
                  OffsetY + SegmentWidth + SegmentGap - 1, _
                  Mid(DisplayPattern(Digit), 6, 1)

'  segment 7 (center)
   DisplaySegment LCD(), HORIZONTAL_RECTANGULAR_SEGMENT, _
                  OffsetX + SegmentWidth + SegmentGap - 1, _
                  OffsetY + SegmentHeight + SegmentWidth + DoubleSegmentGap - 2, _
                  Mid(DisplayPattern(Digit), 7, 1)

End Sub

Private Function GetDisplayPatternIndex(ByVal strDigit As String) As Long

'*************************************************************************
'* returns correct segment lighting pattern index for supplied digit.    *
'*************************************************************************

   If strDigit = " " And m_ShowBurnIn Then
'     for showing unlit digits in burn-in display mode.
      GetDisplayPatternIndex = 10
   ElseIf strDigit = " " Then
'     if not showing burn-in pattern, don't mess with an unlit digit at all.
      GetDisplayPatternIndex = -1
   ElseIf strDigit = "-" Then
'     the pattern index for the minus sign.
      GetDisplayPatternIndex = 11
   ElseIf InStr("ABCDEF", strDigit) Then
'     the pattern index for the appropriate hex value A-F.
      GetDisplayPatternIndex = Asc(strDigit) - 53
   Else
'     the appropriate pattern index for the supplied digit.
      GetDisplayPatternIndex = Val(strDigit)
   End If

End Function

Private Sub DisplaySegment(LCD() As Long, ByVal SegmentNdx As Long, ByVal StartX As Long, ByVal StartY As Long, ByVal LitStatus As String)

'*************************************************************************
'* displays one segment of an LCD digit according to its fill style.     *
'*************************************************************************

'  position the segment region in the correct location.
   OffsetRgn LCD(SegmentNdx), StartX, StartY

   If LitStatus = SEGMENT_UNLIT And m_ShowBurnIn Then
'     if segment is unlit but burn-in mode is active, display as unlit according to fill mode.
      Select Case m_SegmentFillStyle
         Case [Solid]
            FillRgn hdc, LCD(SegmentNdx), CurrentBurnInColorBrush
         Case [Filament]
            FrameRgn hdc, LCD(SegmentNdx), CurrentBurnInColorBrush, 1, 1
      End Select
   Else
      If LitStatus = SEGMENT_LIT Then
'        otherwise, if segment is lit, display according to fill mode.
         Select Case m_SegmentFillStyle
            Case [Solid]
               FillRgn hdc, LCD(SegmentNdx), CurrentLitColorBrush
            Case [Filament]
               FrameRgn hdc, LCD(SegmentNdx), CurrentLitColorBrush, 1, 1
            Case [Gradient]
               Select Case SegmentNdx
                  Case 0, 3, 5, 6  ' these are the vertical digit s

⌨️ 快捷键说明

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