Attribute VB_Name = "Module1"
'#Uses "..\classes\FunctionClass.cls
'#Uses "..\classes\PortPin.cls"
'#Uses "..\include\Const.inc"
'#Uses "..\include\Format.inc"
'#Uses "..\include\Global.inc"
'#Uses "..\include\Pages.inc"
'#Uses "..\include\Port.inc"
'#Uses "Include.inc"
Option Explicit

'*****************************************************************************
' Module:
'        T01
'-----------------------------------------------------------------------------
' Description:
'        This file contains functions which are create controls for the
'        module 'T01'.
'        Furthermore it contains functions for the event handling of
'        these controls.
'
'-----------------------------------------------------------------------------
' History:
'
'        Rev. Author         Date        Description
'        ---------------------------------------------------------------------
'        0.1  Sunil         12-10-04     Initial version
'        0.2  Sunil         03-12-04     GUI Control position coordinates are altered.
'        0.3  Sunil         13-12-04     The Timer0 overflow flag caption "TFO" is changed
'                                        to "TF0".
'        0.4  Sunil         20-12-04     "Enable the Gating Control" option for Timer0 and Timer1 is changed.
'                                         Timer0/1 is enable only while pin EXINT0 is high, not low.
'        0.5  Sunil           29-12-04   module prefix added.
'
'
'*****************************************************************************

'*****************************************************************************
'Description:
'        This function is called from DAvE just before the Peripherals
'        window is shown.
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Function OnLoad(ps As Peripherals) As Boolean
    On Error GoTo OnLoadError

    OnLoad = False
    
    If (Not OnLoadPageTimer0(ps)) Then Exit Function
    If (Not OnLoadPageTimer1(ps)) Then Exit Function
    If (Not OnLoadPageInterrupts(ps)) Then Exit Function
    If (Not OnLoadPageFunctions(ps)) Then Exit Function
    If (Not OnLoadPageParameters(ps)) Then Exit Function
    If (Not OnLoadPageNotes(ps)) Then Exit Function
    
    ' call function to initialize the menu
    If (Not InitMenu(ps, "T01\Dialog")) Then Exit Function

    
    OnLoad = True
    Exit Function

OnLoadError:
    Exit Function
End Function

'*****************************************************************************
'Description:
'        This function is called from DAvE just before a page
'        is shown.
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Page            no. of the page (starts with 1)
'        Pagename        name of the page
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Function OnChangingPage(ps As Peripherals, Page As Integer, Pagename As String) As Boolean
    On Error GoTo OnChangingPageError

    OnChangingPage = False
    
    If (Not OnChangingPageTimer0(ps, Pagename)) Then Exit Function
    If (Not OnChangingPageTimer1(ps, Pagename)) Then Exit Function
    If (Not OnChangingPageInterrupts(ps, Pagename)) Then Exit Function
    If (Not OnChangingPageFunctions(ps, Pagename)) Then Exit Function
    If (Not OnChangingPageParameters(ps, Pagename)) Then Exit Function
    If (Not OnChangingPageNotes(ps, Pagename, "T01")) Then Exit Function

    OnChangingPage = True
    Exit Function

OnChangingPageError:
    Exit Function
End Function

'*****************************************************************************
'Description:
'        This function is called from DAvE in two cases:
'
'        1.
'            The contents of the peripherals window must be refreshed.
'            In this case the 'Controlname' parameter is a empty string
'            and the values array 'v()' contains nothing.
'
'        2.
'            A control on the peripherals has been changed.
'            In this case the 'Controlname' parameter contains the name
'            of the changed control and the values array 'v()' contains the
'            changed value(s).
'
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Controlname     name of the changed control (for case 2)
'        v()             array with the changed values (for case 2)
'        Page            no. of the page (starts with 1)
'        Pagename        name of the page
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Function OnShow(ps As Peripherals, Controlname As String, v() As Variant, Page As Integer, Pagename As String) As Boolean
    On Error Resume Next

    OnShow = False

    If (Not OnShowPageTimer0(ps, Controlname, Pagename, v)) Then Exit Function
    If (Not OnShowPageTimer1(ps, Controlname, Pagename, v)) Then Exit Function
    If (Not OnShowPageInterrupts(ps, Controlname, Pagename, v)) Then Exit Function
    If (Not OnShowPageFunctions(ps, Controlname, Pagename, v)) Then Exit Function
    If (Not OnShowPageParameters(ps, Controlname, Pagename, v)) Then Exit Function
    If (Not OnShowPageNotes(ps, Controlname, Pagename, "T01", v)) Then Exit Function

    OnShow = True
End Function

'*****************************************************************************
'Description:
'        This function is called from DAvE if the user clicks on a button.
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Controlname     name of the button
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Function OnClick(ps As Peripherals, Controlname As String) As Boolean
    On Error GoTo OnClickError

    OnClick = False
    ' no buttons implemented
    OnClick = True
    Exit Function

OnClickError:
    Errorbox "Can not process the click", Err.Description
    Exit Function
End Function

'*****************************************************************************
'Description:
'        This function is called from DAvE if the user clicks on a menu entry.
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Toolname        name of the entry
'        ToolId          id of the entry
'        Tooltext        additional text of the entry
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Function OnMenuClick(ps As Peripherals, Toolname As String, ToolId As Long, Tooltext As String) As Boolean
    On Error GoTo OnMenuClickError

    OnMenuClick = False

    If (Not MenuClick(ps, Toolname, ToolId, Tooltext, "T01\Dialog")) Then Exit Function

    OnMenuClick = True
    Exit Function

OnMenuClickError:
    Exit Function
End Function

'-----------------------------------------------------------------------------
' local functions
'-----------------------------------------------------------------------------

'*****************************************************************************
'Description:
'        This function is called from the OnLoad function of the associated
'        module in order to add a page.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnLoadPageTimer0(ps As Peripherals) As Boolean
  On Error Resume Next
  OnLoadPageTimer0 = False

  If (Not ps.AddPage("Timer 0")) Then Exit Function

  OnLoadPageTimer0 = True
End Function

'*****************************************************************************
'Description:
'        This function is called from the OnChangingPage function of the
'        associated module in order load all controls for the requested page
'        if they are not already loaded.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'        Pagename         requested page name
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnChangingPageTimer0(ps As Peripherals, Pagename As String) As Boolean
  On Error Resume Next

  OnChangingPageTimer0 = False

  If (Not ps.ExtenderCollection("Timer 0").Loaded) And (Pagename = "Timer 0") Then
    ps.ExtenderCollection("Timer 0").Loaded = True

    If (Not ps.AddFrame("fraT0_TimerOperation", 125, 150, 5400, 2425, "Timer Mode (TMOD.T0M)")) Then Exit Function
        If (Not ps.AddOption("optT0_Mode0", 125, 400, 4550, 380, "Mode 0: 8-bit timer (TH0) with a divide-by-32 prescaler (TL0)")) Then Exit Function
        If (Not ps.AddOption("optT0_Mode1", 125, 900, 2500, 380, "Mode 1: 16-bit timer (TH0/TL0)")) Then Exit Function
        If (Not ps.AddOption("optT0_Mode2", 125, 1400, 4000, 380, "Mode 2: 8-bit timer (TL0) with 8-bit auto-reload (TH0)")) Then Exit Function
        If (Not ps.AddOption("optT0_Mode3", 125, 1900, 4100, 380, "Mode 3: 8-bit timer (TL0) and second 8-bit timer (TH0)")) Then Exit Function

    If (Not ps.AddFrame("fraT0_TimerOptions", 5750, 150, 2800, 2425, "Timer Options")) Then Exit Function
        If (Not ps.AddCheck("chkT0_Counter", 125, 200, 2500, 700, "Counter operation on Pin T0 (P1.1)")) Then Exit Function
        If (Not ps.AddCheck("chkT0_EnableGating", 125, 800, 2500, 700, "Enable Gating Control: Timer 0 is enabled only while pin EXINT0 is high. (GATE0)")) Then Exit Function
        If (Not ps.AddCheck("chkT0_TurnOnTimer0", 125, 1450, 1700, 380, "Turn on timer (TR0)")) Then Exit Function
        If (Not ps.AddCheck("chkT0_TurnOnSecondTimer0", 125, 1875, 2250, 380, "Turn on second timer (TR1)")) Then Exit Function

    If (Not ps.AddFrame("fraT0_TimerRegisters", 125, 2750, 5400, 2475, "Timer Registers")) Then Exit Function
        If (Not ps.AddLabel("lblT0_TL0", 0, 125, 475, 2950, 325, "")) Then Exit Function
        ps.ControlCollection("lblT0_TL0").Alignment = 1 'right justified
        If (Not ps.AddText("txtT0_TL0", 3250, 400, 900, 340)) Then Exit Function

        If (Not ps.AddLabel("lblT0_TH0", 0, 125, 975, 2950, 325, "")) Then Exit Function
        ps.ControlCollection("lblT0_TH0").Alignment = 1 'right justified
        If (Not ps.AddText("txtT0_TH0", 3250, 900, 900, 340)) Then Exit Function

        If (Not ps.AddLabel("lblT0_TF0Label", 0, 125, 1475, 2950, 325, "Timer overflow [" & Chr(181) & "s] (TF0)")) Then Exit Function
        ps.ControlCollection("lblT0_TF0Label").Alignment = 1 'right justified
        If (Not ps.AddLabel("lblT0_TF0", 1, 3250, 1450, 1275, 315, "38.38")) Then Exit Function

        If (Not ps.AddLabel("lblT0_TF1Label", 0, 125, 1975, 2950, 325, "Timer overflow [" & Chr(181) & "s] of second timer (TF1)")) Then Exit Function
        ps.ControlCollection("lblT0_TF1Label").Alignment = 1 'right justified
        If (Not ps.AddLabel("lblT0_TF1", 1, 3250, 1950, 1275, 315, "38.38")) Then Exit Function

    If (Not ps.AddFrame("fraT0_InterruptControl", 5725, 2750, 2825, 2475, "Interrupt Control")) Then Exit Function
        If (Not ps.AddCheck("chkT0_EnableET0", 125, 300, 2400, 400, "Enable interrupt of timer (ET0)")) Then Exit Function
        If (Not ps.AddCheck("chkT0_EnableET1", 125, 800, 2250, 425, "Enable interrupt of second timer (ET1)")) Then Exit Function

  End If
  OnChangingPageTimer0 = True
End Function

'*****************************************************************************
'Description:
'        This function is called from the OnShow function of the associated
'        module. See the description for the OnShow function of the
'        associated module for details.
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Controlname     control name
'        Pagename        current page name
'        v()             value array
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnShowPageTimer0(ps As Peripherals, Controlname As String, Pagename As String, v() As Variant) As Boolean
  On Error GoTo OnShowError

  OnShowPageTimer0 = False
     
  Dim r As ProjectData
  Dim c As Collection
  Dim e As Collection
  Dim bDisabled As Boolean
  Dim iTemp As Integer

  Set r = ps.ProjectData
  Set c = ps.ControlCollection
  Set e = ps.ExtenderCollection

  If (Pagename = "Timer 0") Then
    '-------------------------------------------------------------------------
    ' page: Timer 0 (action)
    '-------------------------------------------------------------------------
        
    Select Case Controlname

        Case "optT0_Mode0"
            If (GetTimer0Mode(r) = 3) Then
                r.v(T01_PREFIX & "TCON_TR1") = 0
                r.v(CORE_PREFIX & "IEN0_ET1") = 0
                r.v("T01_USE_IsrTmr1") = 0
            End If
            r.v(T01_PREFIX & "TL0_VAL") = 0
            r.v(T01_PREFIX & "TH0_VAL") = 0
            Call SetTimer0Mode(r, 0)
            r.v("T01_USE_StartTmr1") = 0    'deselect function
            r.v("T01_USE_StopTmr1") = 0     'deselect function

        Case "optT0_Mode1"
            If (GetTimer0Mode(r) = 3) Then
                r.v(T01_PREFIX & "TCON_TR1") = 0
                r.v(CORE_PREFIX & "IEN0_ET1") = 0
                r.v("T01_USE_IsrTmr1") = 0
            End If
            r.v(T01_PREFIX & "TL0_VAL") = 0
            r.v(T01_PREFIX & "TH0_VAL") = 0
            Call SetTimer0Mode(r, 1)
            r.v("T01_USE_StartTmr1") = 0    'deselect function
            r.v("T01_USE_StopTmr1") = 0     'deselect function

        Case "optT0_Mode2"
            If (GetTimer0Mode(r) = 3) Then
                r.v(T01_PREFIX & "TCON_TR1") = 0
                r.v(CORE_PREFIX & "IEN0_ET1") = 0
                r.v("T01_USE_IsrTmr1") = 0
            End If
            r.v(T01_PREFIX & "TL0_VAL") = 0
            r.v(T01_PREFIX & "TH0_VAL") = 0
            Call SetTimer0Mode(r, 2)
            r.v("T01_USE_StartTmr1") = 0    'deselect function
            r.v("T01_USE_StopTmr1") = 0     'deselect function
    
        Case "optT0_Mode3"
            r.v(T01_PREFIX & "TL0_VAL") = 0
            r.v(T01_PREFIX & "TH0_VAL") = 0
            r.v(T01_PREFIX & "TMOD_GATE1") = 0
            Call SetTimer0Mode(r, 3)

        Case "chkT0_TurnOnTimer0"
            r.v(T01_PREFIX & "TCON_TR0") = v(1)

        Case "chkT0_TurnOnSecondTimer0"
            r.v(T01_PREFIX & "TCON_TR1") = v(1)

    
        Case "chkT0_Counter"
            r.v(T01_PREFIX & "TMOD_T0S") = v(1)
            If v(1) Then
                Call RequestAlternateInputPin(r, "T0_1")
            Else
                Call ReleaseAlternateInputPin(r, "T0_1")
            End If
            
        Case "chkT0_EnableGating"
            If (v(1) = 1) Then
                Call RequestAlternateInputPin(r, "EXINT0_0_(Gate)")
            Else
                Call ReleaseAlternateInputPin(r, "EXINT0_0_(Gate)")
            End If
            r.v(T01_PREFIX & "TMOD_GATE0") = v(1)
    
        Case "txtT0_TL0"
            If (GetTimer0Mode(r) = 0) Then
                iTemp = 31      ' mode 0: 5-bit prescaler
            Else
                iTemp = 255     ' modes 1-3: 8-bit register
            End If

            If (IsInputFormatOK(v(1), "", "TL0", 0, iTemp)) Then
                r.v(T01_PREFIX & "TL0_VAL") = v(1)
            Else
                Exit Function
            End If
    
        Case "txtT0_TH0"
            If (IsInputFormatOK(v(1), "", "TH0", 0, 255)) Then
                r.v(T01_PREFIX & "TH0_VAL") = v(1)
            Else
                Exit Function
            End If
    
        Case "chkT0_EnableET0"
            r.v(CORE_PREFIX & "IEN0_ET0") = v(1)
            r.v("T01_USE_IsrTmr0") = v(1)

        Case "chkT0_EnableET1"
            r.v(CORE_PREFIX & "IEN0_ET1") = v(1)
            r.v("T01_USE_IsrTmr1") = v(1)

    End Select     ' case Controlname

    '-------------------------------------------------------------------------
    ' page: Timer 0 (show)
    '-------------------------------------------------------------------------
    With c("optT0_Mode0")
        .Value = GetTimer0Mode(r) = 0
    End With

    With c("optT0_Mode1")
        .Value = GetTimer0Mode(r) = 1
    End With

    With c("optT0_Mode2")
        .Value = GetTimer0Mode(r) = 2
    End With

    With c("optT0_Mode3")
        .Value = GetTimer0Mode(r) = 3
    End With

    With c("chkT0_TurnOnTimer0")
        .Value = -CInt(r.v(T01_PREFIX & "TCON_TR0") = 1)
    End With

    With c("chkT0_TurnOnSecondTimer0")
        .Visible = GetTimer0Mode(r) = 3
        .Value = -CInt(r.v(T01_PREFIX & "TCON_TR1") = 1)
    End With

    With c("chkT0_EnableGating")
                bDisabled = Not IsAlternatePinFree(r, "EXINT0_0_(Gate)")
        .Enabled = Not bDisabled
        .Value = -CInt(r.v(T01_PREFIX & "TMOD_GATE0") = 1)
    End With
    With e("chkT0_EnableGating")
                If (bDisabled) Then
                .DisabledToolTipText = TOOLTIP_DISABLED_IF
                        .DisabledToolTipText = .DisabledToolTipText & GetDisabledAlternatePinTooltip(ps.ProjectData, "EXINT0_0_(Gate)")
                End If
    End With

    With c("txtT0_TL0")
        .Text = FormatTextOutput(r.v(T01_PREFIX & "TL0_VAL"), "H2")
    End With

    With c("lblT0_TL0")
        Select Case GetTimer0Mode(r)
            Case 0
                .Caption = "5-bit prescaler (TL0)"
            Case 1
                .Caption = "Lower byte of 16-bit timer (TL0)"
            Case 2
                .Caption = "8-bit timer (TL0)"
            Case 3
                .Caption = "8-bit timer (TL0)"
        End Select
    End With

    With c("txtT0_TH0")
        .Text = FormatTextOutput(r.v(T01_PREFIX & "TH0_VAL"), "H2")
    End With

    With c("lblT0_TH0")
        Select Case GetTimer0Mode(r)
            Case 0
                .Caption = "8-bit timer (TH0)"
            Case 1
                .Caption = "Higher byte of 16-bit timer (TH0)"
            Case 2
                .Caption = "Reload value (TH0)"
            Case 3
                .Caption = "Second 8-bit timer (TH0)"
        End Select
    End With

    With c("lblT0_TF0")
        Select Case GetTimer0Mode(r)
            Case 0
                .Caption = GetTimerOverflow(r, 0, 0)
            Case 1
                .Caption = GetTimerOverflow(r, 0, 1)
            Case 2
                .Caption = GetTimerOverflow(r, 0, 2)
            Case 3
                .Caption = GetTimerOverflow(r, 0, 3)
        End Select

    End With

    With c("chkT0_Counter")
        bDisabled = Not IsAlternatePinFree(r, "T0_1")
        .Enabled = Not bDisabled
        .Value = r.v(T01_PREFIX & "TMOD_T0S")
    End With
    
    With e("chkT0_Counter")
        If (bDisabled) Then
           .DisabledToolTipText = TOOLTIP_DISABLED_IF
           .DisabledToolTipText = .DisabledToolTipText & GetDisabledAlternatePinTooltip(ps.ProjectData, "T0_1")
        End If
    End With
    
    With c("lblT0_TF0Label")
        .Visible = c("lblT0_TF0").Visible
    End With

    With c("lblT0_TF1")
        If ((GetTimer0Mode(r) = 3)) Then
            .Caption = GetTimerOverflow(r, 1, 3)    'second 8-bit timer
            .Visible = True
        Else
            .Visible = False
        End If
    End With

    With c("lblT0_TF1Label")
        .Visible = c("lblT0_TF1").Visible
    End With

    With c("chkT0_EnableET0")
        .Value = -CInt(r.v(CORE_PREFIX & "IEN0_ET0") = 1)
    End With

    With c("chkT0_EnableET1")
        If (GetTimer0Mode(r) = 3) Then
            .Visible = True
            .Value = -CInt(r.v(CORE_PREFIX & "IEN0_ET1") = 1)
        Else
            .Visible = False
        End If
    End With

  End If         ' if Pagename

  OnShowPageTimer0 = True
  Exit Function

OnShowError:
    Errorbox "Can not show page", Err.Description
End Function

Public Function OnLoadPageTimer1(ps As Peripherals) As Boolean
  On Error Resume Next
  OnLoadPageTimer1 = False

  If (Not ps.AddPage("Timer 1")) Then Exit Function

  OnLoadPageTimer1 = True
End Function

'*****************************************************************************
'Description:
'        This function is called from the OnChangingPage function of the
'        associated module in order load all controls for the requested page
'        if they are not already loaded.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'        Pagename         requested page name
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnChangingPageTimer1(ps As Peripherals, Pagename As String) As Boolean
  On Error Resume Next

  OnChangingPageTimer1 = False

  If (Not ps.ExtenderCollection("Timer 1").Loaded) And (Pagename = "Timer 1") Then
    ps.ExtenderCollection("Timer 1").Loaded = True

    If (Not ps.AddFrame("fraT1_TimerOperation", 125, 150, 5400, 2425, "Timer Mode (TMOD.T1M)")) Then Exit Function
    If (Not ps.AddOption("optT1_Mode0", 125, 400, 4550, 380, "Mode 0: 8-bit timer (TH1) with a divide-by-32 prescaler (TL1)")) Then Exit Function
    If (Not ps.AddOption("optT1_Mode1", 125, 900, 2500, 380, "Mode 1: 16-bit timer (TH1/TL1)")) Then Exit Function
    If (Not ps.AddOption("optT1_Mode2", 125, 1400, 4000, 380, "Mode 2: 8-bit timer (TL1) with 8-bit auto-reload (TH1)")) Then Exit Function
    If (Not ps.AddOption("optT1_Mode3", 125, 1900, 2400, 380, "Mode 3: Timer holds its count")) Then Exit Function

    If (Not ps.AddFrame("fraT1_TimerOptions", 5750, 150, 2800, 2425, "Timer Options")) Then Exit Function
    If (Not ps.AddCheck("chkT1_Counter", 125, 200, 2500, 700, "Counter operation on Pin T1 (P1.5)")) Then Exit Function
    If (Not ps.AddCheck("chkT1_EnableGating", 125, 800, 2500, 700, "Enable Gating Control: Timer 1 is enabled only while pin EXINT1 is high. (GATE1)")) Then Exit Function
    If (Not ps.AddCheck("chkT1_TurnOnTimer1", 125, 1450, 1700, 380, "Turn on timer (TR1)")) Then Exit Function
    ps.ControlCollection("chkT1_TurnOnTimer1").Enabled = False

    If (Not ps.AddFrame("fraT1_TimerRegisters", 125, 2750, 5400, 2475, "Timer Registers")) Then Exit Function

    If (Not ps.AddLabel("lblT1_TL1", 0, 125, 475, 2950, 325, "- not used - (TL1)")) Then Exit Function
    ps.ControlCollection("lblT1_TL1").Alignment = 1 'right justified
    If (Not ps.AddText("txtT1_TL1", 3250, 400, 900, 340)) Then Exit Function

    If (Not ps.AddLabel("lblT1_TH1", 0, 125, 975, 2950, 325, "- not used - (TH1)")) Then Exit Function
    ps.ControlCollection("lblT1_TH1").Alignment = 1 'right justified
    If (Not ps.AddText("txtT1_TH1", 3250, 900, 900, 340)) Then Exit Function

    If (Not ps.AddLabel("lblT1_TF1Label", 0, 125, 1475, 2950, 325, "Timer overflow [" & Chr(181) & "s] (TF1)")) Then Exit Function
    ps.ControlCollection("lblT1_TF1Label").Alignment = 1 'right justified
    If (Not ps.AddLabel("lblT1_TF1", 1, 3250, 1450, 1275, 315, "")) Then Exit Function

    If (Not ps.AddLabel("lblT1_BaudrateLabel", 0, 125, 1975, 2950, 325, "Baud Rate [baud]")) Then Exit Function
    ps.ControlCollection("lblT1_BaudrateLabel").Alignment = 1 'right justified
    If (Not ps.AddLabel("lblT1_Baudrate", 1, 3250, 1950, 1275, 315, "")) Then Exit Function
    
    If (Not ps.AddFrame("fraT1_InterruptControl", 5725, 2750, 2825, 2475, "Interrupt Control")) Then Exit Function
    If (Not ps.AddCheck("chkT1_EnableET1", 125, 300, 2400, 400, "Enable interrupt of timer (ET1)")) Then Exit Function
    ps.ControlCollection("chkT1_EnableET1").Enabled = False

  End If
  OnChangingPageTimer1 = True
End Function

'*****************************************************************************
'Description:
'        This function is called from the OnShow function of the associated
'        module. See the description for the OnShow function of the
'        associated module for details.
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Controlname     control name
'        Pagename        current page name
'        v()             value array
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnShowPageTimer1(ps As Peripherals, Controlname As String, Pagename As String, v() As Variant) As Boolean
  On Error GoTo OnShowError

  OnShowPageTimer1 = False
     
  Dim r As ProjectData
  Dim c As Collection
  Dim e As Collection
  Dim bDisabled As Boolean
  Dim iTemp As Integer

  Set r = ps.ProjectData
  Set c = ps.ControlCollection
  Set e = ps.ExtenderCollection

  If (Pagename = "Timer 1") Then
    '-------------------------------------------------------------------------
    ' page: Timer 1 (action)
    '-------------------------------------------------------------------------
    Select Case Controlname

        Case "optT1_Mode0"
            r.v(T01_PREFIX & "TL1_VAL") = 0
            r.v(T01_PREFIX & "TH1_VAL") = 0
            Call SetTimer1Mode(r, 0)

        Case "optT1_Mode1"
            r.v(T01_PREFIX & "TL1_VAL") = 0
            r.v(T01_PREFIX & "TH1_VAL") = 0
            Call SetTimer1Mode(r, 1)

        Case "optT1_Mode2"
            r.v(T01_PREFIX & "TL1_VAL") = 0
            r.v(T01_PREFIX & "TH1_VAL") = 0
            Call SetTimer1Mode(r, 2)
    
        Case "optT1_Mode3"
            r.v(T01_PREFIX & "TL1_VAL") = 0
            r.v(T01_PREFIX & "TH1_VAL") = 0
            Call SetTimer1Mode(r, 3)

        Case "chkT1_TurnOnTimer1"
            r.v(T01_PREFIX & "TCON_TR1") = v(1)

    
        Case "chkT1_Counter"
            r.v(T01_PREFIX & "TMOD_T1S") = v(1)
            If v(1) Then
                Call RequestAlternateInputPin(r, "T1_1")
            Else
                Call ReleaseAlternateInputPin(r, "T1_1")
            End If
            
        Case "chkT1_EnableGating"
            If (v(1) = 1) Then
                        Call RequestAlternateInputPin(r, "EXINT1_(Gate)")
            Else
                        Call ReleaseAlternateInputPin(r, "EXINT1_(Gate)")
            End If
            r.v(T01_PREFIX & "TMOD_GATE1") = v(1)
    
        Case "txtT1_TL1"
            If (GetTimer1Mode(r) = 0) Then
                iTemp = 31      ' mode 0: 5-bit prescaler
            Else
                iTemp = 255     ' modes 1-3: 8-bit register
            End If

            If (IsInputFormatOK(v(1), "", "TL1", 0, iTemp)) Then
                r.v(T01_PREFIX & "TL1_VAL") = v(1)
            Else
                Exit Function
            End If
    
        Case "txtT1_TH1"
            If (IsInputFormatOK(v(1), "", "TH1", 0, 255)) Then
                r.v(T01_PREFIX & "TH1_VAL") = v(1)
            Else
                Exit Function
            End If
    
        Case "chkT1_EnableET1"
            r.v(CORE_PREFIX & "IEN0_ET1") = v(1)
            r.v("T01_USE_IsrTmr1") = v(1)

    End Select     ' case Controlname

    '-------------------------------------------------------------------------
    ' page: Timer 1 (show)
    '-------------------------------------------------------------------------
    With c("optT1_Mode0")
        .Value = GetTimer1Mode(r) = 0
    End With

    With c("optT1_Mode1")
        .Value = GetTimer1Mode(r) = 1
    End With

    With c("optT1_Mode2")
        .Value = GetTimer1Mode(r) = 2
    End With

    With c("optT1_Mode3")
        .Value = GetTimer1Mode(r) = 3
    End With

    With c("chkT1_TurnOnTimer1")
        bDisabled = GetTimer0Mode(r) = 3   'conflict with Timer 0 running in mode 3
        .Enabled = Not bDisabled
        .Value = -CInt(r.v(T01_PREFIX & "TCON_TR1") = 1)
    End With
    With e("chkT1_TurnOnTimer1")
                If (bDisabled) Then
                .DisabledToolTipText = TOOLTIP_DISABLED_IF
                .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("TR1 is used by Timer 0 in mode 3")
                End If
    End With

    With c("chkT1_EnableGating")
         bDisabled = Not IsAlternatePinFree(r, "EXINT1_(Gate)")
        .Enabled = Not bDisabled
        .Value = -CInt(r.v(T01_PREFIX & "TMOD_GATE1") = 1)
    End With
    With e("chkT1_EnableGating")
                If (bDisabled) Then
                .DisabledToolTipText = TOOLTIP_DISABLED_IF
                        .DisabledToolTipText = .DisabledToolTipText & GetDisabledAlternatePinTooltip(ps.ProjectData, "EXINT1_(Gate)")
                End If
    End With

    With c("txtT1_TL1")
        .Text = FormatTextOutput(r.v(T01_PREFIX & "TL1_VAL"), "H2")
    End With

    With c("lblT1_TL1")
        Select Case GetTimer1Mode(r)
            Case 0
                .Caption = "5-bit prescaler (TL1)"
            Case 1
                .Caption = "Lower byte of 16-bit timer (TL1)"
            Case 2
                .Caption = "8-bit timer (TL1)"
            Case 3
                .Caption = "- not used - (TL1)"
        End Select
    End With

    With c("txtT1_TH1")
        .Text = FormatTextOutput(r.v(T01_PREFIX & "TH1_VAL"), "H2")
    End With

    With c("lblT1_TH1")
        Select Case GetTimer1Mode(r)
            Case 0
                .Caption = "8-bit timer (TH1)"
            Case 1
                .Caption = "Higher byte of 16-bit timer (TH1)"
            Case 2
                .Caption = "Reload value (TH1)"
            Case 3
                .Caption = "- not used - (TH1)"
        End Select
    End With

    With c("lblT1_TF1")
        Select Case GetTimer1Mode(r)
            Case 0
                .Caption = GetTimerOverflow(r, 1, 0)
                .Visible = True
            Case 1
                .Caption = GetTimerOverflow(r, 1, 1)
                .Visible = True
            Case 2
                .Caption = GetTimerOverflow(r, 1, 2)
                .Visible = True
            Case 3
                .Visible = False 'timer holds the count
        End Select
    End With

    With c("chkT1_Counter")
        bDisabled = Not IsAlternatePinFree(r, "T1_1")
        .Enabled = Not bDisabled
        .Value = r.v(T01_PREFIX & "TMOD_T1S")
    End With
    
    With e("chkT1_Counter")
        If (bDisabled) Then
           .DisabledToolTipText = TOOLTIP_DISABLED_IF
           .DisabledToolTipText = .DisabledToolTipText & GetDisabledAlternatePinTooltip(ps.ProjectData, "T1_1")
        End If
    End With
    
    With c("lblT1_TF1Label")
        .Visible = c("lblT1_TF1").Visible
    End With

    With c("lblT1_Baudrate")
        .Caption = GetTimer1Baudrate(r)
        .Visible = .Caption <> ""   ' hide object if timer 1 is not suitable configured for baudrate generation
    End With

    With c("lblT1_BaudrateLabel")
        .Visible = c("lblT1_Baudrate").Visible
    End With
    
    With c("chkT1_EnableET1")
        bDisabled = GetTimer0Mode(r) = 3  'conflict with timer 0 running in mode 3
        .Enabled = Not bDisabled
        .Value = -CInt(r.v(CORE_PREFIX & "IEN0_ET1") = 1)
    End With
    With e("chkT1_EnableET1")
        If (bDisabled) Then
            .DisabledToolTipText = TOOLTIP_DISABLED_IF
            .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("Timer 0 is in mode 3")
        End If
    End With

  End If         ' if Pagename

  OnShowPageTimer1 = True
  Exit Function

OnShowError:
    Errorbox "Can not show page", Err.Description
End Function

Public Function OnLoadPageFunctions(ps As Peripherals) As Boolean
  On Error Resume Next
  OnLoadPageFunctions = False

  If (Not ps.AddPage("Functions")) Then Exit Function

  OnLoadPageFunctions = True
End Function

'*****************************************************************************
'Description:
'        This function is called from the OnChangingPage function of the
'        associated module in order load all controls for the requested page
'        if they are not already loaded.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'        Pagename         requested page name
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnChangingPageFunctions(ps As Peripherals, Pagename As String) As Boolean
  On Error Resume Next

  OnChangingPageFunctions = False

  Dim pos As Long

  If (Not ps.ExtenderCollection("Functions").Loaded) And (Pagename = "Functions") Then
    ps.ExtenderCollection("Functions").Loaded = True

    If (Not ps.AddFrame("fraT01_USE_Init", 100, 100, 4150, 700, "Initialization Function")) Then Exit Function
    If (Not ps.AddCheck("chkT01_USE_Init", 200, 270, 1000, 380, "T01_vInit")) Then Exit Function
    If (Not ps.AddText("txtT01_NAME_Init", 2150, 300, 1900, 315)) Then Exit Function

    If (Not ps.AddFrame("fraT01_CFile", 4400, 100, 4150, 700, "Source File")) Then Exit Function
    If (Not ps.AddText("txtT01_CFile", 1500, 300, 2550, 315)) Then Exit Function
    If (Not ps.AddLabel("lblT01_CFile", 0, 200, 300, 1575, 380, "File name")) Then Exit Function

    If (Not ps.AddFrame("fraLibrary1", 100, 900, 4150, 4400, "Function Library")) Then Exit Function
    pos = 0
    ' Functions and Macros
    If (Not ps.AddCheck("chkT01_USE_StartTmr", 200, 270 + pos * 300, 2100, 380, "T01_vStartTmr")) Then Exit Function
    If (Not ps.AddText("txtT01_NAME_StartTmr", 2150, 300 + pos * 300, 1900, 315)) Then Exit Function
    pos = pos + 1

    If (Not ps.AddCheck("chkT01_USE_StopTmr", 200, 270 + pos * 300, 2100, 380, "T01_vStopTmr")) Then Exit Function
    If (Not ps.AddText("txtT01_NAME_StopTmr", 2150, 300 + pos * 300, 1900, 315)) Then Exit Function
    pos = pos + 1

    If (Not ps.AddCheck("chkT01_USE_ClearTmr", 200, 270 + pos * 300, 2100, 380, "T01_vClearTmr")) Then Exit Function
    If (Not ps.AddText("txtT01_NAME_ClearTmr", 2150, 300 + pos * 300, 1900, 315)) Then Exit Function
    pos = pos + 1

    If (Not ps.AddCheck("chkT01_USE_ReadTmr", 200, 270 + pos * 300, 2100, 380, "T01_ReadTmr")) Then Exit Function
    If (Not ps.AddText("txtT01_NAME_ReadTmr", 2150, 300 + pos * 300, 1900, 315)) Then Exit Function
    pos = pos + 1

    If (Not ps.AddCheck("chkT01_USE_LoadTmr", 200, 270 + pos * 300, 2100, 380, "T01_vLoadTmr")) Then Exit Function
    If (Not ps.AddText("txtT01_NAME_LoadTmr", 2150, 300 + pos * 300, 1900, 315)) Then Exit Function
    pos = pos + 1

    If (Not ps.AddCheck("chkT01_USE_IsrTmr0", 200, 270 + pos * 300, 2100, 380, "T01_viTmr0")) Then Exit Function
    If (Not ps.AddText("txtT01_NAME_IsrTmr0", 2150, 300 + pos * 300, 1900, 315)) Then Exit Function
    pos = pos + 1

    If (Not ps.AddCheck("chkT01_USE_IsrTmr1", 200, 270 + pos * 300, 2100, 380, "T01_viTmr1")) Then Exit Function
    If (Not ps.AddText("txtT01_NAME_IsrTmr1", 2150, 300 + pos * 300, 1900, 315)) Then Exit Function
    pos = pos + 1

    If (Not ps.AddCheck("chkT01_USE_StartTmr1", 200, 270 + pos * 300, 2100, 380, "T01_vStartTmr1")) Then Exit Function
    If (Not ps.AddText("txtT01_NAME_StartTmr1", 2150, 300 + pos * 300, 1900, 315)) Then Exit Function
    pos = pos + 1

    If (Not ps.AddCheck("chkT01_USE_StopTmr1", 200, 270 + pos * 300, 2100, 380, "T01_vStopTmr1")) Then Exit Function
    If (Not ps.AddText("txtT01_NAME_StopTmr1", 2150, 300 + pos * 300, 1900, 315)) Then Exit Function
    pos = pos + 1

  End If

  OnChangingPageFunctions = True
End Function

'*****************************************************************************
'Description:
'        This function is called from the OnShow function of the associated
'        module. See the description for the OnShow function of the
'        associated module for details.
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Controlname     control name
'        Pagename        current page name
'        v()             value array
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnShowPageFunctions(ps As Peripherals, Controlname As String, Pagename As String, v() As Variant) As Boolean
  On Error GoTo OnShowError

  OnShowPageFunctions = False
    
  Dim r As ProjectData
  Dim c As Collection
  Dim e As Collection
  Dim bDisabled As Boolean
  Dim func As FunctionClass

  Set r = ps.ProjectData
  Set c = ps.ControlCollection
  Set e = ps.ExtenderCollection
  Set func = New FunctionClass

  If (Pagename = "Functions") Then
    '-------------------------------------------------------------------------
    ' page: Functions (action)
    '-------------------------------------------------------------------------
    Select Case Controlname
        Case "chkT01_USE_Init"
             r.v("T01_USE_Init") = v(1)
    
        Case "txtT01_NAME_Init"
             If (IsInputFormatOK(v(1), "N30", c("chkT01_USE_Init").Caption)) Then
                r.v("T01_NAME_Init") = v(1)
             Else
                Exit Function
             End If
    
        Case "txtT01_CFile"
             If (IsInputFormatOK(v(1), "S80", c("lblT01_CFile").Caption)) Then
                r.v("T01_CFile") = v(1)
             Else
                Exit Function
             End If
    
    End Select     ' case Controlname

    If (Not UpdateFunction(ps, Controlname, v, "StartTmr")) Then Exit Function
    If (Not UpdateFunction(ps, Controlname, v, "StopTmr")) Then Exit Function
    If (Not UpdateFunction(ps, Controlname, v, "ClearTmr")) Then Exit Function
    If (Not UpdateFunction(ps, Controlname, v, "ReadTmr")) Then Exit Function
    If (Not UpdateFunction(ps, Controlname, v, "LoadTmr")) Then Exit Function
    If (Not UpdateFunction(ps, Controlname, v, "IsrTmr0")) Then Exit Function
    If (Not UpdateFunction(ps, Controlname, v, "IsrTmr1")) Then Exit Function
    If (Not UpdateFunction(ps, Controlname, v, "StartTmr1")) Then Exit Function
    If (Not UpdateFunction(ps, Controlname, v, "StopTmr1")) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: Functions (show)
    '-------------------------------------------------------------------------
    RefreshFunctionDescriptions func, r

    '-------------------------------------------------------------------------
    ' control: chkT01_USE_Init (show)
    '-------------------------------------------------------------------------
    c("chkT01_USE_Init").Value = -CInt(r.v("T01_USE_Init") = 1)
    
    e("chkT01_USE_Init").EnabledTooltipText = FormatFunctionToolTip(r, func, "T01_NAME_Init")

    '-------------------------------------------------------------------------
    ' control: txtT01_NAME_Init (show)
    '-------------------------------------------------------------------------
    ' action on showing the control
    With c("txtT01_NAME_Init")
        bDisabled = r.v("T01_USE_Init") = 0
        .Enabled = Not bDisabled
        .Text = FormatTextOutput(r.s("T01_NAME_Init"), "S")
    End With

    With e("txtT01_NAME_Init")
        If (bDisabled) Then
            .DisabledToolTipText = FormatNormalToolTip(TOOLTIP_DISABLED_FUNC_NAME)
        End If
    End With

    If (Not ShowFunction(ps, v, func, "StartTmr")) Then Exit Function
    If (Not ShowFunction(ps, v, func, "StopTmr")) Then Exit Function
    If (Not ShowFunction(ps, v, func, "ClearTmr")) Then Exit Function
    If (Not ShowFunction(ps, v, func, "ReadTmr")) Then Exit Function
    If (Not ShowFunction(ps, v, func, "LoadTmr")) Then Exit Function
    If (Not ShowFunction(ps, v, func, "IsrTmr0")) Then Exit Function
    If (Not ShowFunction(ps, v, func, "IsrTmr1")) Then Exit Function
    If (Not ShowFunction(ps, v, func, "StartTmr1")) Then Exit Function
    If (Not ShowFunction(ps, v, func, "StopTmr1")) Then Exit Function

    '-------------------------------------------------------------------------
    ' control: lblT01_CFile (show)
    '-------------------------------------------------------------------------
    With c("lblT01_CFile")
        bDisabled = r.v("T01_USE_Init") = 0
        .Enabled = Not bDisabled
    End With

    With e("lblT01_CFile")
        If (bDisabled) Then
            .DisabledToolTipText = FormatNormalToolTip(TOOLTIP_DISABLED_CFILE_NAME)
        End If
    End With

    '-------------------------------------------------------------------------
    ' control: txtT01_CFile (show)
    '-------------------------------------------------------------------------
    With c("txtT01_CFile")
      bDisabled = (r.v("T01_USE_Init") = 0)
      .Enabled = Not bDisabled
      .Text = FormatTextOutput(r.v("T01_CFile"), "S")
    End With

    With e("txtT01_CFile")
        If (bDisabled) Then
            .DisabledToolTipText = FormatNormalToolTip(TOOLTIP_DISABLED_CFILE_NAME)
        End If
    End With

  End If         ' if Pagename

  OnShowPageFunctions = True
  Exit Function

OnShowError:
    Errorbox "Can not show page", Err.Description
End Function

Public Function OnLoadPageParameters(ps As Peripherals) As Boolean
  On Error Resume Next
  OnLoadPageParameters = False

  If (Not ps.AddPage("Parameters")) Then Exit Function

  OnLoadPageParameters = True
End Function

'*****************************************************************************
'Description:
'        This function is called from the OnChangingPage function of the
'        associated module in order load all controls for the requested page
'        if they are not already loaded.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'        Pagename         requested page name
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnChangingPageParameters(ps As Peripherals, Pagename As String) As Boolean
  On Error Resume Next

  Dim iPar As Integer
  Dim sName As String

  OnChangingPageParameters = False

  If (Not ps.ExtenderCollection("Parameters").Loaded) And (Pagename = "Parameters") Then
    ps.ExtenderCollection("Parameters").Loaded = True

    If (Not ps.AddFrame("fraT01_HFile", 100, 100, 8450, 700, "Header File")) Then Exit Function
    If (Not ps.AddText("txtT01_HFile", 1825, 250, 5000, 315)) Then Exit Function
    If (Not ps.AddLabel("lblT01_HFile", 0, 200, 300, 1575, 380, "File name")) Then Exit Function

    If (Not ps.AddFrame("fraParameters1", 100, 900, 4150, 4400, "Parameters")) Then Exit Function
    ' Functions and Macros
    
    For iPar = 0 To NUMBER_OF_T01_PARAMETERS - 1
        sName = T01ParId(iPar)
        If (Not ps.AddLabel("lblPar_" & sName, 0, 200, 370 + iPar * 300, 1575, 380, sName)) Then Exit Function
        If (Not ps.AddText("txtPar_" & sName, 1825, 300 + iPar * 300, 1900, 315)) Then Exit Function
    Next iPar

    
  End If

  OnChangingPageParameters = True
End Function

'*****************************************************************************
'Description:
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the Project Data Object
'        Controlname     control name
'        v()             value array
'        sName           function keyword
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Function UpdateFunction(ps As Peripherals, Controlname As String, v() As Variant, sName As String) As Boolean
  On Error GoTo ExitLabel
  UpdateFunction = False

  Dim r As ProjectData
  Dim c As Collection

  Set r = ps.ProjectData
  Set c = ps.ControlCollection

  '---------------------------------------------------------------------
  ' control: chkT01_USE_.. (action)
  '---------------------------------------------------------------------
  If (Controlname = "chkT01_USE_" & sName) Then
    r.v("T01_USE_" & sName) = v(1)
  End If

  '---------------------------------------------------------------------
  ' control: txtT01_NAME_.. (action)
  '---------------------------------------------------------------------
  If (Controlname = "txtT01_NAME_" & sName) Then
    If (IsInputFormatOK(v(1), "N30", c("chkT01_USE_" & sName).Caption)) Then
        r.v("T01_NAME_" & sName) = v(1)
    End If
  End If

  UpdateFunction = True
  
  Exit Function
  
ExitLabel:
Errorbox "error in Update function", Err.Description
End Function


'*****************************************************************************
'Description:
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        v()             value array
'        func            reference to the function object
'        sName           function keyword
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Function ShowFunction(ps As Peripherals, v() As Variant, func As FunctionClass, sName As String) As Boolean
  On Error GoTo ExitLabel
  ShowFunction = False

  Dim r As ProjectData
  Dim c As Collection
  Dim e As Collection
  Dim bDisabled As Boolean

  Set r = ps.ProjectData
  Set c = ps.ControlCollection
  Set e = ps.ExtenderCollection

  '-------------------------------------------------------------------------
  ' control: chkT01_USE_.. (show)
  '-------------------------------------------------------------------------
  ' action on showing the control
  With c("chkT01_USE_" & sName)
    ' disable condition
    Select Case sName

        Case "IsrTmr0", "IsrTmr1"      ' ISR functions are always disabled
            bDisabled = True

        Case "StartTmr1", "StopTmr1"
            bDisabled = (r.v("T01_USE_Init") = 0) Or (GetTimer0Mode(r) <> 3)

        Case Else
            bDisabled = (r.v("T01_USE_Init") = 0)

    End Select

    .Enabled = Not bDisabled
    .Value = -CInt((r.v("T01_USE_Init") = 1) And (r.v("T01_USE_" & sName) = 1))
  End With

  With e("chkT01_USE_" & sName)
    If (bDisabled) Then
        ' tooltip if control is disabled
        Select Case sName

            Case "IsrTmr0", "IsrTmr1"      ' ISR functions are always disabled
                    .DisabledToolTipText = TOOLTIP_DISABLED_ISR & vbCrLf & FormatFunctionToolTip(r, func, "T01_NAME_" & sName)

            Case "StartTmr1", "StopTmr1"
                .DisabledToolTipText = GetDisabledFunctionTooltipEntry(func, "T01_NAME_" & sName)
                If (r.v("T01_USE_Init") = 0) Then
                    .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
                End If
                If (GetTimer0Mode(r) <> 3) Then
                    .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("Timer 0 is not in mode 3")
                End If

            Case Else
                .DisabledToolTipText = GetDisabledFunctionTooltipEntry(func, "T01_NAME_" & sName)
                .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)

        End Select
    Else
        ' tooltip if control is enabled
        .EnabledTooltipText = FormatFunctionToolTip(r, func, "T01_NAME_" & sName)
    End If
  End With

  '-------------------------------------------------------------------------
  ' control: txtT01_NAME_... (show)
  '-------------------------------------------------------------------------
  With c("txtT01_NAME_" & sName)
    bDisabled = c("chkT01_USE_" & sName).Value = 0
    .Enabled = Not bDisabled
    .Text = FormatTextOutput(r.s("T01_NAME_" & sName), "S")
  End With

  With e("txtT01_NAME_" & sName)
    If (bDisabled) Then
        .DisabledToolTipText = FormatNormalToolTip(TOOLTIP_DISABLED_FUNC_NAME)
    End If
  End With

  ShowFunction = True
  
  Exit Function
  
ExitLabel:
Errorbox "error in Show function", Err.Description
End Function

'*****************************************************************************
'Description:
'        This function is called from the OnShow function of the associated
'        module. See the description for the OnShow function of the
'        associated module for details.
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Controlname     control name
'        Pagename        current page name
'        v()             value array
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnShowPageParameters(ps As Peripherals, Controlname As String, Pagename As String, v() As Variant) As Boolean
  On Error GoTo OnShowError

  OnShowPageParameters = False
    
  Dim r As ProjectData
  Dim c As Collection
  Dim e As Collection
  Dim bDisabled As Boolean
  Dim sName As String
  Dim iPar As Integer

  Set r = ps.ProjectData
  Set c = ps.ControlCollection
  Set e = ps.ExtenderCollection


  If (Pagename = "Parameters") Then
    '-------------------------------------------------------------------------
    ' page: Parameters (action)
    '-------------------------------------------------------------------------
    Select Case Controlname
        Case "txtT01_HFile"
            If (IsInputFormatOK(v(1), "S1000", c("lblT01_HFile").Caption)) Then
                r.v("T01_HFile") = v(1)
            Else
                Exit Function
            End If

        Case Else
            For iPar = 0 To NUMBER_OF_T01_PARAMETERS - 1
                sName = T01ParId(iPar)
                If (Controlname = "txtPar_" & sName) Then
                    If (IsInputFormatOK(v(1), "N30", c("lblPar_" & sName).Caption)) Then
                        r.v("T01_PARA_" & sName) = v(1)
                        Else
                            Exit Function
                        End If
                End If
            Next iPar
    End Select

    '-------------------------------------------------------------------------
    ' page: Parameters (show)
    '-------------------------------------------------------------------------
    With c("lblT01_HFile")
        bDisabled = (r.v("T01_USE_Init") = 0)
        .Enabled = Not bDisabled
    End With
    With e("lblT01_HFile")
        If (bDisabled) Then
            .DisabledToolTipText = FormatNormalToolTip(TOOLTIP_DISABLED_HFILE_NAME)
        End If
    End With

    With c("txtT01_HFile")
        bDisabled = (r.v("T01_USE_Init") = 0)
        .Enabled = Not bDisabled
        .Text = FormatTextOutput(r.v("T01_HFile"), "S")
    End With
    With e("txtT01_HFile")
        If (bDisabled) Then
            .DisabledToolTipText = FormatNormalToolTip(TOOLTIP_DISABLED_HFILE_NAME)
        End If
    End With

    For iPar = 0 To NUMBER_OF_T01_PARAMETERS - 1
        sName = T01ParId(iPar)
        With c("txtPar_" & sName)
            bDisabled = (r.v("T01_USE_Init") = 0)
            .Enabled = Not bDisabled
            .Text = FormatTextOutput(r.v("T01_PARA_" & sName), "S")
        End With
        With e("txtPar_" & sName)
            If (bDisabled) Then
                .DisabledToolTipText = TOOLTIP_DISABLED_PARAMETER
                .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
            End If
        End With
        With c("lblPar_" & sName)
            .Enabled = Not bDisabled
        End With
    Next iPar

  End If         ' if Pagename

  OnShowPageParameters = True
  Exit Function

OnShowError:
    Errorbox "Can not show page", Err.Description

End Function


