Attribute VB_Name = "Module1"
'#Uses "..\classes\FunctionClass.cls"
'#Uses "..\classes\ParameterClass.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:
'        CAPCOMx
'-----------------------------------------------------------------------------
' Description:
'        This file contains functions which are create controls for the
'        module 'CAPCOMx'.
'        Furthermore it contains functions for the event handling of
'        these controls.
'
'-----------------------------------------------------------------------------
' History:
'
'        Rev. Author         Date        Description
'        ---------------------------------------------------------------------
'        1.0   ahe         05.01.01     final version for S-Gold
'
'        ---------------------------------------------------------------------
'        3.0   ahe         02.05.01     final version for Pegasus
'
'        3.1   ahe         08.08.02     - neu interrupt pages
'        3.2   ste         18.12.02     spelling correction
'                          22.01.03     bits PDS and ORSEL deleted
'        3.3   ste         24.02.03     caption for module clock changed
'
'        ---------------------------------------------------------------------
'        5.0  ahe          26.08.04     final version for XC164CM Pegasus light
'
'*****************************************************************************
Dim CHANNELx As Peripherals


'*****************************************************************************
'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

    '-------------------------------------------------------------------------
    ' page: ModuleClock
    '-------------------------------------------------------------------------
    If (Not OnLoadPageModuleClock(ps)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: Control
    '-------------------------------------------------------------------------
    If (Not OnLoadPageControl(ps)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: Timer_x_y
    '-------------------------------------------------------------------------
    If (Not OnLoadPageTimer_x_y(ps)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: Channels
    '-------------------------------------------------------------------------
    If (Not OnLoadPageChannels(ps)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: Interrupts
    '-------------------------------------------------------------------------
    If (Not OnLoadPageInterrupts_32(ps, 0)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: Interrupts
    '-------------------------------------------------------------------------
    If (Not OnLoadPageInterrupts_32(ps, 1)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: PEC
    '-------------------------------------------------------------------------
    If (Not OnLoadPagePEC(ps)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: Functions
    '-------------------------------------------------------------------------
    If (Not OnLoadPageFunctions(ps)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: Parameters
    '-------------------------------------------------------------------------
    If (Not OnLoadPageParameters(ps)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: Notes
    '-------------------------------------------------------------------------
    If (Not OnLoadPageNotes(ps)) Then Exit Function

    '-------------------------------------------------------------------------
    ' end of pages
    '-------------------------------------------------------------------------
    
    '-------------------------------------------------------------------------
    ' call function to initialize the menu
    '-------------------------------------------------------------------------
    If (Not InitMenu(ps, "CCx\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
    Dim sVarPre As String
    Dim vIndex  As Variant

    vIndex = ps.Parameters.v("x")
    sVarPre = "CC" & vIndex

    
    '-------------------------------------------------------------------------
    'page: ModuleClock
    '-------------------------------------------------------------------------
    If (Not OnChangingPageModuleClock(ps, Pagename)) Then Exit Function

    '-------------------------------------------------------------------------
    'page: Timer_x_y
    '-------------------------------------------------------------------------
    If (Not OnChangingPageTimer_x_y(ps, Pagename)) Then Exit Function

    '-------------------------------------------------------------------------
    'page: Control
    '-------------------------------------------------------------------------
    If (Not OnChangingPageControl(ps, Pagename)) Then Exit Function

    '-------------------------------------------------------------------------
    'page: Channels
    '-------------------------------------------------------------------------
    If (Not OnChangingPageChannels(ps, Pagename)) Then Exit Function

    '-------------------------------------------------------------------------
    'page: Interrupts
    '-------------------------------------------------------------------------
    If (Not OnChangingPageInterrupts_32(ps, Pagename, 0)) Then Exit Function

    '-------------------------------------------------------------------------
    'page: Interrupts
    '-------------------------------------------------------------------------
    If (Not OnChangingPageInterrupts_32(ps, Pagename, 1)) Then Exit Function

    '-------------------------------------------------------------------------
    'page: PEC
    '-------------------------------------------------------------------------
    If (Not OnChangingPagePEC(ps, Pagename)) Then Exit Function

    '-------------------------------------------------------------------------
    'page: Functions
    '-------------------------------------------------------------------------
    If (Not OnChangingPageFunctions(ps, Pagename)) Then Exit Function

    '-------------------------------------------------------------------------
    'page: Parameters
    '-------------------------------------------------------------------------
    If (Not OnChangingPageParameters(ps, Pagename)) Then Exit Function

    '-------------------------------------------------------------------------
    'page: Notes
    '-------------------------------------------------------------------------
    If (Not OnChangingPageNotes(ps, Pagename, sVarPre)) 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 GoTo OnShowError

    OnShow = False
    
    Dim sVarPre As String
    Dim vIndex  As Variant

    vIndex = ps.Parameters.v("x")
    sVarPre = "CC" & vIndex


    '-------------------------------------------------------------------------
    ' page: ModuleClock
    '-------------------------------------------------------------------------
    If (Not OnShowPageModuleClock(ps, Controlname, Pagename, v)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: Control
    '-------------------------------------------------------------------------
    If (Not OnShowPageControl(ps, Controlname, Pagename, v)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: Timer_x_y
    '-------------------------------------------------------------------------
    If (Not OnShowPageTimer_x_y(ps, Controlname, Pagename, v)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: Channels
    '-------------------------------------------------------------------------
    If (Not OnShowPageChannels(ps, Controlname, Pagename, v)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: Interrupts
    '-------------------------------------------------------------------------
    If (Not OnShowPageInterrupts_32(ps, Controlname, v, sVarPre, Pagename, 0)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: Interrupts
    '-------------------------------------------------------------------------
    If (Not OnShowPageInterrupts_32(ps, Controlname, v, sVarPre, Pagename, 1)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: PEC
    '-------------------------------------------------------------------------
    If (Not OnShowPagePEC(ps, Controlname, v, Pagename)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: Functions
    '-------------------------------------------------------------------------
    If (Not OnShowPageFunctions(ps, Controlname, Pagename, v)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: Parameters
    '-------------------------------------------------------------------------
    If (Not OnShowPageParameters(ps, Controlname, Pagename, v)) Then Exit Function
       
    '-------------------------------------------------------------------------
    ' page: Notes
    '-------------------------------------------------------------------------
    If (Not OnShowPageNotes(ps, Controlname, Pagename, sVarPre, v)) Then Exit Function


    OnShow = True
    Exit Function

OnShowError:
    errorbox "Can not show page.", Err.Description
    Exit Function
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

    Dim np As Peripherals

    '-------------------------------------------------------------------------
    ' buttons: PEC
    '-------------------------------------------------------------------------
    If (Not OnClickPagePEC(ps, Controlname)) Then Exit Function

    '-------------------------------------------------------------------------
    ' buttons: Channel
    '-------------------------------------------------------------------------
    If (Not OnButtonClickOnPageChannels(ps, Controlname)) Then Exit Function

  

    OnClick = True
    Exit Function

OnClickError:
    errorbox "Can not Text in OnClick.", 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, "CCx\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 the page 'ModuleClock'.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnLoadPageModuleClock(ps As Object) As Boolean
  On Error Resume Next

  OnLoadPageModuleClock = False

  If (Not ps.AddPage("Module Clock")) Then Exit Function

  OnLoadPageModuleClock = 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
'*****************************************************************************
Function OnChangingPageModuleClock(ps As Object, Pagename As String) As Boolean
  On Error Resume Next

  OnChangingPageModuleClock = False
  Dim sVarPre As String
  Dim vIndex  As Variant
  Dim r       As ProjectData

  vIndex = ps.Parameters.v("x")
  sVarPre = "CAPCOM" & vIndex
  
  Set r = ps.ProjectData

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

    '-------------------------------
    ' frame: frmMD
    '-------------------------------
    If (Not ps.AddFrame("frmMD", 100, 100, 5400, 1375, sVarPre & " Disabled Flag (CC" & vIndex & "DIS)")) Then Exit Function
        If (Not ps.AddOption("optDISx_0", 200, 350, 4800, 300, "Enable module; the peripheral is supplied with the clock signal")) Then Exit Function
        If (Not ps.AddOption("optDISx_1", 200, 825, 4800, 300, "Disable module; the clock input of peripheral is disabled")) Then Exit Function

    '-------------------------------
    ' frame: frmInputClock
    '-------------------------------
    If (Not ps.AddFrame("frmInputClock", 100, 1600, 5400, 1000, "Input Clock")) Then Exit Function
        If (Not ps.AddLabel("lbl_txt_InputClock", 0, 200, 450, 3225, 300, "Input clock of the " & sVarPre & " module [MHz]")) Then Exit Function
        If (Not ps.AddLabel("lbl_box_InputClock", 1, 3550, 400, 1000, 300, "")) Then Exit Function

  End If
  OnChangingPageModuleClock = 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 OnShowPageModuleClock(ps As Object, Controlname As String, Pagename As String, v() As Variant) As Boolean
  On Error GoTo OnShowPageModuleClockError

  OnShowPageModuleClock = False

  Dim r         As ProjectData
  Dim c         As Object
  Dim e         As Object
  Dim bDisabled As Boolean
  Dim sVarPre   As String
  Dim vIndex    As Variant
  Dim sRegPre   As String
  Dim i         As Integer
  Dim iTmr_x    As Integer
  Dim iTmr_y    As Integer
  Dim iTmr      As Integer
  Dim iCh_low   As Integer
  Dim iCh_high  As Integer
  Dim iChannel  As Integer
  Dim lRegPre   As Long
  Dim iCh_Group As Integer


  vIndex = ps.Parameters.v("x")
  sVarPre = "CC" & vIndex
  sRegPre = sVarPre & "_"
 
  If (vIndex = 1) Then
      iCh_low = 0
      iCh_high = 7 + CH_HIGH
      iTmr_x = 0
      iTmr_y = 1
  Else
      iCh_low = 16
      iCh_high = 23 + CH_HIGH
      iTmr_x = 7
      iTmr_y = 8
  End If

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

  If (Pagename = "Module Clock") Then
    '-------------------------------------------------------------------------
    ' page: ModuleClock (action)
    '-------------------------------------------------------------------------
    Select Case (Controlname)
        '---------------------------------------------------------------------
        ' control: optDISx_0 (action)
        '---------------------------------------------------------------------
        Case "optDISx_0"
            r.v("SYSCON3_CC" & vIndex & "DIS") = 0

        '---------------------------------------------------------------------
        ' control: optDISx_1 (action)
        '---------------------------------------------------------------------
        Case "optDISx_1"
            r.v("SYSCON3_CC" & vIndex & "DIS") = 1
            
            '------------------------------------------------------- set TxyCON to 0
            r.sfr(sRegPre & "T" & iTmr_x & iTmr_y & "CON") = 0
            r.sfr(sRegPre & "IOC") = 1

            '------------------------------------------------------- reset pins
            If (GetPinFunction(r, sVarPre & "_T" & iTmr_x & "IN") <> 0) Then
                Call ReleaseAlternateInputPin(r, sVarPre & "_T" & iTmr_x & "IN")
            End If

            '------------------------------------------------------- reset ISR's
            Call DisableSRN(r, sVarPre, sRegPre & "T" & iTmr_x & "IC", "Tmr" & iTmr_x)
            Call DisableSRN(r, sVarPre, sRegPre & "T" & iTmr_y & "IC", "Tmr" & iTmr_y)

            '------------------------------------------------------- reset vInit
            r.v(sVarPre & "_USE_Init") = 0

            '------------------------------------------------------- reset channelx
            For iChannel = iCh_low To iCh_high
                lRegPre = iChannel \ 4

                If (iChannel < (iCh_high - 7)) Then
                    iCh_Group = 1
                Else
                    iCh_Group = 2
                End If

                If (r.v(sRegPre & "M" & lRegPre & "_MOD" & iChannel) <> 0) Then
                    Call SetChannelxToDefault(r, vIndex, iCh_Group, iChannel)
                End If

            Next iChannel


      Case Else
    End Select

    '-------------------------------------------------------------------------
    ' page: ModuleClock (show)
    '-------------------------------------------------------------------------

    '-------------------------------------------------------------------------
    ' control: optDISx_0 (show)
    '-------------------------------------------------------------------------
    With c("optDISx_0")
      bDisabled = False
      .Enabled = Not (bDisabled)
      .Value = -CInt(r.v("SYSCON3_CC" & vIndex & "DIS") = 0)
    End With

    With e("optDISx_0")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip("")
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: optDISx_1 (show)
    '-------------------------------------------------------------------------
    With c("optDISx_1")
      bDisabled = False
      .Enabled = Not (bDisabled)
      .Value = -CInt(r.v("SYSCON3_CC" & vIndex & "DIS") = 1)
    End With

    With e("optDISx_1")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip("")
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: lbl_txt_InputClock (show)
    '-------------------------------------------------------------------------
    With c("lbl_txt_InputClock")
      bDisabled = (IsModuleClockDisabled(r, vIndex))
      .Enabled = Not (bDisabled)
    End With

    With e("lbl_txt_InputClock")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (IsModuleClockDisabled(r, vIndex)) Then
          .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleClockDisabled(r, vIndex)
        End If
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: lbl_box_InputClock (show)
    '-------------------------------------------------------------------------
    With c("lbl_box_InputClock")
      bDisabled = (IsModuleClockDisabled(r, vIndex))
      .Enabled = Not (bDisabled)
      If (GetCAPCOMModuleClock(r, vIndex) > GetMaxSystemClock(r)) Then
          .Caption = TO_HIGH
      Else
          .Caption = GetCAPCOMModuleClock(r, vIndex)
      End If

    End With

    With e("lbl_box_InputClock")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (IsModuleClockDisabled(r, vIndex)) Then
          .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleClockDisabled(r, vIndex)
        End If
      End If
    End With


  End If

  OnShowPageModuleClock = True
  Exit Function

OnShowPageModuleClockError:
  errorbox "Can not show page", Err.Description
  Exit Function
End Function

'*****************************************************************************
'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 OnLoadPageControl(ps As Object) As Boolean
  On Error Resume Next

  OnLoadPageControl = False

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

  OnLoadPageControl = 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
'*****************************************************************************
Function OnChangingPageControl(ps As Object, Pagename As String) As Boolean
  On Error Resume Next

  OnChangingPageControl = False

  Dim vIndex As Variant
  Dim sIndex As String

  vIndex = ps.Parameters.v("x")
  sIndex = "CAPCOM" & vIndex
  
  If (Not ps.ExtenderCollection("Control").Loaded) And (Pagename = "Control") Then
    ps.ExtenderCollection("Control").Loaded = True
  
    '-------------------------------
    ' frame: frmCCxORSEL
    '-------------------------------
'    If (Not ps.AddFrame("frmCCxORSEL",100,100, 5800, 1200, _
'      "Output Register Select (ORSEL)")) Then Exit Function
'        If (Not ps.AddOption("optCCxORSEL_0", 150, 250, 5500, 400, _
'          "The contents of the port register is visible at output port")) Then Exit Function
'        If (Not ps.AddOption("optCCxORSEL_1", 150, 650, 5500, 400, _
'          "The contents of the CC" & vIndex & "_OUT register is visible at output port")) Then Exit Function

    '-------------------------------
    ' frame: frmCCxPL
    '-------------------------------
    If (Not ps.AddFrame("frmCCxPL", 100, 100, 5800, 1200, "Port Lock Control (PL)")) Then Exit Function
        If (Not ps.AddOption("optCCxPL_0", 150, 250, 5500, 400, "The contents of the port register is changed by the CAPCOM" & vIndex & " unit")) Then Exit Function
        If (Not ps.AddOption("optCCxPL_1", 150, 650, 5500, 400, "The contents of the port register is not changed by the CAPCOM" & vIndex & " unit")) Then Exit Function

    '-------------------------------
    ' frame: frmCCxSTAG
    '-------------------------------
    If (Not ps.AddFrame("frmCCxSTAG", 100, 1400, 5800, 800, "Stagger Control")) Then Exit Function
        If (Not ps.AddCheck("chkCCxSTAG", 150, 250, 5500, 400, "Disable staggered mode (STAG)")) Then Exit Function

  End If
  OnChangingPageControl = 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 OnShowPageControl(ps As Object, Controlname As String, Pagename As String, v() As Variant) As Boolean
  On Error GoTo OnShowPageControlError

  OnShowPageControl = False

  Dim r             As ProjectData
  Dim c             As Object
  Dim e             As Object
  Dim bDisabled     As Boolean
  Dim vIndex        As Variant
  Dim sRegPre       As String
  Dim sVarPre       As String
  Dim sCCx          As String
  Dim i             As Integer
  Dim dSystemClock  As Double

  vIndex = ps.Parameters.v("x")
  sVarPre = "CC" & vIndex
  sRegPre = sVarPre & "_"

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

  If (Pagename = "Control") Then
    '-------------------------------------------------------------------------
    ' page: ModuleClock (action)
    '-------------------------------------------------------------------------
    Select Case (Controlname)
        '---------------------------------------------------------------------
        ' control: optCCxORSEL_0 (action)
        '---------------------------------------------------------------------
'        Case "optCCxORSEL_0"
'             r.v(sRegPre & "IOC_ORSEL") = 0
'             r.v(sRegPre & "IOC_STAG") = 0
'             r.v(sVarPre & "_USE_SetCCxOUT") = 0
'             r.v(sVarPre & "_USE_ResetCCxOUT") = 0
'             r.v(sVarPre & "_USE_GetCCxOUT") = 0
'             r.v(sVarPre & "_USE_SetPortDirectionOutput") = 0
'             r.v(sVarPre & "_USE_SetPortDirectionInput") = 0
'
'        '---------------------------------------------------------------------
'        ' control: optCCxORSEL_1 (action)
'        '---------------------------------------------------------------------
'        Case "optCCxORSEL_1"
'             r.v(sRegPre & "IOC_ORSEL") = 1
'             r.v(sRegPre & "IOC_PL") = 0
'             r.v(sVarPre & "_USE_PortLock") = 0
'             r.v(sVarPre & "_USE_PortUnlock") = 0

        '---------------------------------------------------------------------
        ' control: OPTCCxPL_0 (action)
        '---------------------------------------------------------------------
        Case "optCCxPL_0"
             r.v(sRegPre & "IOC_PL") = 0
  
        '---------------------------------------------------------------------
        ' control: optCCxPL_1 (action)
        '---------------------------------------------------------------------
        Case "optCCxPL_1"
             r.v(sRegPre & "IOC_PL") = 1
  
        '---------------------------------------------------------------------
        ' control: chkCCxSTAG (action)
        '---------------------------------------------------------------------
        Case "chkCCxSTAG"
             r.v(sRegPre & "IOC_STAG") = v(1)
  
  
      Case Else
    End Select
  
    '-------------------------------------------------------------------------
    ' page: ModuleClock (show)
    '-------------------------------------------------------------------------
  
    '-------------------------------------------------------------------------
    ' control: optCCxORSEL_0 (show)
    '-------------------------------------------------------------------------
'    For i = 0 To 1
'        With c("optCCxORSEL_" & i)
'          bDisabled = IsModuleClockDisabled(r, vIndex)
'          .Enabled = Not(bDisabled)
'          ' show condition
'          .Value = -CInt(r.v(sRegPre & "IOC_ORSEL") = i)
'        End With
'
'        With e("optCCxORSEL_" & i)
'          If (bDisabled) Then
'            ' tooltip if control is disabled
'            .DisabledTooltipText = TOOLTIP_DISABLED_IF
'            .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleClockDisabled(r, vIndex)
'          Else
'            ' tooltip if control is enabled
'          End If
'        End With
'    Next i
  
    '-------------------------------------------------------------------------
    ' control: optCCxPL_0 (show)
    '-------------------------------------------------------------------------
    For i = 0 To 1
        With c("optCCxPL_" & i)
          bDisabled = IsModuleClockDisabled(r, vIndex)
          .Enabled = Not (bDisabled)
          ' show condition
          .Value = -CInt(r.v(sRegPre & "IOC_PL") = i)
        End With
      
        With e("optCCxPL_" & i)
          If (bDisabled) Then
              ' tooltip if control is disabled
              .DisabledTooltipText = TOOLTIP_DISABLED_IF
              If (IsModuleClockDisabled(r, vIndex)) Then
                  .DisabledTooltipText = .DisabledTooltipText & _
                    GetTooltipModuleClockDisabled(r, vIndex)
              End If
          Else
            ' tooltip if control is enabled
          End If
        End With
    Next i
  
    '-------------------------------------------------------------------------
    ' control: chkCCxSTAG (show)
    '-------------------------------------------------------------------------
    With c("chkCCxSTAG")
      bDisabled = IsModuleClockDisabled(r, vIndex)
      .Enabled = Not (bDisabled)
      ' show condition
      .Value = -CInt(r.v(sRegPre & "IOC_STAG") = 1)
    End With
  
    With e("chkCCxSTAG")
      If (bDisabled) Then
              ' tooltip if control is disabled
              .DisabledTooltipText = TOOLTIP_DISABLED_IF
              If (IsModuleClockDisabled(r, vIndex)) Then
                  .DisabledTooltipText = .DisabledTooltipText & _
                    GetTooltipModuleClockDisabled(r, vIndex)
              End If
      Else
        ' tooltip if control is enabled
      End If
    End With
  
  End If

  OnShowPageControl = True
  Exit Function

OnShowPageControlError:
  errorbox "Can not show page", Err.Description
  Exit Function
End Function


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

  OnLoadPageTimer_x_y = False
  Dim iTmr_x  As Integer
  Dim iTmr_y  As Integer
  Dim vIndex  As Variant

  vIndex = ps.Parameters.v("x")
  If (vIndex = 1) Then
      iTmr_x = 0
      iTmr_y = 1
  Else
      iTmr_x = 7
      iTmr_y = 8
  End If


  If (Not ps.AddPage("Timer " & iTmr_x & "/" & iTmr_y)) Then Exit Function

  OnLoadPageTimer_x_y = 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
'*****************************************************************************
Function OnChangingPageTimer_x_y(ps As Object, Pagename As String) As Boolean
  On Error Resume Next

  OnChangingPageTimer_x_y = False
  Dim iTmr_x  As Integer
  Dim iTmr_y  As Integer
  Dim vIndex  As Variant
  Dim sCCx    As String
  Dim sRegPre As String

  vIndex = ps.Parameters.v("x")
  If (vIndex = 1) Then
      iTmr_x = 0
      iTmr_y = 1
  Else
      iTmr_x = 7
      iTmr_y = 8
  End If

  sCCx = "CC" & vIndex
  sRegPre = "CC" & vIndex & "_"
  
  
  If (Not ps.ExtenderCollection("Timer " & iTmr_x & "/" & iTmr_y).Loaded) And _
       (Pagename = "Timer " & iTmr_x & "/" & iTmr_y) Then
    ps.ExtenderCollection("Timer " & iTmr_x & "/" & iTmr_y).Loaded = True
  

    '-------------------------------
    ' frame: frmTxM
    '-------------------------------
    If (Not ps.AddFrame("frmT" & iTmr_x & "M", 100, 100, 2825, 900, _
        "Timer " & iTmr_x & " Mode (T" & iTmr_x & "M)")) Then Exit Function
        If (Not ps.AddOption("optT" & iTmr_x & "M_0", 200, 225, 1900, 300, _
            "Timer mode")) Then Exit Function
        If (Not ps.AddOption("optT" & iTmr_x & "M_1", 200, 550, 1900, 300, _
            "Counter mode")) Then Exit Function

    '-------------------------------
    ' frame: frmTxI
    '-------------------------------
    If (Not ps.AddFrame("frmT" & iTmr_x & "I", 3050, 100, 5550, 900, _
        "Timer " & iTmr_x & " Input Selection (T" & iTmr_x & "I)")) Then Exit Function
        If (Not ps.AddCombo("cboT" & iTmr_x & "I", 1525, 350, 3875, 315)) Then Exit Function
        If (Not ps.AddLabel("lblT" & iTmr_x & "I", 0, 200, 400, 1225, 330, _
            "Edge selection")) Then Exit Function

    '-------------------------------
    ' frame: frmTxR
    '-------------------------------
    If (Not ps.AddFrame("frmT" & iTmr_x & "R", 100, 1050, 2825, 800, _
        "Timer " & iTmr_x & " Start Control")) Then Exit Function
        If (Not ps.AddCheck("chkT" & iTmr_x & "R", 200, 250, 2525, 375, _
            "Start T" & iTmr_x & " after initialization (T" & iTmr_x & "R)")) Then Exit Function

    '-------------------------------
    ' frame: frmTxIE
    '-------------------------------
    If (Not ps.AddFrame("frmT" & iTmr_x & "IE", 100, 1900, 2825, 800, _
        "Interrupt Control")) Then Exit Function
        If (Not ps.AddCheck("chkT" & iTmr_x & "IE", 200, 300, 2500, 300, _
            "Enable T" & iTmr_x & " interrupt (IE)")) Then Exit Function

    '-------------------------------
    ' frame: frmTimReg_x
    '-------------------------------
    If (Not ps.AddFrame("frmTimReg_" & iTmr_x & "", 3050, 1050, 5550, 1650, _
        "Timer " & iTmr_x & " Registers")) Then Exit Function
        If (Not ps.AddLabel("lblOverflow_" & iTmr_x & "", 0, 200, 400, 1125, 305, _
            "Overflow [xxs]")) Then Exit Function
        If (Not ps.AddText("txtOverflow_" & iTmr_x & "", 1425, 350, 1100, 300)) Then Exit Function
        If (Not ps.AddText("txtT" & iTmr_x & "REL", 4400, 350, 1000, 300)) Then Exit Function
        If (Not ps.AddLabel("lblT" & iTmr_x & "REL", 0, 2700, 300, 1600, 380, _
            "Timer " & iTmr_x & " reload register (" & sRegPre & "T" & iTmr_x & "REL)")) Then Exit Function
        If (Not ps.AddText("txtT" & iTmr_x & "", 4400, 1000, 1000, 315)) Then Exit Function
        If (Not ps.AddLabel("lblT" & iTmr_x & "", 0, 2700, 950, 1575, 380, _
            "Timer " & iTmr_x & " register (" & sRegPre & "T" & iTmr_x & ")")) Then Exit Function

    '-------------------------------
    ' frame: frmTyM
    '-------------------------------
    If (Not ps.AddFrame("frmT" & iTmr_y & "M", 100, 2750, 2825, 900, _
        "Timer " & iTmr_y & " Mode (T" & iTmr_y & "M)")) Then Exit Function
        If (Not ps.AddOption("optT" & iTmr_y & "M_0", 200, 225, 1900, 300, _
            "Timer mode")) Then Exit Function
        If (Not ps.AddOption("optT" & iTmr_y & "M_1", 200, 550, 1900, 300, _
            "Counter mode")) Then Exit Function

    '-------------------------------
    ' frame: frmTyI
    '-------------------------------
    If (Not ps.AddFrame("frmT" & iTmr_y & "I", 3050, 2750, 5550, 900, _
        "Timer " & iTmr_y & " Input Selection (T" & iTmr_y & "I)")) Then Exit Function
        If (Not ps.AddCombo("cboT" & iTmr_y & "I", 1525, 350, 3875, 315)) Then Exit Function
        If (Not ps.AddLabel("lblT" & iTmr_y & "I", 0, 200, 400, 1225, 330, _
            "Edge selection")) Then Exit Function

    '-------------------------------
    ' frame: frmTyR
    '-------------------------------
    If (Not ps.AddFrame("frmT" & iTmr_y & "R", 100, 3700, 2825, 800, _
        "Timer " & iTmr_y & " Start Control")) Then Exit Function
        If (Not ps.AddCheck("chkT" & iTmr_y & "R", 200, 250, 2525, 375, _
            "Start T" & iTmr_y & " after initialization (T" & iTmr_y & "R)")) Then Exit Function

    '-------------------------------
    ' frame: frmTyIE
    '-------------------------------
    If (Not ps.AddFrame("frmT" & iTmr_y & "IE", 100, 4550, 2825, 800, _
        "Interrupt Control")) Then Exit Function
        If (Not ps.AddCheck("chkT" & iTmr_y & "IE", 200, 300, 2500, 300, _
            "Enable T" & iTmr_y & " interrupt (IE)")) Then Exit Function

    '-------------------------------
    ' frame: frmTimReg_y
    '-------------------------------
    If (Not ps.AddFrame("frmTimReg_" & iTmr_y & "", 3050, 3700, 5550, 1650, _
        "Timer " & iTmr_y & " Registers")) Then Exit Function
        If (Not ps.AddLabel("lblOverflow_" & iTmr_y & "", 0, 200, 400, 1125, 305, _
            "Overflow [xxs]")) Then Exit Function
        If (Not ps.AddText("txtOverflow_" & iTmr_y & "", 1425, 350, 1100, 300)) Then Exit Function
        If (Not ps.AddText("txtT" & iTmr_y & "REL", 4400, 350, 1000, 300)) Then Exit Function
        If (Not ps.AddLabel("lblT" & iTmr_y & "REL", 0, 2700, 300, 1600, 380, _
            "Timer " & iTmr_y & " reload register (" & sRegPre & "T" & iTmr_y & "REL)")) Then Exit Function
        If (Not ps.AddText("txtT" & iTmr_y & "", 4400, 1000, 1000, 315)) Then Exit Function
        If (Not ps.AddLabel("lblT" & iTmr_y & "", 0, 2700, 950, 1575, 380, _
            "Timer " & iTmr_y & " register (" & sRegPre & "T" & iTmr_y & ")")) Then Exit Function

  End If
  OnChangingPageTimer_x_y = 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 OnShowPageTimer_x_y(ps As Object, Controlname As String, Pagename As String, v() As Variant) As Boolean
  On Error GoTo OnShowPageTimer_x_yError

  OnShowPageTimer_x_y = False

  Dim r           As ProjectData
  Dim c           As Object
  Dim e           As Object
  Dim iTmr_x      As Integer
  Dim iTmr_y      As Integer
  Dim iTmr        As Integer
  Dim vIndex      As Variant
  Dim sVarPre     As String
  Dim sRegPre     As String
  Dim sCCx        As String
  Dim sCCxPin     As String
  Dim s           As String
  Dim bDisabled   As Boolean
  Dim i           As Integer
  Dim uTime       As UnitType
  Dim dDivider    As Double
  Dim sDisabledTooltip As String

  vIndex = ps.Parameters.v("x")
  If (vIndex = 1) Then
      iTmr_x = 0
      iTmr_y = 1
  Else
      iTmr_x = 7
      iTmr_y = 8
  End If

  sVarPre = "CC" & vIndex
  sRegPre = sVarPre & "_"
  sCCxPin = "CC" & vIndex & "_"

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

  If (Pagename = "Timer " & iTmr_x & "/" & iTmr_y) Then
    '-------------------------------------------------------------------------
    ' page: Timer_x_y (action)
    '-------------------------------------------------------------------------

    For iTmr = iTmr_x To iTmr_y
        Select Case (Controlname)
            '---------------------------------------------------------------------
            ' control: optT..M_0 (action)
            '---------------------------------------------------------------------
            Case "optT" & iTmr & "M_0"
                r.v(sRegPre & "T" & iTmr_x & iTmr_y & "CON_T" & iTmr & "M") = 0
                r.v(sRegPre & "T" & iTmr_x & iTmr_y & "CON_T" & iTmr & "I") = 0
                
                If (r.Exist("MuxFor_" & sVarPre & "_T" & iTmr & "IN")) Then
                    If (GetPinFunction(r, sCCxPin & "T" & iTmr & "IN") = 1) Then
                        Call ReleaseAlternateInputPin(r, sCCxPin & "T" & iTmr & "IN")
                    End If
                End If

            '---------------------------------------------------------------------
            ' control: optT..M_1 (action)
            '---------------------------------------------------------------------
            Case "optT" & iTmr & "M_1"
                r.v(sRegPre & "T" & iTmr_x & iTmr_y & "CON_T" & iTmr & "M") = 1
                r.v(sRegPre & "T" & iTmr_x & iTmr_y & "CON_T" & iTmr & "I") = 0

            '---------------------------------------------------------------------
            ' control: txtT..REL (action)
            '---------------------------------------------------------------------
            Case "txtT" & iTmr & "REL"
                If (IsInputFormatOK(v(1), "H4", c("lblT" & iTmr & "REL").Caption, 0, 65535)) Then
                  r.sfr(sRegPre & "T" & iTmr & "REL") = v(1)
                  r.sfr(sRegPre & "T" & iTmr) = v(1)
                Else
                    Exit Function
                End If

            '---------------------------------------------------------------------
            ' control: txtOverflow_.. (action)
            '---------------------------------------------------------------------
            Case "txtOverflow_" & iTmr & ""
                uTime = ConvertTime(GetOverflow(r, vIndex, iTmr))
                dDivider = uTime.dDivider
                If (IsInputFormatOK(v(1), "F", c("lblOverflow_" & iTmr).Caption, _
                    Format(GetMinResolution(r, vIndex, iTmr) / dDivider, "0.0000000"), _
                    Format(GetMaxResolution(r, vIndex, iTmr) / dDivider, "0.0000000"))) Then

                  r.l(sRegPre & "T" & iTmr & "REL_T" & iTmr & "REL") = _
                    GetTimerNrValue(r, vIndex, v(1) * dDivider, True, iTmr)   'True for overflow
                  r.l(sRegPre & "T" & iTmr & "_T" & iTmr) = _
                    r.l(sRegPre & "T" & iTmr & "REL_T" & iTmr & "REL")
                Else
                    Exit Function
                End If

            '---------------------------------------------------------------------
            ' control: txtT.. (action)
            '---------------------------------------------------------------------
            Case "txtT" & iTmr & ""
                If (IsInputFormatOK(v(1), "H4", c("lblT" & iTmr).Caption, 0, 65535)) Then
                  r.sfr(sRegPre & "T" & iTmr) = v(1)
                Else
                    Exit Function
                End If

            '---------------------------------------------------------------------
            ' control: chkT..R (action)
            '---------------------------------------------------------------------
            Case "chkT" & iTmr & "R"
                r.v(sRegPre & "T" & iTmr_x & iTmr_y & "CON_T" & iTmr & "R") = v(1)

            '---------------------------------------------------------------------
            ' control: chkT..IE (action)
            '---------------------------------------------------------------------
            Case "chkT" & iTmr & "IE"
                If v(1) = 1 Then
                  Call EnableSRN(r, sVarPre, sRegPre & "T" & iTmr & "IC", "Tmr" & iTmr)
                Else
                  Call DisableSRN(r, sVarPre, sRegPre & "T" & iTmr & "IC", "Tmr" & iTmr)
                End If

            '---------------------------------------------------------------------
            ' control: cboTxI (action)
            '---------------------------------------------------------------------
            Case "cboT" & iTmr & "I"
                If (r.v(sRegPre & "T" & iTmr_x & iTmr_y & "CON_T" & iTmr & "M") = 1) Then
                    Select Case (v(1))  ' if counter mode
                        Case ("Overflow/Underflow of timer T6")
                            r.v(sRegPre & "T" & iTmr_x & iTmr_y & "CON_T" & iTmr & "I") = 0
                            If (r.Exist("MuxFor_" & sVarPre & "_T" & iTmr & "IN")) Then
                                If (GetPinFunction(r, sCCxPin & "T" & iTmr & "IN") = 1) Then
                                    Call ReleaseAlternateInputPin(r, sCCxPin & "T" & iTmr & "IN")
                                End If
                            End If
                        Case ("Positive transition on pin T" & iTmr & "IN (" & _
                              GetPinName(sCCxPin & "T" & iTmr & "IN") & ")")
                            r.v(sRegPre & "T" & iTmr_x & iTmr_y & "CON_T" & iTmr & "I") = 1
                            If (GetPinFunction(r, sCCxPin & "T" & iTmr & "IN") = 0) Then
                                Call RequestAlternateInputPin(r, sCCxPin & "T" & iTmr & "IN")
                            End If
                        
                        Case ("Negative transition on pin T" & iTmr & "IN (" & _
                              GetPinName(sCCxPin & "T" & iTmr & "IN") & ")")
                            r.v(sRegPre & "T" & iTmr_x & iTmr_y & "CON_T" & iTmr & "I") = 2
                            If (GetPinFunction(r, sCCxPin & "T" & iTmr & "IN") = 0) Then
                                Call RequestAlternateInputPin(r, sCCxPin & "T" & iTmr & "IN")
                            End If
                        
                        Case ("Any transition on pin T" & iTmr & "IN (" & _
                              GetPinName(sCCxPin & "T" & iTmr & "IN") & ")")
                            r.v(sRegPre & "T" & iTmr_x & iTmr_y & "CON_T" & iTmr & "I") = 3
                            If (GetPinFunction(r, sCCxPin & "T" & iTmr & "IN") = 0) Then
                                Call RequestAlternateInputPin(r, sCCxPin & "T" & iTmr & "IN")
                            End If
                    
                    End Select
                Else
                    For i = 0 To 7  ' if timer mode
                       If v(1) = GetPrescalerResolution(r, vIndex, i) Then
                          r.v(sRegPre & "T" & iTmr_x & iTmr_y & "CON_T" & iTmr & "I") = i
                       End If
                    Next i
                End If
          Case Else
        End Select

    Next iTmr


    bDisabled = (IsModuleClockDisabled(r, vIndex))

    sDisabledTooltip = ""
    sDisabledTooltip = TOOLTIP_DISABLED_IF

    If (IsModuleClockDisabled(r, vIndex)) Then
        sDisabledTooltip = sDisabledTooltip & GetTooltipModuleClockDisabled(r, vIndex)
    End If

    Call SetDefaultPropertiesForAllControlsOnPage(Pagename, c, e, bDisabled, sDisabledTooltip, "")

    '-------------------------------------------------------------------------
    ' page: Timer_x_y (show)
    '-------------------------------------------------------------------------

    For iTmr = iTmr_x To iTmr_y

        '-------------------------------------------------------------------------
        ' control: optTx0M_0 (show)
        '-------------------------------------------------------------------------
        With c("optT" & iTmr & "M_0")
            .Value = -CInt(r.v(sRegPre & "T" & iTmr_x & iTmr_y & "CON_T" & iTmr & "M") = 0)
        End With

        '-------------------------------------------------------------------------
        ' control: optTx0M_1 (show)
        '-------------------------------------------------------------------------
        With c("optT" & iTmr & "M_1")
            bDisabled = (IsModuleClockDisabled(r, vIndex))
            .Enabled = Not (bDisabled)
            .Value = -CInt(r.v(sRegPre & "T" & iTmr_x & iTmr_y & "CON_T" & iTmr & "M") = 1)
        End With

        With e("optT" & iTmr & "M_1")
          If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (IsModuleClockDisabled(r, vIndex)) Then
              .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleClockDisabled(r, vIndex)
            End If
          End If
        End With

        '-------------------------------------------------------------------------
        ' control: txtTx0REL (show)
        '-------------------------------------------------------------------------
        With c("txtT" & iTmr & "REL")
            .Text = FormatTextOutput(r.sfr(sRegPre & "T" & iTmr & "REL"), "H4")
        End With

        '-------------------------------------------------------------------------
        ' control: lblTx0REL (show)
        '-------------------------------------------------------------------------
        With c("lblT" & iTmr & "REL")
        End With

        '-------------------------------------------------------------------------
        ' control: txtOverflow_x0 (show)
        '-------------------------------------------------------------------------
        With c("txtOverflow_" & iTmr & "")
            bDisabled = (IsModuleClockDisabled(r, vIndex) Or _
                         r.v(sRegPre & "T" & iTmr_x & iTmr_y & "CON_T" & iTmr & "M") = 1)
            .Enabled = Not (bDisabled)
          
          If (r.v(sRegPre & "T" & iTmr_x & iTmr_y & "CON_T" & iTmr & "M") = 1) Then
            .Text = CALCULATION_NOT_POSSIBLE
            c("lblOverflow_" & iTmr).Caption = "Overflow [s]"
          Else
            uTime = ConvertTime(GetOverflow(r, vIndex, iTmr))
            .Text = Format(uTime.dValue, "0.0000000")
            c("lblOverflow_" & iTmr).Caption = "Overflow [" & uTime.sUnit & "]"
          End If

        End With

        With e("txtOverflow_" & iTmr & "")
          If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (IsModuleClockDisabled(r, vIndex)) Then
              .DisabledTooltipText = .DisabledTooltipText & _
                GetTooltipModuleClockDisabled(r, vIndex)
            End If
            If (r.v(sRegPre & "T" & iTmr_x & iTmr_y & "CON_T" & iTmr & "M") = 1) Then
              .DisabledTooltipText = .DisabledTooltipText & _
                FormatDisabledToolTip("counter mode is selected")
            End If
          End If
        End With

        '-------------------------------------------------------------------------
        ' control: lblOverflow_x0 (show)
        '-------------------------------------------------------------------------
        With c("lblOverflow_" & iTmr & "")
            .Enabled = Not (bDisabled)
        End With

        '-------------------------------------------------------------------------
        ' control: txtTx0 (show)
        '-------------------------------------------------------------------------
        With c("txtT" & iTmr & "")
            .Text = FormatTextOutput(r.sfr(sRegPre & "T" & iTmr), "H4")
        End With

        '-------------------------------------------------------------------------
        ' control: lblTx0 (show)
        '-------------------------------------------------------------------------
        With c("lblT" & iTmr & "")
        End With

        '-------------------------------------------------------------------------
        ' control: chkTx0R (show)
        '-------------------------------------------------------------------------
        With c("chkT" & iTmr & "R")
            .Value = -CInt(r.v(sRegPre & "T" & iTmr_x & iTmr_y & "CON_T" & iTmr & "R") = 1)
        End With

        '-------------------------------------------------------------------------
        ' control: chkTx0IE (show)
        '-------------------------------------------------------------------------
        With c("chkT" & iTmr & "IE")
            .Value = -CInt(r.v(sRegPre & "T" & iTmr & "IC_IE") = 1)
        End With

        '-------------------------------------------------------------------------
        ' control: cboTxI (show)
        '-------------------------------------------------------------------------
        With c("cboT" & iTmr & "I")
            .Clear
            If (r.v(sRegPre & "T" & iTmr_x & iTmr_y & "CON_T" & iTmr & "M") = 1) Then
                .AddItem "Overflow/Underflow of timer T6"

                
                If (r.Exist("MuxFor_" & sVarPre & "_T" & iTmr & "IN") = True) Then
                    If (IsAlternateInputPinFree(r, sCCxPin & "T" & iTmr & "IN")) Then
                        .AddItem "Positive transition on pin T" & iTmr & _
                                 "IN (" & GetPinName(sCCxPin & "T" & iTmr & "IN") & ")"
                        .AddItem "Negative transition on pin T" & iTmr & _
                                 "IN (" & GetPinName(sCCxPin & "T" & iTmr & "IN") & ")"
                        .AddItem "Any transition on pin T" & iTmr & _
                                 "IN (" & GetPinName(sCCxPin & "T" & iTmr & "IN") & ")"
                    End If
                End If

                .ListIndex = r.v(sRegPre & "T" & iTmr_x & iTmr_y & "CON_T" & iTmr & "I")
            Else
                For i = 0 To 7
                  .AddItem GetPrescalerResolution(r, vIndex, i)
                Next i
                .ListIndex = r.v(sRegPre & "T" & iTmr_x & iTmr_y & "CON_T" & iTmr & "I")
            End If

            
        End With

        '-------------------------------------------------------------------------
        ' control: lblTx0I (show)
        '-------------------------------------------------------------------------
        With c("lblT" & iTmr & "I")
            If (r.v(sRegPre & "T" & iTmr_x & iTmr_y & "CON_T" & iTmr & "M") = 0) Then
                .Caption = "Prescaler"
            Else
                .Caption = "Edge selection"
            End If
        End With

    Next iTmr


  End If

  OnShowPageTimer_x_y = True
  Exit Function

OnShowPageTimer_x_yError:
  errorbox "Can not show page", Err.Description
  Exit Function
End Function

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

  OnLoadPageChannels = False

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

  OnLoadPageChannels = 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
'*****************************************************************************
Function OnChangingPageChannels(ps As Object, Pagename As String) As Boolean
  On Error Resume Next

  OnChangingPageChannels = False
  Dim vIndex    As Variant
  Dim i         As Integer
  Dim iChannel  As Integer
  Dim iCh_low   As Integer
  Dim iCh_high  As Integer

  vIndex = ps.Parameters.v("x")

  If (vIndex = 1) Then
      iCh_low = 0
      iCh_high = 7 + CH_HIGH
  Else
      iCh_low = 16
      iCh_high = 23 + CH_HIGH
  End If
  
  If (Not ps.ExtenderCollection("Channels").Loaded) And (Pagename = "Channels") Then
    ps.ExtenderCollection("Channels").Loaded = True
  

    '-------------------------------
    ' frame: frmCh_x
    '-------------------------------
    If (Not ps.AddFrame("frmCh_" & vIndex, 100, 100, 8425, 4550, _
        "Capture / Compare Channels")) Then Exit Function
        iChannel = iCh_low
        For i = 0 To 7
            If (Not ps.AddButton("btnCh_" & iChannel, 200, 400 + i * 500, 1800, 380, _
                "Configure Channel " & iChannel)) Then Exit Function
            If (Not ps.AddCheck("chkCh_" & iChannel, 2200, 400 + i * 500, 2000, 380, _
                "Channel " & iChannel & " is enabled")) Then Exit Function
            iChannel = iChannel + 1
        Next i

        For i = 0 To 7
            If (Not ps.AddButton("btnCh_" & iChannel, 4400, 400 + i * 500, 1800, 380, _
                "Configure Channel " & iChannel)) Then Exit Function
            If (Not ps.AddCheck("chkCh_" & iChannel, 6400, 400 + i * 500, 2000, 380, _
                "Channel " & iChannel & " is enabled")) Then Exit Function
            iChannel = iChannel + 1
        Next i

  End If
  OnChangingPageChannels = 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 OnShowPageChannels(ps As Object, Controlname As String, Pagename As String, v() As Variant) As Boolean
  On Error GoTo OnShowPageChannelsError

  OnShowPageChannels = False

  Dim r           As ProjectData
  Dim c           As Object
  Dim e           As Object
  Dim vIndex      As Variant
  Dim i           As Integer
  Dim iChannel    As Integer
  Dim iCh_low     As Integer
  Dim iCh_high    As Integer
  Dim bDisabled   As Boolean
  Dim sVarPre     As String

  vIndex = ps.Parameters.v("x")

  If (vIndex = 1) Then
      iCh_low = 0
      iCh_high = 7 + CH_HIGH
  Else
      iCh_low = 16
      iCh_high = 23 + CH_HIGH
  End If

  sVarPre = "CC" & vIndex

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

  If (Pagename = "Channels") Then
    '-------------------------------------------------------------------------
    ' page: Channels (action)
    '-------------------------------------------------------------------------
    For iChannel = iCh_low To iCh_high
        Select Case (Controlname)
            '---------------------------------------------------------------------
            ' control: btnCh_x (action)
            '---------------------------------------------------------------------
            Case "btnCh_" & iChannel

            '---------------------------------------------------------------------
            ' control: chkCh_x (action)
            '---------------------------------------------------------------------
            Case "chkCh_" & iChannel


          Case Else
        End Select

    Next iChannel

    '-------------------------------------------------------------------------
    ' page: Channels (show)
    '-------------------------------------------------------------------------

    For iChannel = iCh_low To iCh_high
        '-------------------------------------------------------------------------
        ' control: btnCh_x (show)
        '-------------------------------------------------------------------------
        With c("btnCh_" & iChannel)
            bDisabled = False
            .Enabled = Not (bDisabled)
        End With

        With e("btnCh_" & iChannel)
            If (bDisabled) Then
                .DisabledTooltipText = TOOLTIP_DISABLED_IF
                If (IsModuleClockDisabled(r, vIndex)) Then
                    .DisabledTooltipText = .DisabledTooltipText & _
                      GetTooltipModuleClockDisabled(r, vIndex)
                End If
            End If
        End With
    
        '-------------------------------------------------------------------------
        ' control: chkCh_x (show)
        '-------------------------------------------------------------------------
        With c("chkCh_" & iChannel)
            bDisabled = True
            .Enabled = Not (bDisabled)
            .Value = -CInt(r.v(sVarPre & "_CC" & iChannel & "_Use") = 1)
        End With

        With e("chkCh_" & iChannel)
            If (bDisabled) Then
                .DisabledTooltipText = ""
                If (1 = 1) Then
                    '.DisabledTooltipText = .DisabledTooltipText & FormatNormalTooltip("Das ist nur eine Statusanzeige.")
                End If
            End If
        End With

    Next iChannel


  End If

  OnShowPageChannels = True
  Exit Function

OnShowPageChannelsError:
  Exit Function
End Function



'*****************************************************************************
'Description:
'        This function is called from the OnClick function of the associated
'        module if a button on the page 'Channels' will be clicked.
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Controlname     control name of the button
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnButtonClickOnPageChannels(ps As Object, Controlname As String) As Boolean
  On Error GoTo OnButtonClickOnPageChannelsError

  OnButtonClickOnPageChannels = False
  Dim vIndex      As Variant
  Dim i           As Integer
  Dim iChannel    As Integer
  Dim iCh_low     As Integer
  Dim iCh_high    As Integer
  Dim bDisabled   As Boolean
  Dim iCh_Group   As Integer
  Dim sDiabledTooltip As String

  vIndex = ps.Parameters.v("x")

  If (vIndex = 1) Then
      iCh_low = 0
      iCh_high = 7 + CH_HIGH
  Else
      iCh_low = 16
      iCh_high = 23 + CH_HIGH
  End If

  '---------------------------------------------------------------------
  ' control: btnCh_x (action)
  '---------------------------------------------------------------------
  For iChannel = iCh_low To iCh_high
      If (Controlname = "btnCh_" & iChannel) Then
          If (iChannel < (iCh_high - 7)) Then
              iCh_Group = 1
          Else
              iCh_Group = 2
          End If

          Set CHANNELx = New Peripherals
          CHANNELx.Parameters.Add ("x")
          CHANNELx.Parameters.v("x") = vIndex
          CHANNELx.Parameters.Add ("Channel")
          CHANNELx.Parameters.v("Channel") = iChannel
          CHANNELx.Parameters.Add ("Ch_Group")
          CHANNELx.Parameters.v("Ch_Group") = iCh_Group
          Set CHANNELx.ProjectData = ps.ProjectData
          CHANNELx.Caption = "Configure CAPCOM" & vIndex & " Channel " & iChannel
          CHANNELx.Scriptfile = DefGetPath("Scripts") & "CCx\Channel_x.DAVE"
          CHANNELx.Show

      End If
  Next iChannel


  OnButtonClickOnPageChannels = True
  Exit Function

OnButtonClickOnPageChannelsError:
  Exit Function
End Function

'*****************************************************************************
'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 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

  Dim i         As Integer
  Dim iCh       As Integer
  Dim vIndex    As Variant
  Dim iCh_low   As Integer
  Dim iCh_high  As Integer
  Dim iTmr_x    As Integer
  Dim iTmr_y    As Integer
  Dim aFunctions(1 To 16) As String

  vIndex = ps.Parameters.v("x")
  If (vIndex = 1) Then
      iCh_low = 0
      iCh_high = 7 + CH_HIGH
      iTmr_x = 0
      iTmr_y = 1
  Else
      iCh_low = 16
      iCh_high = 23 + CH_HIGH
      iTmr_x = 7
      iTmr_y = 8
  End If

  OnChangingPageFunctions = False
  

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

    '-------------------------------
    ' frame: fra_Init
    '-------------------------------
    If (Not ps.AddFrame("fra_Init", 100, 100, 4150, 700, _
        CAPTION_FRA_USE_INIT)) Then Exit Function
      If (Not ps.AddCheck("chk_Init", 150, 275, 200, 275, "")) Then Exit Function
      If (Not ps.AddText("txt_Init", 400, 250, 3600, 325)) Then Exit Function

    '-------------------------------
    ' frame: fra_CFile
    '-------------------------------
    If (Not ps.AddFrame("fra_CFile", 4400, 100, 4150, 700, _
        CAPTION_FRA_CFILE)) Then Exit Function
      If (Not ps.AddText("txt_CFile", 1475, 250, 2500, 325)) Then Exit Function
      If (Not ps.AddLabel("lbl_CFile", 0, 200, 300, 1250, 275, _
          CAPTION_LBL_CFILE)) Then Exit Function


    '-------------------------------
    ' frame: fraLibrary1
    '-------------------------------
    ' initialize the array
    For i = LBound(aFunctions) To UBound(aFunctions)
          aFunctions(i) = ""
    Next i

    ' Functions and Macros
    i = LBound(aFunctions)
    aFunctions(i) = "StartTmr"
    i = i + 1
    aFunctions(i) = "StopTmr"
    i = i + 1
    aFunctions(i) = "ClearTmr"
    i = i + 1
    aFunctions(i) = "ReadTmr"
    i = i + 1
    aFunctions(i) = "LoadTmr"
    i = i + 1
    aFunctions(i) = "SetReload"
    i = i + 1
    aFunctions(i) = "SetCCxReg"
    i = i + 1
    aFunctions(i) = "GetCCxReg"
    i = i + 1
    aFunctions(i) = "Tmr" & iTmr_x
    i = i + 1
    aFunctions(i) = "Tmr" & iTmr_y
    i = i + 1


    If (Not ps.AddFrame("fraLibrary1", 100, 900, 4150, 4400, CAPTION_FRA_LIBRARY1)) Then Exit Function
      For i = LBound(aFunctions) To UBound(aFunctions)
        If Not (aFunctions(i) = "") Then
          If (Not ps.AddCheck("chk_" & aFunctions(i), 150, 325 + (300 * (i - 1)), 200, 275, "")) Then Exit Function
          If (Not ps.AddText("txt_" & aFunctions(i), 400, 300 + (300 * (i - 1)), 3600, 325)) Then Exit Function
        End If
      Next i

    '-------------------------------
    ' frame: fraLibrary2
    '-------------------------------
    ' initialize the array
    For i = LBound(aFunctions) To UBound(aFunctions)
      aFunctions(i) = ""
    Next i

    ' Functions and Macros
    i = LBound(aFunctions)
    aFunctions(i) = "PortLock"
    i = i + 1
    aFunctions(i) = "PortUnlock"
    i = i + 1
    aFunctions(i) = "EnableSingleEvent"
    i = i + 1
    aFunctions(i) = "SelectDoubleRegisterCompareMode"
    i = i + 1
    aFunctions(i) = "SetCCxOUT"
    i = i + 1
    aFunctions(i) = "ResetCCxOUT"
    i = i + 1
    aFunctions(i) = "GetCCxOUT"
    i = i + 1
'    aFunctions(i) = "SetPortDirectionOutput"
'    i = i + 1
'    aFunctions(i) = "SetPortDirectionInput"
'    i = i + 1


    If (Not ps.AddFrame("fraLibrary2", 4400, 900, 4150, 4400, CAPTION_FRA_LIBRARY2)) Then Exit Function
      For i = LBound(aFunctions) To UBound(aFunctions)
        If Not (aFunctions(i) = "") Then
          If (Not ps.AddCheck("chk_" & aFunctions(i), 150, 325 + (300 * (i - 1)), 200, 275, "")) Then Exit Function
          If (Not ps.AddText("txt_" & aFunctions(i), 400, 300 + (300 * (i - 1)), 3600, 325)) Then Exit Function
        End If
      Next i

  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 OnShowPageFunctionsError

  OnShowPageFunctions = False
    
  Dim r           As ProjectData
  Dim c           As Collection
  Dim e           As Collection
  Dim bDisabled   As Boolean
  Dim func        As FunctionClass
  Dim d           As String
  Dim sVarPre     As String
  Dim sRegPre     As String
  Dim sName       As String
  Dim vIndex      As Variant
  Dim sFctName    As String
  Dim iCh_low     As Integer
  Dim iCh_high    As Integer
  Dim iTmr_x      As Integer
  Dim iTmr_y      As Integer
  Dim i           As Integer

  vIndex = ps.Parameters.v("x")
  sVarPre = "CC" & vIndex
  sRegPre = sVarPre & "_"

  If (vIndex = 1) Then
      iCh_low = 0
      iCh_high = 7 + CH_HIGH
      iTmr_x = 0
      iTmr_y = 1
  Else
      iCh_low = 16
      iCh_high = 23 + CH_HIGH
      iTmr_x = 7
      iTmr_y = 8
  End If

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

  If (Pagename = "Functions") Then

    '-------------------------------------------------------------------------
    ' page: Functions (action)
    '-------------------------------------------------------------------------
    
    RefreshFunctionDescriptions(vIndex, func, r, 0)
    'RefreshFunctionDescriptions(vIndex, func, r, 0)
    If (Not UpdateFunction(sVarPre, ps, func, Controlname, v)) Then Exit Function
    
    
    '-------------------------------------------------------------------------
    ' page: Functions (show)
    '-------------------------------------------------------------------------
    Set func = New FunctionClass
    RefreshFunctionDescriptions(vIndex, func, r, 0)

    sName = sVarPre & "_NAME_Init"
    ' disable condition
    func.Disabled(sName) = (IsModuleClockDisabled(r, vIndex))
    ' tooltip if control is disabled
    d = GetDisabledFunctionToolTipEntry(func, sName)
    If (IsModuleClockDisabled(r, vIndex)) Then
      d = d & GetTooltipModuleClockDisabled(r, vIndex)
    End If
    func.DisabledToolTip(sName) = d

    sFctName = "StartTmr"
    sName = sVarPre & "_NAME_" & sFctName
    ' disable condition
    func.Disabled(sName) = (r.v(sVarPre & "_USE_Init") = 0)
    ' tooltip if control is disabled
    d = GetDisabledFunctionToolTipEntry(func, sName)
    If (r.v(sVarPre & "_USE_Init") = 0) Then
      d = d & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
    End If
    func.DisabledToolTip(sName) = d

    sFctName = "StopTmr"
    sName = sVarPre & "_NAME_" & sFctName
    ' disable condition
    func.Disabled(sName) = (r.v(sVarPre & "_USE_Init") = 0)
    ' tooltip if control is disabled
    d = GetDisabledFunctionToolTipEntry(func, sName)
    If (r.v(sVarPre & "_USE_Init") = 0) Then
      d = d & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
    End If
    func.DisabledToolTip(sName) = d

    sFctName = "ClearTmr"
    sName = sVarPre & "_NAME_" & sFctName
    ' disable condition
    func.Disabled(sName) = (r.v(sVarPre & "_USE_Init") = 0)
    ' tooltip if control is disabled
    d = GetDisabledFunctionToolTipEntry(func, sName)
    If (r.v(sVarPre & "_USE_Init") = 0) Then
      d = d & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
    End If
    func.DisabledToolTip(sName) = d
   
    
    sFctName = "ReadTmr"
    sName = sVarPre & "_NAME_" & sFctName
    ' disable condition
    func.Disabled(sName) = (r.v(sVarPre & "_USE_Init") = 0)
    ' tooltip if control is disabled
    d = GetDisabledFunctionToolTipEntry(func, sName)
    If (r.v(sVarPre & "_USE_Init") = 0) Then
       d = d & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
    End If
    func.DisabledToolTip(sName) = d
    

    sFctName = "LoadTmr"
    sName = sVarPre & "_NAME_" & sFctName
    ' disable condition
    func.Disabled(sName) = (r.v(sVarPre & "_USE_Init") = 0)
    ' tooltip if control is disabled
    d = GetDisabledFunctionToolTipEntry(func, sName)
    If (r.v(sVarPre & "_USE_Init") = 0) Then
      d = d & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
    End If
    func.DisabledToolTip(sName) = d

    sFctName = "SetReload"
    sName = sVarPre & "_NAME_" & sFctName
    ' disable condition
    func.Disabled(sName) = (r.v(sVarPre & "_USE_Init") = 0)
    ' tooltip if control is disabled
    d = GetDisabledFunctionToolTipEntry(func, sName)
    If (r.v(sVarPre & "_USE_Init") = 0) Then
      d = d & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
    End If
    func.DisabledToolTip(sName) = d
 
    sFctName = "SetCCxReg"
    sName = sVarPre & "_NAME_" & sFctName
    ' disable condition
    func.Disabled(sName) = (r.v(sVarPre & "_USE_Init") = 0)
    ' tooltip if control is disabled
    d = GetDisabledFunctionToolTipEntry(func, sName)
    If (r.v(sVarPre & "_USE_Init") = 0) Then
      d = d & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
    End If
    func.DisabledToolTip(sName) = d

    sFctName = "GetCCxReg"
    sName = sVarPre & "_NAME_" & sFctName
    ' disable condition
    func.Disabled(sName) = (r.v(sVarPre & "_USE_Init") = 0)
    ' tooltip if control is disabled
    d = GetDisabledFunctionToolTipEntry(func, sName)
    If (r.v(sVarPre & "_USE_Init") = 0) Then
      d = d & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
    End If
    func.DisabledToolTip(sName) = d

    sFctName = "Tmr" & iTmr_x
    sName = sVarPre & "_NAME_" & sFctName
    ' disable condition
    func.Disabled(sName) = True
    ' tooltip if control is disabled
    d = TOOLTIP_DISABLED_ISR32
    func.DisabledToolTip(sName) = d
    ' value for the control
    func.Value(sName) = IsISRSelected(r, sVarPre, sRegPre & "T" & iTmr_x & "IC", "Tmr" & iTmr_x)

    sFctName = "Tmr" & iTmr_y
    sName = sVarPre & "_NAME_" & sFctName
    ' disable condition
    func.Disabled(sName) = True
    ' tooltip if control is disabled
    d = TOOLTIP_DISABLED_ISR32
    func.DisabledToolTip(sName) = d
    ' value for the control
    func.Value(sName) = IsISRSelected(r, sVarPre, sRegPre & "T" & iTmr_y & "IC", "Tmr" & iTmr_y)

    sFctName = "PortLock"
    sName = sVarPre & "_NAME_" & sFctName
    ' disable condition
    func.Disabled(sName) = (r.v(sVarPre & "_USE_Init") = 0)
    ' tooltip if control is disabled
    d = GetDisabledFunctionToolTipEntry(func, sName)
    If (r.v(sVarPre & "_USE_Init") = 0) Then
      d = d & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
    End If
    func.DisabledToolTip(sName) = d

    sFctName = "PortUnlock"
    sName = sVarPre & "_NAME_" & sFctName
    ' disable condition
    func.Disabled(sName) = (r.v(sVarPre & "_USE_Init") = 0)
    ' tooltip if control is disabled
    d = GetDisabledFunctionToolTipEntry(func, sName)
    If (r.v(sVarPre & "_USE_Init") = 0) Then
      d = d & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
    End If
    func.DisabledToolTip(sName) = d

    sFctName = "EnableSingleEvent"
    sName = sVarPre & "_NAME_" & sFctName
    ' disable condition
    func.Disabled(sName) = (r.v(sVarPre & "_USE_Init") = 0)
    ' tooltip if control is disabled
    d = GetDisabledFunctionToolTipEntry(func, sName)
    If (r.v(sVarPre & "_USE_Init") = 0) Then
      d = d & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
    End If
    func.DisabledToolTip(sName) = d

    sFctName = "SelectDoubleRegisterCompareMode"
    sName = sVarPre & "_NAME_" & sFctName
    ' disable condition
    func.Disabled(sName) = (r.v(sVarPre & "_USE_Init") = 0)
    ' tooltip if control is disabled
    d = GetDisabledFunctionToolTipEntry(func, sName)
    If (r.v(sVarPre & "_USE_Init") = 0) Then
      d = d & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
    End If
    func.DisabledToolTip(sName) = d

    sFctName = "SetCCxOUT"
    sName = sVarPre & "_NAME_" & sFctName
    ' disable condition
    func.Disabled(sName) = (r.v(sVarPre & "_USE_Init") = 0)
    ' tooltip if control is disabled
    d = GetDisabledFunctionToolTipEntry(func, sName)
    If (r.v(sVarPre & "_USE_Init") = 0) Then
      d = d & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
    End If
    func.DisabledToolTip(sName) = d

    sFctName = "ResetCCxOUT"
    sName = sVarPre & "_NAME_" & sFctName
    ' disable condition
    func.Disabled(sName) = (r.v(sVarPre & "_USE_Init") = 0)
    ' tooltip if control is disabled
    d = GetDisabledFunctionToolTipEntry(func, sName)
    If (r.v(sVarPre & "_USE_Init") = 0) Then
      d = d & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
    End If
    func.DisabledToolTip(sName) = d

    sFctName = "GetCCxOUT"
    sName = sVarPre & "_NAME_" & sFctName
    ' disable condition
    func.Disabled(sName) = (r.v(sVarPre & "_USE_Init") = 0)
    ' tooltip if control is disabled
    d = GetDisabledFunctionToolTipEntry(func, sName)
    If (r.v(sVarPre & "_USE_Init") = 0) Then
      d = d & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
    End If
    func.DisabledToolTip(sName) = d
   
'    sFctName = "SetPortDirectionOutput"
'    sName = sVarPre & "_NAME_" & sFctName
'    ' disable condition
'    func.Disabled(sName) = (r.v(sVarPre & "_USE_Init") = 0)
'    ' tooltip if control is disabled
'    d = GetDisabledFunctionToolTipEntry(func, sName)
'    If (r.v(sVarPre & "_USE_Init") = 0) Then
'      d = d & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
'    End If
'    func.DisabledToolTip(sName) = d
'
'    sFctName = "SetPortDirectionInput"
'    sName = sVarPre & "_NAME_" & sFctName
'    ' disable condition
'    func.Disabled(sName) = (r.v(sVarPre & "_USE_Init") = 0)
'    ' tooltip if control is disabled
'    d = GetDisabledFunctionToolTipEntry(func, sName)
'    If (r.v(sVarPre & "_USE_Init") = 0) Then
'      d = d & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
'    End If
'    func.DisabledToolTip(sName) = d

    If (Not ShowFunction(sVarPre, ps, func, v)) Then Exit Function
    
  End If         ' if Pagename
  OnShowPageFunctions = True
  
  Exit Function
  
OnShowPageFunctionsError:
  errorbox "Can not show page", Err.Description
  
  Exit Function
End Function


'*****************************************************************************
'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 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 r           As ProjectData
  Dim c           As Collection
  Dim e           As Collection
  Dim bDisabled   As Boolean
  Dim sVarPre     As String
  Dim vIndex      As Variant
  Dim sParaName   As String
  Dim i           As Integer
  Dim iCh         As Integer
  Dim iCh_low     As Integer
  Dim iCh_high    As Integer
  Dim iTmr_x      As Integer
  Dim iTmr_y      As Integer
  Dim aParameters(1 To 16) As String

  vIndex = ps.Parameters.v("x")
  sVarPre = "CC" & vIndex
  
  If (vIndex = 1) Then
      iCh_low = 0
      iCh_high = 7 + CH_HIGH
      iTmr_x = 0
      iTmr_y = 1
  Else
      iCh_low = 16
      iCh_high = 23 + CH_HIGH
      iTmr_x = 7
      iTmr_y = 8
  End If


  OnChangingPageParameters = False

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

    '-------------------------------------------------------------------------
    ' frame: frmCAPCOMx_HFile
    '-------------------------------------------------------------------------
    If (Not ps.AddFrame("fra_HFile", 100, 100, 4150, 700, CAPTION_FRA_HFILE)) Then Exit Function
      If (Not ps.AddText("txt_HFile", 1475, 250, 2500, 325)) Then Exit Function
      If (Not ps.AddLabel("lbl_HFile", 0, 200, 300, 1250, 300, CAPTION_LBL_HFILE)) Then Exit Function

    
    '-------------------------------
    ' frame: fraParameters1
    '-------------------------------
    ' initialize the array
    For i = LBound(aParameters) To UBound(aParameters)
      aParameters(i) = ""
    Next i

    i = LBound(aParameters)
    aParameters(i) = "TIMER_" & iTmr_x
    i = i + 1
    aParameters(i) = "TIMER_" & iTmr_y
    i = i + 1

    For iCh = iCh_low To iCh_high - 9
        aParameters(i) = "CC_" & iCh
        i = i + 1
    Next iCh


    If (Not ps.AddFrame("fraParameters1", 100, 900, 4150, 4400, CAPTION_FRA_PARAMETERS1)) Then Exit Function
      For i = LBound(aParameters) To UBound(aParameters)
        If Not (aParameters(i) = "") Then
          If (Not ps.AddText("txt_" & aParameters(i), 200, 300 * i, 3800, 325)) Then Exit Function
        End If
      Next i
    
    '-------------------------------
    ' frame: fraParameters1
    '-------------------------------
    ' initialize the array
    For i = LBound(aParameters) To UBound(aParameters)
      aParameters(i) = ""
    Next i

    i = LBound(aParameters)
    For iCh = iCh_low + 7 To iCh_high
        aParameters(i) = "CC_" & iCh
        i = i + 1
    Next iCh


    If (Not ps.AddFrame("fraParameters2", 4400, 900, 4150, 4400, CAPTION_FRA_PARAMETERS1)) Then Exit Function
      For i = LBound(aParameters) To UBound(aParameters)
        If Not (aParameters(i) = "") Then
          If (Not ps.AddText("txt_" & aParameters(i), 200, 300 * i, 3800, 325)) Then Exit Function
        End If
      Next i
    
    ' Functions and Macros
  End If

  OnChangingPageParameters = 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 OnShowPageParameters(ps As Peripherals, Controlname As String, Pagename As String, v() As Variant) As Boolean
  On Error GoTo OnShowPageParametersError
  OnShowPageParameters = False
    
  Dim r           As ProjectData
  Dim c           As Collection
  Dim e           As Collection
  Dim para        As ParameterClass
  Dim vIndex      As Variant
  Dim sVarPre     As String
  Dim sRegPre     As String
  Dim sName       As String
  Dim d           As String
  Dim i           As Integer

  vIndex = ps.Parameters.v("x")
  sVarPre = "CC" & vIndex
  sRegPre = sVarPre & "_"

  Set r = ps.ProjectData
  Set c = ps.ControlCollection
  Set e = ps.ExtenderCollection
  Set para = New ParameterClass


  If (Pagename = "Parameters") Then

    '-------------------------------------------------------------------------
    ' page: Parameters (action)
    '-------------------------------------------------------------------------
    RefreshParameterDescriptions(vIndex, para, r)

    If (Not UpdateParameter(sVarPre, ps, para, Controlname, v)) Then Exit Function


    '-------------------------------------------------------------------------
    ' page: Parameters (show)
    '-------------------------------------------------------------------------

    Set para = New ParameterClass
    RefreshParameterDescriptions(vIndex, para, r)

'    sName = sIndex & "_PARA_T2"
'    ' disable condition
'    para.Disabled(sName) = True
'    ' tooltip if control is disabled
'    d = FormatDisabledTooltip("Fred ...")
'    para.DisabledToolTip(sName) = d

    If (Not ShowParameter(sVarPre, ps, para, v)) Then Exit Function

  End If         ' if Pagename

  OnShowPageParameters = True
  Exit Function

OnShowPageParametersError:
    errorbox "Can not show page", Err.Description
    Exit Function
End Function





'*****************************************************************************
'Description:
'        This function sets the CAPCOM module to the default.
'
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        vIndex          parameter
'-----------------------------------------------------------------------------
'Returns:
'        none
'*****************************************************************************
Sub SetCAPCOMToDefault(r As ProjectData, vIndex As Variant)
    Dim sVarPre     As String
    Dim s           As String
    Dim sCCx        As String
    Dim sCCxPin     As String
    Dim iTmr_x      As Integer
    Dim iTmr_y      As Integer
    Dim iTmr        As Integer
    Dim iCh_low     As Integer
    Dim iCh_high    As Integer
    Dim iCh         As Integer
    Dim iCh_Group   As Integer

    sVarPre = "CC" & vIndex
    sCCx = "CC" & vIndex
    s = ""
    sCCxPin = "CC" & vIndex & "_"
    
    If (vIndex = 1) Then
        iTmr_x = 0
        iTmr_y = 1
        iCh_low = 0
        iCh_high = 7 + CH_HIGH
    Else
        iTmr_x = 7
        iTmr_y = 8
        iCh_low = 16
        iCh_high = 23 + CH_HIGH
    End If

    For iTmr = iTmr_x To iTmr_y
        If (r.v(s & "T" & iTmr_x & iTmr_y & "CON_T" & iTmr & "M") = 1) Then

            r.v(s & "T" & iTmr_x & iTmr_y & "CON_T" & iTmr & "M") = 0
            
            If (r.Exist("MuxFor_" & sVarPre & "_T" & iTmr & "IN")) Then
                If (GetPinFunction(r, sCCxPin & "T" & iTmr & "IN") = 1) Then
                    r.v(s & "T" & iTmr_x & iTmr_y & "CON_T" & iTmr & "I") = 0
                    Call ReleaseAlternateInputPin(r, sCCxPin & "T" & iTmr & "IN")
                End If
            End If

        End If

        Call DisableSRN(r, sVarPre, s & "T" & iTmr & "SRC", "Tmr" & iTmr)

    Next iTmr
    
    r.v(sVarPre & "_USE_Init") = 0
    r.v(sCCx & "IOC_" & sCCx & "PL") = 0

    For iCh = iCh_low To iCh_high
        If (iCh < (iCh_high - 3)) Then
            iCh_Group = 1
        Else
            iCh_Group = 2
        End If

        Call SetChannelxToDefault(r, vIndex, iCh_Group, iCh)
    Next iCh

End Sub

