Attribute VB_Name = "Module3"
'#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

Dim SharedInt As Integer
'*****************************************************************************
' Module:
'        ADC
'-----------------------------------------------------------------------------
' Description:
'        This file contains functions which are create controls for the
'        module 'ADC'.
'        Furthermore it contains functions for the event handling of
'        these controls.
'
'-----------------------------------------------------------------------------
' History:
'
'        Rev.     Author         Date        Description
'        ----------------------------------------------------------------------
'        0.1    sheshadri       02.11.04     initial version
'        0.2    sheshadri       05.05.05     added actual boundary value label
'                                            in general dialog
'        0.3    sheshadri       16.11.05     Functions GetResultDatax and Get
'                                            GetResultChNumx is changed for x=0-3
'                                            Result Register FIFO functionality
'                                            removed acording to B-Step
'
'*****************************************************************************

'*****************************************************************************
'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: General
    '-------------------------------------------------------------------------
    If (Not OnLoadPageGeneral(ps)) Then Exit Function

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

    '-------------------------------------------------------------------------
        ' page: Sequential
    '-------------------------------------------------------------------------
    If (Not OnLoadPageSequential(ps)) Then Exit Function
    '-------------------------------------------------------------------------
        ' page: Parallel
    '-------------------------------------------------------------------------
    If (Not OnLoadPageParallel(ps)) Then Exit Function
    
    '-------------------------------------------------------------------------
        ' page: Result Register
    '-------------------------------------------------------------------------
    If (Not OnLoadPageResultRegister(ps)) Then Exit Function
    
    '-------------------------------------------------------------------------
    ' page: Interrupts
    '-------------------------------------------------------------------------
    If (Not OnLoadPageInterrupts(ps)) Then Exit Function

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

    '-------------------------------------------------------------------------
    ' page: Functions2
    '-------------------------------------------------------------------------
    If (Not OnLoadPageFunctions2(ps)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: Functions3
    '-------------------------------------------------------------------------
    If (Not OnLoadPageFunctions3(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, "ADC\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
    
    Dim sVarPre As String
    
    sVarPre = "ADC"

    OnChangingPage = False
    
    '-------------------------------------------------------------------------
    'page: ModuleClock
    '-------------------------------------------------------------------------
    If (Not OnChangingPageModuleClock(ps, Pagename)) Then Exit Function
   
   '-------------------------------------------------------------------------
    'page: General
    '-------------------------------------------------------------------------
    If (Not OnChangingPageGeneral(ps, Pagename)) Then Exit Function

   '-------------------------------------------------------------------------
    'page: Channels
    '-------------------------------------------------------------------------
    If (Not OnChangingPageChannels(ps, Pagename)) Then Exit Function
   
    '-------------------------------------------------------------------------
    ' page: Sequential
    '-------------------------------------------------------------------------
    If (Not OnChangingPageSequential(ps, Pagename)) Then Exit Function
    '-------------------------------------------------------------------------
        ' page: Parallel
    '-------------------------------------------------------------------------
    If (Not OnChangingPageParallel(ps, Pagename)) Then Exit Function
    
    '-------------------------------------------------------------------------
        ' page: Result Register
    '-------------------------------------------------------------------------
    If (Not OnChangingPageResultRegister(ps, Pagename)) Then Exit Function
    
    '-------------------------------------------------------------------------
    'page: Interrupts
    '-------------------------------------------------------------------------
    If (Not OnChangingPageInterrupts(ps, Pagename)) Then Exit Function

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

    '-------------------------------------------------------------------------
    'page: Functions2
    '-------------------------------------------------------------------------
    If (Not OnChangingPageFunctions2(ps, Pagename)) Then Exit Function
    '-------------------------------------------------------------------------
    'page: Functions3
    '-------------------------------------------------------------------------
    If (Not OnChangingPageFunctions3(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
    
    Dim sVarPre As String
    
    sVarPre = "ADC"

    OnShow = False

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

    '-------------------------------------------------------------------------
    ' page: Channels
    '-------------------------------------------------------------------------
    If (Not OnShowPageChannels(ps, Controlname, Pagename, v)) Then Exit Function
    
    '-------------------------------------------------------------------------
        ' page: Sequential
    '-------------------------------------------------------------------------
    If (Not OnShowPageSequential(ps, Controlname, Pagename, v)) Then Exit Function
    '-------------------------------------------------------------------------
        ' page: Parallel
    '-------------------------------------------------------------------------
    If (Not OnShowPageParallel(ps, Controlname, Pagename, v)) Then Exit Function
    
    
    '-------------------------------------------------------------------------
        ' page: Result Register
    '-------------------------------------------------------------------------
    If (Not OnShowPageResultRegister(ps, Controlname, Pagename, v)) Then Exit Function
    
    '-------------------------------------------------------------------------
    ' page: Interrupts
    '-------------------------------------------------------------------------
    If (Not OnShowPageInterrupts(ps, Controlname, Pagename, v)) Then Exit Function

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

    '-------------------------------------------------------------------------
    ' page: Functions2
    '-------------------------------------------------------------------------
    If (Not OnShowPageFunctions2(ps, Controlname, Pagename, v)) Then Exit Function
    '-------------------------------------------------------------------------
    ' page: Functions3
    '-------------------------------------------------------------------------
    If (Not OnShowPageFunctions3(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
    Dim i As Integer

    Dim cps As Variant
    Dim ctc As Variant
    Dim pcd As Variant
    Dim h As Variant

    Dim v() As Variant

    Dim r As ProjectData
    Dim sIndex As String
    Dim sPrefix As String

    sIndex = "ADC"
    sPrefix = sIndex & "_"

    Set r = ps.ProjectData
    
        '---------------------------------------------------------------------
        ' control: btnCh i (action)
        '---------------------------------------------------------------------
        For i = 0 To 7
          If (Controlname = "btnCh" & i) Then
            Set np = New Peripherals
            np.Parameters.Add ("x")
            np.Parameters.v("x") = ps.Parameters.v("x")
            np.Parameters.Add ("Number")
            np.Parameters.v("Number") = i
            Set np.ProjectData = ps.ProjectData
            np.Caption = "Configure ADC " & " Channel " & i
            np.Scriptfile = DefGetPath("Scripts") & "\ADC\CHANNEL.DAVE"
            np.Show
          End If
        Next i

    OnClick = True
    Exit Function

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




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

    OnMenuClick = False

    If (Not MenuClick(ps, Toolname, ToolId, Tooltext, "ADC\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
    
    Dim sIndex As String
    Dim sPrefix As String

    sIndex = "ADC"
    sPrefix = sIndex & "_"

  OnChangingPageModuleClock = False
      
      If (Not ps.ExtenderCollection("Module Clock").Loaded) And (Pagename = "Module Clock") Then
    
        ps.ExtenderCollection("Module Clock").Loaded = True
  
        '-------------------------------
        ' frame: frmMD
        '-------------------------------
        If (Not ps.AddFrame("frmAdcEn", 100, 100, 5400, 1375, " ADC Disabled Flag (PMCON1) ")) Then Exit Function
            If (Not ps.AddOption("optADC_DIS_0", 200, 350, 4800, 300, "Enable module; the peripheral is supplied with the clock signal")) Then Exit Function
            If (Not ps.AddOption("optADC_DIS_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 module [MHz]")) Then Exit Function
            If (Not ps.AddLabel("lbl_box_InputClock", 1, 3550, 400, 1000, 300, "")) Then Exit Function

      End If
'  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
    
    Dim sVarPre As String
    Dim sRegPre As String

  sVarPre = "ADC"
  sRegPre = sVarPre & "_"

  OnShowPageModuleClock = False
  
  Dim r           As ProjectData
  Dim c           As Object
  Dim e           As Object
  Dim bDisabled   As Boolean
  Dim vIndex As Variant
  
  Set r = ps.ProjectData
  Set c = ps.ControlCollection
  Set e = ps.ExtenderCollection
    
If (Pagename = "Module Clock") Then
  
      Select Case (Controlname)
      
         Case "optADC_DIS_0"
            r.v(SCU_PREFIX & "PMCON1_ADC_DIS") = 0
                r.v("ADC_USE_Init") = 0
            
         Case "optADC_DIS_1"
'            r.v(SCU_PREFIX & "PMCON1_ADC_DIS") = 1
'                r.v("ADC_USE_Init") = 0
                Call DisableADC(r)
      End Select
   

     With c("optADC_DIS_0")
         bDisabled = False
         .Enabled = Not (bDisabled)
         .Value = -CInt(r.v(SCU_PREFIX & "PMCON1_ADC_DIS") = 0)
         If (r.v(SCU_PREFIX & "PMCON1_ADC_DIS") = 0) Then
         
         End If
     End With

    With c("optADC_DIS_1")
         bDisabled = False
         .Enabled = Not (bDisabled)
         .Value = -CInt(r.v(SCU_PREFIX & "PMCON1_ADC_DIS") = 1)
         If (r.v(SCU_PREFIX & "PMCON1_ADC_DIS") = 1) Then
         End If
     End With
    
      With c("lbl_box_InputClock")
        bDisabled = (r.v(SCU_PREFIX & "PMCON1_ADC_DIS") = 1)
        .Enabled = Not (bDisabled)
          If (r.v(SCU_PREFIX & "PMCON1_ADC_DIS") = 1) Then
             .Caption = CALCULATION_NOT_POSSIBLE
           Else
             .Caption = Format(GetADCModuleClock(r), "00.000")
          End If
      End With
          
      With e("lbl_box_InputClock")
        If (bDisabled) Then
          .DisabledTooltipText = TOOLTIP_DISABLED_IF
          .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleClockDisabled(r, vIndex)
        End If
      End With

      With c("lbl_txt_InputClock")
        bDisabled = (r.v(SCU_PREFIX & "PMCON1_ADC_DIS") = 1)
        .Enabled = Not (bDisabled)
          If (r.v(SCU_PREFIX & "PMCON1_ADC_DIS") = 1) Then
          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 OnLoadPageGeneral(ps As Object) As Boolean
  On Error Resume Next

  OnLoadPageGeneral = False
  If (Not ps.AddPage("General")) Then Exit Function

  OnLoadPageGeneral = 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 OnChangingPageGeneral(ps As Object, Pagename As String) As Boolean
  On Error Resume Next
    
  OnChangingPageGeneral = False

  Dim vIndex As Variant
  Dim v As Variant
  Dim iTopOffset As Integer

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

    If (Not ps.AddFrame("frmClkControl", 120, 120, 4200, 1320, "Analog Part Clock Control (GLOBCTR.CTC)")) Then Exit Function
        If (Not ps.AddLabel("lblAnaClockDivider", 0, 120, 340, 1600, 385, "Analog Clock Divider")) Then Exit Function
        If (Not ps.AddCombo("cboAnaClockDivider", 1700, 300, 1100, 315)) Then Exit Function
        If (Not ps.AddLabel("lblADCI", 0, 2900, 300, 420, 385, "fADCI [MHz]")) Then Exit Function
        If (Not ps.AddLabel("lblboxADCI", 1, 3400, 300, 700, 315, "")) Then Exit Function
        If (Not ps.AddLabel("lblCovTime", 0, 800, 800, 2800, 385, "Total Conversion Time tCONV [" & TXT_US & "]")) Then Exit Function
        If (Not ps.AddLabel("lblboxCovTime", 1, 3400, 800, 700, 315, "")) Then Exit Function

    If (Not ps.AddFrame("frmConvResol", 120, 1560, 4200, 960, "Conversion Result Resolution (GLOBCTR.DW)")) Then Exit Function
        If (Not ps.AddOption("optConvResol0", 120, 240, 1600, 380, "10 Bit resolution")) Then Exit Function
        If (Not ps.AddOption("optConvResol1", 120, 560, 1600, 380, " 8 Bit resolution")) Then Exit Function
    
    If (Not ps.AddFrame("frmLimitCheck", 120, 2640, 4200, 960, "Limit Check Boundarys (LCBR)")) Then Exit Function
        If (Not ps.AddLabel("lblLimitCheck0", 0, 120, 240, 1575, 350, "Boundary 0")) Then Exit Function
        If (Not ps.AddText("txtLimitCheck0", 1500, 240, 600, 315)) Then Exit Function
        If (Not ps.AddLabel("lblLimitCheck1", 0, 120, 600, 1575, 350, "Boundary 1")) Then Exit Function
        If (Not ps.AddText("txtLimitCheck1", 1500, 600, 600, 315)) Then Exit Function
        
        If (Not ps.AddLabel("lblboundary", 0, 2600, 100, 1500, 350, "Actual Value")) Then Exit Function
        If (Not ps.AddLabel("lblActCheck0", 1, 2650, 300, 700, 250, "")) Then Exit Function
        If (Not ps.AddLabel("lblActCheck1", 1, 2650, 650, 700, 250, "")) Then Exit Function
        
    If (Not ps.AddFrame("frmArbitrationSlot", 4440, 120, 4200, 1320, "Arbitration Slot Functions (PRAR.ASENx)")) Then Exit Function
        If (Not ps.AddCheck("chkArbitrationSlot0", 120, 240, 3500, 380, "Enable arbitration slot 0 (Sequential source)")) Then Exit Function
        If (Not ps.AddCheck("chkArbitrationSlot1", 120, 700, 3200, 380, "Enable arbitration slot 1 (Parallel source)")) Then Exit Function
    
    If (Not ps.AddFrame("frmArbitrationMode", 4440, 1560, 4200, 960, "Arbitration Mode (PRAR.ARBM)")) Then Exit Function
        If (Not ps.AddOption("optArbitrationMode0", 240, 200, 1975, 380, "Permanent arbitration")) Then Exit Function
        If (Not ps.AddOption("optArbitrationMode1", 240, 550, 3840, 380, "Arbitration started by pending conversion request")) Then Exit Function

    If (Not ps.AddFrame("frmSampleTime", 4440, 2640, 4200, 960, "Sample Time Control (INPCR0.STC)")) Then Exit Function
        If (Not ps.AddLabel("lblSampleTime", 0, 120, 340, 1575, 385, "Sample time")) Then Exit Function
        If (Not ps.AddText("txtSampleTime", 1680, 340, 975, 315)) Then Exit Function

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

    Dim sVarPre As String
    Dim sRegPre As String

  sVarPre = "ADC"
  sRegPre = sVarPre & "_"

  OnShowPageGeneral = False
  
  Dim r As ProjectData
  Dim e As Object
  Dim bDisabled As Boolean
  Dim c As Collection
  Dim vIndex As Variant
  Dim i As Integer
  Dim temp_ctc As Integer
  
  Set r = ps.ProjectData
  Set e = ps.ExtenderCollection
  Set c = ps.ControlCollection

  If (Pagename = "General") Then
  
  Select Case (Controlname)
  
          Case "cboAnaClockDivider"
                temp_ctc = r.v(sRegPre & "GLOBCTR_CTC")
                r.v(sRegPre & "GLOBCTR_CTC") = c("cboAnaClockDivider").ListIndex
            If (IsClocktoohigh(r)) Then
                If (Ask("The internal clock for the analog part fADCI is limited to a maximum frequency of 10 MHz." & vbCrLf & _
                        "The fADCI frequency calculated would be : " & Get_fADCImsg(r) & _
                        ". All ADC configuration will be disabled." & vbCrLf & _
                        "Do you want to continue ?")) Then
                    r.v("ADC_USE_Init") = 0
                Else
                    r.v(sRegPre & "GLOBCTR_CTC") = temp_ctc
                End If
            End If
            
            
         Case "optConvResol0"
            r.v(sRegPre & "GLOBCTR_DW") = 0
            
         Case "optConvResol1"
            r.v(sRegPre & "GLOBCTR_DW") = 1
            
         Case "txtLimitCheck0"
            If (IsInputFormatOK(v(1), "", c("lblLimitCheck0").Caption, 0, 15)) Then
                r.v(sRegPre & "LCBR_BOUND0") = v(1)
           Else
             Exit Function
           End If
           
         Case "txtLimitCheck1"
            If (IsInputFormatOK(v(1), "", c("lblLimitCheck1").Caption, 0, 15)) Then
                r.v(sRegPre & "LCBR_BOUND1") = v(1)
           Else
             Exit Function
           End If
            
         Case "optArbitrationMode0"
            r.v(sRegPre & "PRAR_ARBM") = 0
            
         Case "optArbitrationMode1"
            r.v(sRegPre & "PRAR_ARBM") = 1
            
         Case "chkArbitrationSlot0"
            r.v(sRegPre & "PRAR_ASEN0") = v(1)
         
         Case "chkArbitrationSlot1"
            r.v(sRegPre & "PRAR_ASEN1") = v(1)

         Case "txtSampleTime"
            If (IsInputFormatOK(v(1), "", c("lblSampleTime").Caption, 0, 255)) Then
                r.v(sRegPre & "INPCR0_STC") = v(1)
           Else
             Exit Function
           End If

    End Select
'----------------------------------------------------------------
' On Show
'----------------------------------------------------------------
    
    With c("lblAnaClockDivider")
    bDisabled = ((r.v(SCU_PREFIX & "PMCON1_ADC_DIS") = 1))
       .Enabled = Not (bDisabled)
    End With
    
    With c("cboAnaClockDivider")
    bDisabled = ((r.v(SCU_PREFIX & "PMCON1_ADC_DIS") = 1))
        .Clear
        .Enabled = Not (bDisabled)
        .AddItem "fADC / 2 "
        .AddItem "fADC / 3 "
        .AddItem "fADC / 4 "
        .AddItem "fADC / 32 "
            .ListIndex = r.v(sRegPre & "GLOBCTR_CTC")
    End With
        
    With e("cboAnaClockDivider")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleClockDisabled(r, vIndex)
      End If
    End With
    
    With c("lblADCI")
    bDisabled = ((r.v(SCU_PREFIX & "PMCON1_ADC_DIS") = 1))
       .Enabled = Not (bDisabled)
    End With
    
    With c("lblboxADCI")
    bDisabled = ((r.v(SCU_PREFIX & "PMCON1_ADC_DIS") = 1))
       .Enabled = Not (bDisabled)
       .Caption = Format(Get_fADCI(r), "00.00")
    End With
    
    With c("lblCovTime")
    bDisabled = ((r.v(SCU_PREFIX & "PMCON1_ADC_DIS") = 1))
       .Enabled = Not (bDisabled)
    End With
    
    With c("lblboxCovTime")
    bDisabled = ((r.v(SCU_PREFIX & "PMCON1_ADC_DIS") = 1))
       .Enabled = Not (bDisabled)
       .Caption = Format(GetAdcConversionTime(r), "0.00")
    End With
    
    For i = 0 To 1
        bDisabled = (r.v(SCU_PREFIX & "PMCON1_ADC_DIS") = 1) Or IsClocktoohigh(r)
        
        With c("optConvResol" & i)
            .Enabled = Not (bDisabled)
            .Value = -CInt(r.v(sRegPre & "GLOBCTR_DW") = i)
        End With
        
        With e("optConvResol" & i)
          If (bDisabled) Then
              .DisabledTooltipText = GetTooltipModule(r, 0)
          End If
        End With
        
        With c("lblLimitCheck" & i)
           .Enabled = Not (bDisabled)
        End With
        
        With c("txtLimitCheck" & i)
           .Enabled = Not (bDisabled)
           .Text = FormatTextOutput(r.v(sRegPre & "LCBR_BOUND" & i), "H1")
        End With
        
        With e("txtLimitCheck" & i)
          If (bDisabled) Then
              .DisabledTooltipText = GetTooltipModule(r, 0)
          End If
        End With
        
        With c("lblActCheck" & i)
            If (r.v(sRegPre & "GLOBCTR_DW") = 0) Then
                .Caption = FormatTextOutput(r.v(sRegPre & "LCBR_BOUND" & i) * (&H40), "H3")
            Else
                .Caption = FormatTextOutput((r.v(sRegPre & "LCBR_BOUND" & i) * (&H10)), "H2")
            End If
        End With
        
         With c("optArbitrationMode" & i)
            .Enabled = Not (bDisabled)
            .Value = -CInt(r.v(sRegPre & "PRAR_ARBM") = i)
        End With
        
        With e("optArbitrationMode" & i)
          If (bDisabled) Then
              .DisabledTooltipText = GetTooltipModule(r, 0)
          End If
        End With
        
    Next i
    
        With c("chkArbitrationSlot0")
            .Enabled = Not (bDisabled)
            .Value = r.v(sRegPre & "PRAR_ASEN0")
        End With

        With e("chkArbitrationSlot0")
          If (bDisabled) Then
              .DisabledTooltipText = GetTooltipModule(r, 0)
          End If
        End With
        
        With c("chkArbitrationSlot1")
            .Enabled = Not (bDisabled)
            .Value = r.v(sRegPre & "PRAR_ASEN1")
        End With

        With e("chkArbitrationSlot1")
          If (bDisabled) Then
              .DisabledTooltipText = GetTooltipModule(r, 0)
          End If
        End With
    
        With c("lblSampleTime")
        bDisabled = (r.v(SCU_PREFIX & "PMCON1_ADC_DIS") = 1) Or IsClocktoohigh(r)
           .Enabled = Not (bDisabled)
        End With
    
        With c("txtSampleTime")
           .Enabled = Not (bDisabled)
           .Text = FormatTextOutput(r.v(sRegPre & "INPCR0_STC"), "H2")
        End With
 
        With e("txtSampleTime")
          If (bDisabled) Then
              .DisabledTooltipText = GetTooltipModule(r, 0)
          End If
        End With

  End If

  OnShowPageGeneral = True
  Exit Function

OnShowPageGeneralError:
  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
  
  If (Not ps.ExtenderCollection("Channels").Loaded) And (Pagename = "Channels") Then
    ps.ExtenderCollection("Channels").Loaded = True

    '-------------------------------
    ' frame: frmChannels
    '-------------------------------
    If (Not ps.AddFrame("frmChannels", 120, 120, 8520, 5160, "Channel Configuration")) Then Exit Function
        If (Not ps.AddButton("btnCh0", 240, 480, 1800, 315, "Configure Channel 0")) Then Exit Function
        If (Not ps.AddButton("btnCh1", 240, 1080, 1800, 315, "Configure Channel 1")) Then Exit Function
        If (Not ps.AddButton("btnCh2", 240, 1680, 1800, 315, "Configure Channel 2")) Then Exit Function
        If (Not ps.AddButton("btnCh3", 240, 2280, 1800, 315, "Configure Channel 3")) Then Exit Function
        If (Not ps.AddButton("btnCh4", 4320, 480, 1800, 315, "Configure Channel 4")) Then Exit Function
        If (Not ps.AddButton("btnCh5", 4320, 1080, 1800, 315, "Configure Channel 5")) Then Exit Function
        If (Not ps.AddButton("btnCh6", 4320, 1680, 1800, 315, "Configure Channel 6")) Then Exit Function
        If (Not ps.AddButton("btnCh7", 4320, 2280, 1800, 315, "Configure Channel 7")) Then Exit Function
        
        If (Not ps.AddCheck("chkUSE_CHANNEL_0", 2160, 480, 1920, 380, "Channel 0 is enabled")) Then Exit Function
        If (Not ps.AddCheck("chkUSE_CHANNEL_1", 2160, 1080, 1920, 380, "Channel 1 is enabled")) Then Exit Function
        If (Not ps.AddCheck("chkUSE_CHANNEL_2", 2160, 1680, 1975, 380, "Channel 2 is enabled")) Then Exit Function
        If (Not ps.AddCheck("chkUSE_CHANNEL_3", 2160, 2280, 1975, 380, "Channel 3 is enabled")) Then Exit Function
        If (Not ps.AddCheck("chkUSE_CHANNEL_4", 6240, 480, 1975, 380, "Channel 4 is enabled")) Then Exit Function
        If (Not ps.AddCheck("chkUSE_CHANNEL_5", 6240, 1080, 1975, 380, "Channel 5 is enabled")) Then Exit Function
        If (Not ps.AddCheck("chkUSE_CHANNEL_6", 6240, 1680, 1975, 380, "Channel 6 is enabled")) Then Exit Function
        If (Not ps.AddCheck("chkUSE_CHANNEL_7", 6240, 2280, 1975, 380, "Channel 7 is enabled")) Then Exit Function

  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 bDisabled As Boolean
  Dim vIndex As Variant
  Dim i As Variant
    
    Dim sVarPre As String
    Dim sRegPre As String

  sVarPre = "ADC"
  sRegPre = sVarPre & "_"

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

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

  If (Pagename = "Channels") Then

    '-------------------------------------------------------------------------
    ' page: Channels (show)
    '-------------------------------------------------------------------------
    
    For i = 0 To 7
      With c("btnCh" & i)
        bDisabled = IsModuleClockDisabled(r, vIndex) Or IsClocktoohigh(r) Or _
                    Not (r.v(sRegPre & "PRAR_ASEN0") = 1 Or r.v(sRegPre & "PRAR_ASEN1") = 1)
        .Enabled = Not (bDisabled)
      End With

      With e("btnCh" & i)
        If (bDisabled) Then
              .DisabledTooltipText = GetTooltipModule(r, 22)
        End If
      End With

      With c("chkUSE_CHANNEL_" & i)
        bDisabled = True
        .Enabled = Not (bDisabled)
        .Value = -CInt(r.v("ADC_USE_CHANNEL_" & i) = 1)
      End With

      With e("chkUSE_CHANNEL_" & i)
        .DisabledTooltipText = "This control is always disabled." & vbCrLf & "To enable the channel open the channels configuration dialog."
      End With
    Next i
  End If

  OnShowPageChannels = True
  Exit Function

OnShowPageChannelsError:
  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 OnLoadPageSequential(ps As Peripherals) As Boolean
  On Error Resume Next
  OnLoadPageSequential = False

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

  OnLoadPageSequential = 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 OnChangingPageSequential(ps As Peripherals, Pagename As String) As Boolean
  On Error Resume Next

  Dim i As Integer
  Dim aFunctions(1 To 16) As String
 Dim pos As Long

  OnChangingPageSequential = False

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

    '-------------------------------
    ' frame: frmGate
    '-------------------------------
    If (Not ps.AddFrame("frmSeqGate", 120, 120, 4200, 1100, "Enable Gate (QMR0.ENGT)")) Then Exit Function
        If (Not ps.AddOption("optSeqGate0", 120, 240, 4000, 380, "Gating line is permanently 0 (source is switched off)")) Then Exit Function
        If (Not ps.AddOption("optSeqGate1", 120, 620, 4000, 380, "Gating line is permanently 1 (source is switched on)")) Then Exit Function

'    '-------------------------------
'    ' frame: frmTrgMode
'    '-------------------------------
'    If (Not ps.AddFrame("frmTrgMode", 120, 1250, 4200, 1000, "Trigger Mode (QMR0.TRMD)")) Then Exit Function
'        If (Not ps.AddOption("optTrgMode0", 120, 240, 1975, 300, "Mode 0 is selected")) Then Exit Function
'        If (Not ps.AddOption("optTrgMode1", 120, 600, 1975, 300, "Mode 1 is selected")) Then Exit Function
    
    '-------------------------------
    ' frame: frmExtTrg
    '-------------------------------
    If (Not ps.AddFrame("frmSeqEventTrg", 120, 1250, 4200, 1000, "External Trigger (QMR0.ENTR)")) Then Exit Function
        If (Not ps.AddCheck("chkSeqEventTrg", 120, 340, 2400, 380, "Enable external trigger")) Then Exit Function

    If (Not ps.AddFrame("frmSeqSrcIntrPtr", 120, 2300, 4200, 1350, "Interrupt Node Pointer" & " [Event Interrupt 0]")) Then Exit Function
        If (Not ps.AddOption("optSeqIntr_0", 120, 340, 1500, 300, "SR0 Activated")) Then Exit Function
        If (Not ps.AddOption("optSeqIntr_1", 120, 750, 1500, 300, "SR1 Activated")) Then Exit Function

    If (Not ps.AddFrame("frmCntSrc0", 4440, 120, 4200, 1100, "Priority of Request Source 0 (PRAR.PRIO0)")) Then Exit Function
        If (Not ps.AddOption("optCntSrc0_0", 120, 240, 1400, 350, "Low priority")) Then Exit Function
        If (Not ps.AddOption("optCntSrc0_1", 120, 580, 1400, 350, "High priority")) Then Exit Function

    If (Not ps.AddFrame("frmCntConvStartMode0", 4440, 1250, 4200, 1000, "Conversion Start Mode Source 0 (PRAR.CSM0)")) Then Exit Function
        If (Not ps.AddOption("optCntConvStartRS0_Mode0", 120, 240, 2000, 380, "Wait-for-start mode")) Then Exit Function
        If (Not ps.AddOption("optCntConvStartRS0_Mode1", 120, 600, 2400, 380, "Cancel-inject-repeat mode")) Then Exit Function
    
    If (Not ps.AddFrame("frmCntExtTrgCnt_SR0", 4440, 2300, 4200, 1350, "External Trigger Control Source 0 (ETRCR.ETRSEL0)")) Then Exit Function
        If (Not ps.AddLabel("lblCntExtTrgCnt_SR0", 0, 120, 300, 1080, 385, "Trigger input")) Then Exit Function
        If (Not ps.AddCombo("cboCntExtTrgCnt_SR0", 1440, 300, 2000, 315)) Then Exit Function
        If (Not ps.AddCheck("chkCntExtTrgCnt_SR0", 120, 750, 2500, 380, "Enable synchronizing stage")) Then Exit Function

  End If

  OnChangingPageSequential = 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 OnShowPageSequential(ps As Peripherals, Controlname As String, Pagename As String, v() As Variant) As Boolean
  On Error GoTo OnShowPageSequentialError

  OnShowPageSequential = False
  
  Dim i As Integer
  Dim j As Integer
  Dim r As ProjectData
  Dim c As Collection
  Dim e As Collection
  Dim vIndex As Variant
  Dim bDisabled As Boolean
  Dim sName As String

  Dim sVarPre As String
  Dim sRegPre As String

  sVarPre = "ADC"
  sRegPre = sVarPre & "_"

  Set r = ps.ProjectData
  Set c = ps.ControlCollection
  Set e = ps.ExtenderCollection
  
  If (Pagename = "Sequential") Then

  Select Case (Controlname)
        Case "optSeqGate0"
            If (Not IsADC_SourceDisable(ps)) Then
                r.v(sRegPre & "QMR0_ENGT") = 0
            End If
          
        Case "optSeqGate1"
          r.v(sRegPre & "QMR0_ENGT") = 1

        Case "chkSeqEventTrg"
          r.v(sRegPre & "QMR0_ENTR") = v(1)
        
'        Case "optTrgMode0"
'          r.v(sRegPre & "QMR0_TRMD") = 0
'
'        Case "optTrgMode1"
'          r.v(sRegPre & "QMR0_TRMD") = 1
          
        Case "optCntSrc0_0"
            r.v(sRegPre & "PRAR_PRIO0") = 0
            
        Case "optCntSrc0_1"
            r.v(sRegPre & "PRAR_PRIO0") = 1

        Case "optCntConvStartRS0_Mode0"
            r.v(sRegPre & "PRAR_CSM0") = 0
        
        Case "optCntConvStartRS0_Mode1"
            r.v(sRegPre & "PRAR_CSM0") = 1

        Case "cboCntExtTrgCnt_SR0"
            r.v(sRegPre & "ETRCR_ETRSEL0") = c("cboCntExtTrgCnt_SR0").ListIndex

        Case "chkCntExtTrgCnt_SR0"
            r.v(sRegPre & "ETRCR_SYNEN0") = v(1)

        Case "chkSeqSrcIntr"
          r.v(sRegPre & "QINR0_ENSI") = v(1)
            Call IsInterruptEnabled(r)
            
        Case "optSeqIntr_0"
          r.v(sRegPre & "EVINPR_EVINP0") = 0

        Case "optSeqIntr_1"
          r.v(sRegPre & "EVINPR_EVINP0") = 1

End Select

    If (r.v("CCU6_USE_Init") = 0) Then
        r.v(sRegPre & "ETRCR_ETRSEL0") = 0
        r.v(sRegPre & "ETRCR_SYNEN0") = 0
    End If

    For i = 0 To 1
      bDisabled = (r.v(SCU_PREFIX & "PMCON1_ADC_DIS") = 1) Or IsClocktoohigh(r) Or _
                    Not (r.v(sRegPre & "PRAR_ASEN0") = 1)
      
      With c("optSeqGate" & i)
         .Enabled = Not (bDisabled)
         .Value = -CInt(r.v(sRegPre & "QMR0_ENGT") = i)
      End With

      With e("optSeqGate" & i)
        If (bDisabled) Then
              .DisabledTooltipText = GetTooltipModule(r, 1)
        End If
      End With
    Next i
      
'    For i = 0 To 1
'      bDisabled = (r.v(SCU_PREFIX & "PMCON1_ADC_DIS") = 1) Or IsClocktoohigh(r) Or _
'            r.v(sRegPre & "QMR0_ENGT") = 0 Or r.v(sRegPre & "PRAR_ASEN0") = 0
'
'      With c("optTrgMode" & i)
'         .Enabled = Not (bDisabled)
'         .Value = -CInt(r.v(sRegPre & "QMR0_TRMD") = i)
'      End With
'
'      With e("optTrgMode" & i)
'        If (bDisabled) Then
'              .DisabledToolTipText = GetTooltipModule(r, 4)
'        End If
'      End With
'    Next i
    
    If (r.v(sRegPre & "QMR0_ENTR") = 0) Then
        r.v(sRegPre & "ETRCR_ETRSEL0") = 0
        r.v(sRegPre & "ETRCR_SYNEN0") = 0
    End If
      With c("chkSeqEventTrg")
      bDisabled = (r.v(SCU_PREFIX & "PMCON1_ADC_DIS") = 1) Or IsClocktoohigh(r) Or _
            r.v(sRegPre & "QMR0_ENGT") = 0 Or r.v(sRegPre & "PRAR_ASEN0") = 0
         .Enabled = Not (bDisabled)
         .Value = r.v(sRegPre & "QMR0_ENTR")
      End With

      With e("chkSeqEventTrg")
        If (bDisabled) Then
              .DisabledTooltipText = GetTooltipModule(r, 4)
        End If
      End With
      
      For i = 0 To 1 ' Source 0
      
      bDisabled = (r.v(SCU_PREFIX & "PMCON1_ADC_DIS") = 1) Or IsClocktoohigh(r) Or _
            r.v(sRegPre & "QMR0_ENGT") = 0 Or r.v(sRegPre & "PRAR_ASEN0") = 0
      
      With c("optCntSrc0_" & i)
         .Enabled = Not (bDisabled)
         .Value = -CInt(r.v(sRegPre & "PRAR_PRIO0") = i)
      End With

      With e("optCntSrc0_" & i)
        If (bDisabled) Then
              .DisabledTooltipText = GetTooltipModule(r, 4)
        End If
      End With
  
      With c("optCntConvStartRS0_Mode" & i)
         .Enabled = Not (bDisabled)
         .Value = -CInt(r.v(sRegPre & "PRAR_CSM0") = i)
      End With

      With e("optCntConvStartRS0_Mode" & i)
        If (bDisabled) Then
              .DisabledTooltipText = GetTooltipModule(r, 4)
        End If
      End With
      
      Next i
      
      i = 0 ' Source 0
      bDisabled = (r.v(SCU_PREFIX & "PMCON1_ADC_DIS") = 1) Or IsClocktoohigh(r) Or _
                r.v(sRegPre & "QMR0_ENGT") = 0 Or r.v(sRegPre & "QMR0_ENTR") = 0 Or _
                r.v("CCU6_USE_Init") = 0 Or r.v(sRegPre & "PRAR_ASEN0") = 0
      
      With c("lblCntExtTrgCnt_SR" & i)
         .Enabled = Not (bDisabled)
      End With
    
      With c("cboCntExtTrgCnt_SR" & i)
            .Clear
            .Enabled = Not (bDisabled)
            For j = 0 To 7
            .AddItem " ETR" & i & j
            Next j
                .ListIndex = r.v(sRegPre & "ETRCR_ETRSEL" & i)
      End With
      
      With e("cboCntExtTrgCnt_SR" & i)
        If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (r.v(sRegPre & "PRAR_ASEN0") = 0) Then
              .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip(TOOLTIP_ADC_ARBSLOT0_DISABLED)
              ElseIf (r.v(sRegPre & "QMR0_ENGT") = 0) Then
              .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip(TOOLTIP_ADC_GATING_0)
              ElseIf ((r.v(sRegPre & "QMR0_ENTR") = 0) And (r.v("CCU6_USE_Init") = 0)) Then
                .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip(TOOLTIP_ADC_EXTR_TRG_DISABLED)
                .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip(TOOLTIP_ADC_CC6_DISABLED)
              ElseIf (r.v(sRegPre & "QMR0_ENTR") = 0) Then
                .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip(TOOLTIP_ADC_EXTR_TRG_DISABLED)
              ElseIf (r.v("CCU6_USE_Init") = 0) Then
                .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip(TOOLTIP_ADC_CC6_DISABLED)
              Else
                .DisabledTooltipText = GetTooltipModule(r, 4)
            End If
        End If
      End With
      
      With c("chkCntExtTrgCnt_SR" & i)
         .Enabled = Not (bDisabled)
         .Value = r.v(sRegPre & "ETRCR_SYNEN" & i)
      End With

      With e("chkCntExtTrgCnt_SR" & i)
        If (bDisabled) Then
              .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (r.v(sRegPre & "PRAR_ASEN0") = 0) Then
              .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip(TOOLTIP_ADC_ARBSLOT0_DISABLED)
              ElseIf (r.v(sRegPre & "QMR0_ENGT") = 0) Then
              .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip(TOOLTIP_ADC_GATING_0)
              ElseIf ((r.v(sRegPre & "QMR0_ENTR") = 0) And (r.v("CCU6_USE_Init") = 0)) Then
                .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip(TOOLTIP_ADC_EXTR_TRG_DISABLED)
                .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip(TOOLTIP_ADC_CC6_DISABLED)
              ElseIf (r.v(sRegPre & "QMR0_ENTR") = 0) Then
                .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip(TOOLTIP_ADC_EXTR_TRG_DISABLED)
              ElseIf (r.v("CCU6_USE_Init") = 0) Then
                .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip(TOOLTIP_ADC_CC6_DISABLED)
              Else
                .DisabledTooltipText = GetTooltipModule(r, 4)
            End If
        End If
      End With
      

     bDisabled = (r.v(SCU_PREFIX & "PMCON1_ADC_DIS") = 1) Or IsClocktoohigh(r) Or _
            r.v(sRegPre & "QMR0_ENGT") = 0 Or r.v(sRegPre & "PRAR_ASEN0") = 0

     For i = 0 To 1
      With c("optSeqIntr_" & i)
         .Enabled = Not (bDisabled)
         .Value = -CInt(r.v(sRegPre & "EVINPR_EVINP0") = i)
      End With

      With e("optSeqIntr_" & i)
        If (bDisabled) Then
              .DisabledTooltipText = GetTooltipModule(r, 4)
        End If
      End With
     Next i

  End If
  OnShowPageSequential = True
  Exit Function

OnShowPageSequentialError:
  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 OnLoadPageParallel(ps As Peripherals) As Boolean
  On Error Resume Next
  OnLoadPageParallel = False

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

  OnLoadPageParallel = 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 OnChangingPageParallel(ps As Peripherals, Pagename As String) As Boolean
  On Error Resume Next

  Dim i As Integer
  Dim aFunctions(1 To 16) As String
 Dim pos As Long
    
  OnChangingPageParallel = False

   If (Not ps.ExtenderCollection("Parallel").Loaded) And (Pagename = "Parallel") Then
    ps.ExtenderCollection("Parallel").Loaded = True
  
    '-------------------------------
    ' frame: frmGate
    '-------------------------------

    If (Not ps.AddFrame("frmGate", 120, 120, 4200, 1050, "Enable Gate (CRMR1.ENGT)")) Then Exit Function
        If (Not ps.AddOption("optGate0", 120, 240, 4000, 380, "Gating line is permanently 0 (source is switched off)")) Then Exit Function
        If (Not ps.AddOption("optGate1", 120, 620, 4000, 380, "Gating line is permanently 1 (source is switched on)")) Then Exit Function

    '-------------------------------
    ' frame: frmExtTrg
    '-------------------------------
    If (Not ps.AddFrame("frmExtTrg", 120, 1250, 4200, 900, "External Trigger (CRMR1.ENTR)")) Then Exit Function
        If (Not ps.AddCheck("chkExtTrg", 120, 240, 2200, 380, "Enable external trigger")) Then Exit Function

    '-------------------------------
    ' frame: frmAutoScan
    '-------------------------------
    If (Not ps.AddFrame("frmAutoScan", 120, 2200, 4200, 900, "Autoscan (CRMR1.SCAN)")) Then Exit Function
        If (Not ps.AddCheck("chkAutoscan", 120, 240, 1600, 380, "Enable autoscan")) Then Exit Function
    '-------------------------------
    ' frame: frmSrcIntr
    '-------------------------------
    If (Not ps.AddFrame("frmSrcIntr", 120, 3150, 4200, 900, "Source Interrupt (CRMR1.ENSI)" & " [Event Interrupt 1]")) Then Exit Function
        If (Not ps.AddCheck("chkSrcIntr", 120, 240, 1975, 380, "Enable source interrupt ")) Then Exit Function

    If (Not ps.AddFrame("frmCntSrc1", 4440, 120, 4200, 1050, "Priority of Request Source 1 (PRAR.PRIO1)")) Then Exit Function
        If (Not ps.AddOption("optCntSrc1_0", 120, 240, 1400, 350, "Low priority")) Then Exit Function
        If (Not ps.AddOption("optCntSrc1_1", 120, 580, 1400, 350, "High priority")) Then Exit Function

    If (Not ps.AddFrame("frmCntConvStartMode1", 4440, 1250, 4200, 1000, "Conversion Start Mode Source 1 (PRAR.CSM1)")) Then Exit Function
        If (Not ps.AddOption("optCntConvStartRS1_Mode0", 120, 240, 2000, 350, "Wait-for-start mode")) Then Exit Function
        If (Not ps.AddOption("optCntConvStartRS1_Mode1", 120, 550, 2400, 350, "Cancel-inject-repeat mode")) Then Exit Function

    If (Not ps.AddFrame("frmCntExtTrgCnt_SR1", 4440, 2325, 4200, 1080, "External Trigger Control Source 1 (ETRCR.ETRSEL1)")) Then Exit Function
        If (Not ps.AddLabel("lblCntExtTrgCnt_SR1", 0, 120, 240, 1575, 385, "Trigger input")) Then Exit Function
        If (Not ps.AddCombo("cboCntExtTrgCnt_SR1", 1440, 240, 2000, 315)) Then Exit Function
        If (Not ps.AddCheck("chkCntExtTrgCnt_SR1", 120, 600, 2500, 380, "Enable synchronizing stage ")) Then Exit Function

    If (Not ps.AddFrame("frmParSrcIntrPtr", 4440, 3450, 4200, 600, "Interrupt Node Pointer")) Then Exit Function
        If (Not ps.AddOption("optParIntr_0", 120, 180, 1500, 300, "SR0 Activated")) Then Exit Function
        If (Not ps.AddOption("optParIntr_1", 2100, 180, 1500, 300, "SR1 Activated")) Then Exit Function

  End If

  OnChangingPageParallel = 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 OnShowPageParallel(ps As Peripherals, Controlname As String, Pagename As String, v() As Variant) As Boolean
  On Error GoTo OnShowPageParallelError

  OnShowPageParallel = False
  Dim i As Integer
  Dim j As Integer
  Dim r As ProjectData
  Dim c As Collection
  Dim e As Collection
  Dim vIndex As Variant
  Dim bDisabled As Boolean
  Dim sName As String

  Dim sVarPre As String
  Dim sRegPre As String

  sVarPre = "ADC"
  sRegPre = sVarPre & "_"
  
  Set r = ps.ProjectData
  Set c = ps.ControlCollection
  Set e = ps.ExtenderCollection
  
  If (Pagename = "Parallel") Then

    Select Case (Controlname)
        Case "optGate0"
            If (Not IsADC_SourceDisable(ps)) Then
                r.v(sRegPre & "CRMR1_ENGT") = 0
            End If
    
        Case "optGate1"
          r.v(sRegPre & "CRMR1_ENGT") = 1
        
        Case "chkExtTrg"
          r.v(sRegPre & "CRMR1_ENTR") = v(1)
    
'        Case "chkSrcIntr"
'          r.v(sRegPre & "CRMR1_ENSI") = v(1)
'            Call IsInterruptEnabled(r)
         Case "chkSrcIntr"
            If (IsCpuTypeOK(r)) Then
              If (v(1) = 1) Then
                 'MsgBox MSG_SELECT_XINTR6_INTERRUPTS
                 If (r.v("INTR_MSGEN") = 1) Then
                      SharedInt = MsgBox(MSG_SELECT_XINTR6_INTERRUPTS, vbYesNo + vbQuestion, "DAvE")
                      If (SharedInt = 6) Then
                         r.v("INTR_MSGEN") = 1
                      ElseIf (SharedInt = 7) Then
                         r.v("INTR_MSGEN") = 0
                         SharedInt = MsgBox(MSGBOX_SHAREDINT_ENABLE, vbInformation, "DAvE")
                      End If
                 End If
                 r.v(sRegPre & "CRMR1_ENSI") = v(1)
                 Call IsInterruptEnabled(r)
              Else
                  r.v(sRegPre & "CRMR1_ENSI") = v(1)
                  Call IsInterruptEnabled(r)
              End If
            Else
               r.v(sRegPre & "CRMR1_ENSI") = v(1)
               Call IsInterruptEnabled(r)
            End If

        Case "chkAutoscan"
          r.v(sRegPre & "CRMR1_SCAN") = v(1)
    
        Case "optCntSrc1_0"
            r.v(sRegPre & "PRAR_PRIO1") = 0
        
        Case "optCntSrc1_1"
            r.v(sRegPre & "PRAR_PRIO1") = 1

        Case "optCntConvStartRS1_Mode0"
            r.v(sRegPre & "PRAR_CSM1") = 0

        Case "optCntConvStartRS1_Mode1"
            r.v(sRegPre & "PRAR_CSM1") = 1

        Case "cboCntExtTrgCnt_SR1"
            r.v(sRegPre & "ETRCR_ETRSEL1") = c("cboCntExtTrgCnt_SR1").ListIndex
            
        Case "chkCntExtTrgCnt_SR1"
            r.v(sRegPre & "ETRCR_SYNEN1") = v(1)

        Case "optParIntr_0"
          r.v(sRegPre & "EVINPR_EVINP1") = 0

        Case "optParIntr_1"
          r.v(sRegPre & "EVINPR_EVINP1") = 1

    End Select
    
    If (r.v("CCU6_USE_Init") = 0) Then
        r.v(sRegPre & "ETRCR_ETRSEL1") = 0
        r.v(sRegPre & "ETRCR_SYNEN1") = 0
    End If
    
    If (r.v(sRegPre & "CRMR1_ENSI") = 0) Then
          r.v(sRegPre & "EVINPR_EVINP1") = 0
    End If
    
      bDisabled = (r.v(SCU_PREFIX & "PMCON1_ADC_DIS") = 1) Or IsClocktoohigh(r) Or _
                    Not (r.v(sRegPre & "PRAR_ASEN1") = 1)
    For i = 0 To 1
      With c("optGate" & i)
         .Enabled = Not (bDisabled)
         .Value = -CInt(r.v(sRegPre & "CRMR1_ENGT") = i)
      End With

      With e("optGate" & i)
        If (bDisabled) Then
              .DisabledTooltipText = GetTooltipModule(r, 2)
        End If
      End With
    Next i
    
      With c("chkExtTrg")
      bDisabled = (r.v(SCU_PREFIX & "PMCON1_ADC_DIS") = 1) Or IsClocktoohigh(r) Or _
        r.v(sRegPre & "CRMR1_ENGT") = 0 Or r.v(sRegPre & "PRAR_ASEN1") = 0
         .Enabled = Not (bDisabled)
         .Value = r.v(sRegPre & "CRMR1_ENTR")
      End With

      With e("chkExtTrg")
        If (bDisabled) Then
              .DisabledTooltipText = GetTooltipModule(r, 3)
        End If
      End With
            
      With c("chkSrcIntr")
      bDisabled = (r.v(SCU_PREFIX & "PMCON1_ADC_DIS") = 1) Or IsClocktoohigh(r) Or _
        r.v(sRegPre & "CRMR1_ENGT") = 0 Or r.v(sRegPre & "PRAR_ASEN1") = 0
         .Enabled = Not (bDisabled)
         .Value = r.v(sRegPre & "CRMR1_ENSI")
      End With

      With e("chkSrcIntr")
        If (bDisabled) Then
              .DisabledTooltipText = GetTooltipModule(r, 3)
        End If
      End With
    
      With c("chkAutoscan")
      bDisabled = (r.v(SCU_PREFIX & "PMCON1_ADC_DIS") = 1) Or IsClocktoohigh(r) Or _
        r.v(sRegPre & "CRMR1_ENGT") = 0 Or r.v(sRegPre & "PRAR_ASEN1") = 0
         .Enabled = Not (bDisabled)
         .Value = r.v(sRegPre & "CRMR1_SCAN")
      End With

      With e("chkAutoscan")
        If (bDisabled) Then
              .DisabledTooltipText = GetTooltipModule(r, 3)
        End If
      End With
      
      For i = 0 To 1 ' Source 0
      
      bDisabled = (r.v(SCU_PREFIX & "PMCON1_ADC_DIS") = 1) Or IsClocktoohigh(r) Or _
        r.v(sRegPre & "CRMR1_ENGT") = 0 Or r.v(sRegPre & "PRAR_ASEN1") = 0
      
      With c("optCntSrc1_" & i)
         .Enabled = Not (bDisabled)
         .Value = -CInt(r.v(sRegPre & "PRAR_PRIO1") = i)
      End With

      With e("optCntSrc1_" & i)
        If (bDisabled) Then
              .DisabledTooltipText = GetTooltipModule(r, 3)
        End If
      End With
  
      With c("optCntConvStartRS1_Mode" & i)
         .Enabled = Not (bDisabled)
         .Value = -CInt(r.v(sRegPre & "PRAR_CSM1") = i)
      End With

      With e("optCntConvStartRS1_Mode" & i)
        If (bDisabled) Then
              .DisabledTooltipText = GetTooltipModule(r, 3)
        End If
      End With
      
      Next i
      
    If (r.v(sRegPre & "CRMR1_ENTR") = 0) Then
        r.v(sRegPre & "ETRCR_ETRSEL1") = 0
        r.v(sRegPre & "ETRCR_SYNEN1") = 0
    End If
      
      bDisabled = (r.v(SCU_PREFIX & "PMCON1_ADC_DIS") = 1) Or IsClocktoohigh(r) Or _
                    r.v(sRegPre & "CRMR1_ENTR") = 0 Or r.v(sRegPre & "CRMR1_ENGT") = 0 Or _
                    r.v("CCU6_USE_Init") = 0 Or r.v(sRegPre & "PRAR_ASEN1") = 0


      i = 1 ' Source 1
      With c("lblCntExtTrgCnt_SR" & i)
         .Enabled = Not (bDisabled)
      End With
    
      With c("cboCntExtTrgCnt_SR" & i)
            .Clear
            .Enabled = Not (bDisabled)
            For j = 0 To 7
            .AddItem " ETR" & i & j
            Next j
                .ListIndex = r.v(sRegPre & "ETRCR_ETRSEL" & i)
      End With
    
      With e("cboCntExtTrgCnt_SR" & i)
        If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
              If (r.v(sRegPre & "PRAR_ASEN1") = 0) Then
                .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip(TOOLTIP_ADC_ARBSLOT1_DISABLED)
                ElseIf (r.v(sRegPre & "CRMR1_ENGT") = 0) Then
                .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip(TOOLTIP_ADC_GATING_0)
                ElseIf ((r.v(sRegPre & "CRMR1_ENTR") = 0) And (r.v("CCU6_USE_Init") = 0)) Then
                .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip(TOOLTIP_ADC_EXTR_TRG_DISABLED)
                .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip(TOOLTIP_ADC_CC6_DISABLED)
                ElseIf (r.v(sRegPre & "CRMR1_ENTR") = 0) Then
                .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip(TOOLTIP_ADC_EXTR_TRG_DISABLED)
                ElseIf (r.v("CCU6_USE_Init") = 0) Then
                .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip(TOOLTIP_ADC_CC6_DISABLED)
              Else
                .DisabledTooltipText = GetTooltipModule(r, 3)
            End If
        End If
      End With
      
      With c("chkCntExtTrgCnt_SR" & i)
         .Enabled = Not (bDisabled)
         .Value = r.v(sRegPre & "ETRCR_SYNEN" & i)
      End With

      With e("chkCntExtTrgCnt_SR" & i)
        If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
              If (r.v(sRegPre & "PRAR_ASEN1") = 0) Then
                .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip(TOOLTIP_ADC_ARBSLOT1_DISABLED)
                ElseIf (r.v(sRegPre & "CRMR1_ENGT") = 0) Then
                .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip(TOOLTIP_ADC_GATING_0)
                ElseIf ((r.v(sRegPre & "CRMR1_ENTR") = 0) And (r.v("CCU6_USE_Init") = 0)) Then
                .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip(TOOLTIP_ADC_EXTR_TRG_DISABLED)
                .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip(TOOLTIP_ADC_CC6_DISABLED)
                ElseIf (r.v(sRegPre & "CRMR1_ENTR") = 0) Then
                .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip(TOOLTIP_ADC_EXTR_TRG_DISABLED)
                ElseIf (r.v("CCU6_USE_Init") = 0) Then
                .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip(TOOLTIP_ADC_CC6_DISABLED)
              Else
                .DisabledTooltipText = GetTooltipModule(r, 3)
            End If
        End If
      End With

      bDisabled = (r.v(SCU_PREFIX & "PMCON1_ADC_DIS") = 1) Or IsClocktoohigh(r) Or _
        r.v(sRegPre & "CRMR1_ENGT") = 0 Or r.v(sRegPre & "PRAR_ASEN1") = 0 Or _
        (r.v(sRegPre & "CRMR1_ENSI") = 0)

      For i = 0 To 1
      With c("optParIntr_" & i)
         .Enabled = Not (bDisabled)
         .Value = -CInt(r.v(sRegPre & "EVINPR_EVINP1") = i)
      End With

      With e("optParIntr_" & i)
        If (bDisabled) Then
              .DisabledTooltipText = TOOLTIP_DISABLED_IF
              If (r.v(sRegPre & "PRAR_ASEN1") = 0) Then
                .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip(TOOLTIP_ADC_ARBSLOT1_DISABLED)
                ElseIf (r.v(sRegPre & "CRMR1_ENGT") = 0) Then
                .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip(TOOLTIP_ADC_GATING_0)
                ElseIf (r.v(sRegPre & "CRMR1_ENSI") = 0) Then
                .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip(TOOLTIP_ADC_SRCINTR_DISABLED)
                Else
                .DisabledTooltipText = GetTooltipModule(r, 3)
              End If
        End If
      End With
     Next i

  End If
  OnShowPageParallel = True
  Exit Function

OnShowPageParallelError:
  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 OnLoadPageResultRegister(ps As Peripherals) As Boolean
  On Error Resume Next
  OnLoadPageResultRegister = False

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

  OnLoadPageResultRegister = 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 OnChangingPageResultRegister(ps As Peripherals, Pagename As String) As Boolean
  On Error Resume Next

  Dim i As Integer
  Dim aFunctions(1 To 16) As String
 Dim pos As Long

  OnChangingPageResultRegister = False

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

    '-------------------------------
    ' frame: frmResultRegister0
    '-------------------------------
    If (Not ps.AddFrame("frmResultRegister0", 120, 120, 4080, 1700, "Settings for Result Register 0 (RCR0)")) Then Exit Function
        If (Not ps.AddCheck("chkResultRegister0_Data", 120, 250, 2000, 300, "Enable data reduction")) Then Exit Function
        If (Not ps.AddCheck("chkResultRegister0_Intr", 120, 550, 3800, 300, "Enable interrupt" & " [Event Interrupt 4]")) Then Exit Function
        If (Not ps.AddCheck("chkResultRegister0_Wait", 120, 850, 2500, 300, "Enable wait-for-read mode")) Then Exit Function
        If (Not ps.AddCheck("chkResultRegister0_VF", 120, 1150, 3500, 300, "Reset valid flag register by read access")) Then Exit Function
    
    If (Not ps.AddFrame("frmRes0IntrPtr", 120, 2000, 4080, 600, "Interrupt Node Pointer")) Then Exit Function
        If (Not ps.AddOption("optRes0Intr_0", 120, 200, 1500, 300, "SR0 Activated")) Then Exit Function
        If (Not ps.AddOption("optRes0Intr_1", 2100, 200, 1500, 300, "SR1 Activated")) Then Exit Function

    '-------------------------------
    ' frame: frmResultRegister1
    '-------------------------------
    If (Not ps.AddFrame("frmResultRegister1", 120, 2760, 4080, 1700, "Settings for Result Register 1 (RCR1)")) Then Exit Function
        If (Not ps.AddCheck("chkResultRegister1_Data", 120, 250, 2000, 300, "Enable data reduction")) Then Exit Function
        If (Not ps.AddCheck("chkResultRegister1_Intr", 120, 550, 3800, 300, "Enable interrupt" & " [Event Interrupt 5]")) Then Exit Function
        If (Not ps.AddCheck("chkResultRegister1_Wait", 120, 850, 2500, 300, "Enable wait-for-read mode")) Then Exit Function
        If (Not ps.AddCheck("chkResultRegister1_VF", 120, 1150, 3500, 300, "Reset valid flag register by read access")) Then Exit Function
    
    If (Not ps.AddFrame("frmRes1IntrPtr", 120, 4600, 4080, 600, "Interrupt Node Pointer")) Then Exit Function
        If (Not ps.AddOption("optRes1Intr_0", 120, 200, 1500, 300, "SR0 Activated")) Then Exit Function
        If (Not ps.AddOption("optRes1Intr_1", 2100, 200, 1500, 300, "SR1 Activated")) Then Exit Function
    
    '-------------------------------
    ' frame: frmResultRegister2
    '-------------------------------
    If (Not ps.AddFrame("frmResultRegister2", 4440, 120, 4080, 1700, "Settings for Result Register 2 (RCR2)")) Then Exit Function
        If (Not ps.AddCheck("chkResultRegister2_Data", 120, 250, 2000, 300, "Enable data reduction")) Then Exit Function
        If (Not ps.AddCheck("chkResultRegister2_Intr", 120, 550, 3800, 300, "Enable interrupt" & " [Event Interrupt 6]")) Then Exit Function
        If (Not ps.AddCheck("chkResultRegister2_Wait", 120, 850, 2500, 300, "Enable wait-for-read mode")) Then Exit Function
        If (Not ps.AddCheck("chkResultRegister2_VF", 120, 1150, 3500, 300, "Reset valid flag register by read access")) Then Exit Function
    
    If (Not ps.AddFrame("frmRes2IntrPtr", 4440, 2000, 4080, 600, "Interrupt Node Pointer")) Then Exit Function
        If (Not ps.AddOption("optRes2Intr_0", 120, 200, 1500, 300, "SR0 Activated")) Then Exit Function
        If (Not ps.AddOption("optRes2Intr_1", 2100, 200, 1500, 300, "SR1 Activated")) Then Exit Function

    '-------------------------------
    ' frame: frmResultRegister3
    '-------------------------------
    If (Not ps.AddFrame("frmResultRegister3", 4440, 2760, 4080, 1700, "Settings for Result Register 3 (RCR3)")) Then Exit Function
        If (Not ps.AddCheck("chkResultRegister3_Data", 120, 250, 2000, 300, "Enable data reduction")) Then Exit Function
        If (Not ps.AddCheck("chkResultRegister3_Intr", 120, 550, 3800, 300, "Enable interrupt" & " [Event Interrupt 7]")) Then Exit Function
        If (Not ps.AddCheck("chkResultRegister3_Wait", 120, 850, 2500, 300, "Enable wait-for-read mode")) Then Exit Function
        If (Not ps.AddCheck("chkResultRegister3_VF", 120, 1150, 3500, 300, "Reset valid flag register by read access")) Then Exit Function
    
    If (Not ps.AddFrame("frmRes3IntrPtr", 4440, 4600, 4080, 600, "Interrupt Node Pointer")) Then Exit Function
        If (Not ps.AddOption("optRes3Intr_0", 120, 200, 1500, 300, "SR0 Activated")) Then Exit Function
        If (Not ps.AddOption("optRes3Intr_1", 2100, 200, 1500, 300, "SR1 Activated")) Then Exit Function

  End If

  OnChangingPageResultRegister = 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 OnShowPageResultRegister(ps As Peripherals, Controlname As String, Pagename As String, v() As Variant) As Boolean
  On Error GoTo OnShowPageResultRegisterError

  OnShowPageResultRegister = False
  Dim i As Integer
  Dim r As ProjectData
  Dim c As Collection
  Dim e As Collection
  Dim vIndex As Variant
  Dim bDisabled As Boolean
  Dim sName As String

    Dim sVarPre As String
    Dim sRegPre As String

  sVarPre = "ADC"
  sRegPre = sVarPre & "_"

  Set r = ps.ProjectData
  Set c = ps.ControlCollection
  Set e = ps.ExtenderCollection
  
If (Pagename = "ResultRegister") Then

    Select Case (Controlname)
        Case "chkResultRegister0_Data"
          r.v(sRegPre & "RCR0_DRCTR") = v(1)
        
'        Case "chkResultRegister0_Intr"
'          r.v(sRegPre & "RCR0_IEN") = v(1)
'            Call IsInterruptEnabled(r)
'
'
         Case "chkResultRegister0_Intr"
            If (IsCpuTypeOK(r)) Then
              If (v(1) = 1) Then
                 'MsgBox MSG_SELECT_XINTR6_INTERRUPTS
                 If (r.v("INTR_MSGEN") = 1) Then
                      SharedInt = MsgBox(MSG_SELECT_XINTR6_INTERRUPTS, vbYesNo + vbQuestion, "DAvE")
                      If (SharedInt = 6) Then
                         r.v("INTR_MSGEN") = 1
                      ElseIf (SharedInt = 7) Then
                         r.v("INTR_MSGEN") = 0
                         SharedInt = MsgBox(MSGBOX_SHAREDINT_ENABLE, vbInformation, "DAvE")
                      End If
                 End If
                 r.v(sRegPre & "RCR0_IEN") = v(1)
                 Call IsInterruptEnabled(r)
              Else
                 r.v(sRegPre & "RCR0_IEN") = v(1)
                 Call IsInterruptEnabled(r)
              End If
            Else
               r.v(sRegPre & "RCR0_IEN") = v(1)
               Call IsInterruptEnabled(r)
            End If
        Case "chkResultRegister0_Wait"
          r.v(sRegPre & "RCR0_WFR") = v(1)
          
        Case "chkResultRegister0_VF"
          r.v(sRegPre & "RCR0_VFCTR") = v(1)
        
        Case "chkResultRegister1_Data"
          r.v(sRegPre & "RCR1_DRCTR") = v(1)
        
'        Case "chkResultRegister1_Intr"
'          r.v(sRegPre & "RCR1_IEN") = v(1)
'            Call IsInterruptEnabled(r)
         Case "chkResultRegister1_Intr"
            If (IsCpuTypeOK(r)) Then
               If (v(1) = 1) Then
                  'MsgBox MSG_SELECT_XINTR6_INTERRUPTS
                  If (r.v("INTR_MSGEN") = 1) Then
                      SharedInt = MsgBox(MSG_SELECT_XINTR6_INTERRUPTS, vbYesNo + vbQuestion, "DAvE")
                      If (SharedInt = 6) Then
                         r.v("INTR_MSGEN") = 1
                      ElseIf (SharedInt = 7) Then
                         r.v("INTR_MSGEN") = 0
                         SharedInt = MsgBox(MSGBOX_SHAREDINT_ENABLE, vbInformation, "DAvE")
                      End If
                  End If
                  r.v(sRegPre & "RCR1_IEN") = v(1)
                  Call IsInterruptEnabled(r)
               Else
                  r.v(sRegPre & "RCR1_IEN") = v(1)
                  Call IsInterruptEnabled(r)
               End If
            Else
                r.v(sRegPre & "RCR1_IEN") = v(1)
                Call IsInterruptEnabled(r)
            End If
        Case "chkResultRegister1_Wait"
          r.v(sRegPre & "RCR1_WFR") = v(1)
          
        Case "chkResultRegister1_VF"
          r.v(sRegPre & "RCR1_VFCTR") = v(1)
          
        Case "chkResultRegister2_Data"
          r.v(sRegPre & "RCR2_DRCTR") = v(1)
        
'        Case "chkResultRegister2_Intr"
'          r.v(sRegPre & "RCR2_IEN") = v(1)
'            Call IsInterruptEnabled(r)
          Case "chkResultRegister2_Intr"
            If (IsCpuTypeOK(r)) Then
               If (v(1) = 1) Then
                  'MsgBox MSG_SELECT_XINTR6_INTERRUPTS
                  If (r.v("INTR_MSGEN") = 1) Then
                      SharedInt = MsgBox(MSG_SELECT_XINTR6_INTERRUPTS, vbYesNo + vbQuestion, "DAvE")
                      If (SharedInt = 6) Then
                         r.v("INTR_MSGEN") = 1
                      ElseIf (SharedInt = 7) Then
                         r.v("INTR_MSGEN") = 0
                         SharedInt = MsgBox(MSGBOX_SHAREDINT_ENABLE, vbInformation, "DAvE")
                      End If
                  End If
                  r.v(sRegPre & "RCR2_IEN") = v(1)
                  Call IsInterruptEnabled(r)
               Else
                 r.v(sRegPre & "RCR2_IEN") = v(1)
                 Call IsInterruptEnabled(r)
               End If
            Else
                r.v(sRegPre & "RCR2_IEN") = v(1)
                Call IsInterruptEnabled(r)
            End If
        Case "chkResultRegister2_Wait"
          r.v(sRegPre & "RCR2_WFR") = v(1)
          
        Case "chkResultRegister2_VF"
          r.v(sRegPre & "RCR2_VFCTR") = v(1)
          
        Case "chkResultRegister3_Data"
          r.v(sRegPre & "RCR3_DRCTR") = v(1)
        
'        Case "chkResultRegister3_Intr"
'          r.v(sRegPre & "RCR3_IEN") = v(1)
'            Call IsInterruptEnabled(r)
          
        Case "chkResultRegister3_Intr"
           If (IsCpuTypeOK(r)) Then
               If (v(1) = 1) Then
                  'MsgBox MSG_SELECT_XINTR6_INTERRUPTS
                  If (r.v("INTR_MSGEN") = 1) Then
                      SharedInt = MsgBox(MSG_SELECT_XINTR6_INTERRUPTS, vbYesNo + vbQuestion, "DAvE")
                      If (SharedInt = 6) Then
                         r.v("INTR_MSGEN") = 1
                      ElseIf (SharedInt = 7) Then
                         r.v("INTR_MSGEN") = 0
                         SharedInt = MsgBox(MSGBOX_SHAREDINT_ENABLE, vbInformation, "DAvE")
                      End If
                  End If
                  r.v(sRegPre & "RCR3_IEN") = v(1)
                  Call IsInterruptEnabled(r)
               Else
                  r.v(sRegPre & "RCR3_IEN") = v(1)
                  Call IsInterruptEnabled(r)
               End If
            Else
               r.v(sRegPre & "RCR3_IEN") = v(1)
               Call IsInterruptEnabled(r)
            End If
        Case "chkResultRegister3_Wait"
          r.v(sRegPre & "RCR3_WFR") = v(1)
          
        Case "chkResultRegister3_VF"
          r.v(sRegPre & "RCR3_VFCTR") = v(1)
        
        Case "optRes0Intr_0"
          r.v(sRegPre & "EVINPR_EVINP4") = 0

        Case "optRes0Intr_1"
          r.v(sRegPre & "EVINPR_EVINP4") = 1

        Case "optRes1Intr_0"
          r.v(sRegPre & "EVINPR_EVINP5") = 0

        Case "optRes1Intr_1"
          r.v(sRegPre & "EVINPR_EVINP5") = 1

        Case "optRes2Intr_0"
          r.v(sRegPre & "EVINPR_EVINP6") = 0

        Case "optRes2Intr_1"
          r.v(sRegPre & "EVINPR_EVINP6") = 1

        Case "optRes3Intr_0"
          r.v(sRegPre & "EVINPR_EVINP7") = 0

        Case "optRes3Intr_1"
          r.v(sRegPre & "EVINPR_EVINP7") = 1
        
    End Select
        If (r.v(sRegPre & "RCR0_IEN") = 0) Then
          r.v(sRegPre & "EVINPR_EVINP4") = 0
        End If

        If (r.v(sRegPre & "RCR1_IEN") = 0) Then
          r.v(sRegPre & "EVINPR_EVINP5") = 0
        End If

        If (r.v(sRegPre & "RCR2_IEN") = 0) Then
          r.v(sRegPre & "EVINPR_EVINP6") = 0
        End If

        If (r.v(sRegPre & "RCR3_IEN") = 0) Then
          r.v(sRegPre & "EVINPR_EVINP7") = 0
        End If

      bDisabled = (r.v(SCU_PREFIX & "PMCON1_ADC_DIS") = 1) Or IsClocktoohigh(r) Or _
                  Not (r.v(sRegPre & "QMR0_ENGT") = 1 Or r.v(sRegPre & "CRMR1_ENGT") = 1) Or _
                  Not (r.v(sRegPre & "PRAR_ASEN0") = 1 Or r.v(sRegPre & "PRAR_ASEN1") = 1)
    For i = 0 To 3
     
      With c("chkResultRegister" & i & "_Data")
         .Enabled = Not (bDisabled)
         .Value = r.v(sRegPre & "RCR" & i & "_DRCTR")
      End With

      With e("chkResultRegister" & i & "_Data")
        If (bDisabled) Then
              .DisabledTooltipText = GetTooltipModule(r, 44)
        End If
      End With
      
      With c("chkResultRegister" & i & "_Intr")
         .Enabled = Not (bDisabled)
         .Value = r.v(sRegPre & "RCR" & i & "_IEN")
      End With

      With e("chkResultRegister" & i & "_Intr")
        If (bDisabled) Then
              .DisabledTooltipText = GetTooltipModule(r, 44)
        End If
      End With

      With c("chkResultRegister" & i & "_Wait")
         .Enabled = Not (bDisabled)
         .Value = r.v(sRegPre & "RCR" & i & "_WFR")
      End With

      With e("chkResultRegister" & i & "_Wait")
        If (bDisabled) Then
              .DisabledTooltipText = GetTooltipModule(r, 44)
        End If
      End With

      With c("chkResultRegister" & i & "_VF")
         .Enabled = Not (bDisabled)
         .Value = r.v(sRegPre & "RCR" & i & "_VFCTR")
      End With

      With e("chkResultRegister" & i & "_VF")
        If (bDisabled) Then
              .DisabledTooltipText = GetTooltipModule(r, 44)
        End If
      End With
      
    Next i
      
      bDisabled = (r.v(SCU_PREFIX & "PMCON1_ADC_DIS") = 1) Or IsClocktoohigh(r) Or _
                  Not (r.v(sRegPre & "QMR0_ENGT") = 1 Or r.v(sRegPre & "CRMR1_ENGT") = 1) Or _
                  Not (r.v(sRegPre & "PRAR_ASEN0") = 1 Or r.v(sRegPre & "PRAR_ASEN1") = 1) Or _
                  r.v(sRegPre & "RCR0_IEN") = 0
      For i = 0 To 1
      With c("optRes0Intr_" & i)
         .Enabled = Not (bDisabled)
         .Value = -CInt(r.v(sRegPre & "EVINPR_EVINP4") = i)
      End With

      With e("optRes0Intr_" & i)
        If (bDisabled) Then
              .DisabledTooltipText = GetTooltipModule(r, 48)
        End If
      End With
      Next i

      bDisabled = (r.v(SCU_PREFIX & "PMCON1_ADC_DIS") = 1) Or IsClocktoohigh(r) Or _
                  Not (r.v(sRegPre & "QMR0_ENGT") = 1 Or r.v(sRegPre & "CRMR1_ENGT") = 1) Or _
                  Not (r.v(sRegPre & "PRAR_ASEN0") = 1 Or r.v(sRegPre & "PRAR_ASEN1") = 1) Or _
                  r.v(sRegPre & "RCR1_IEN") = 0

      For i = 0 To 1
      With c("optRes1Intr_" & i)
         .Enabled = Not (bDisabled)
         .Value = -CInt(r.v(sRegPre & "EVINPR_EVINP5") = i)
      End With

      With e("optRes1Intr_" & i)
        If (bDisabled) Then
              .DisabledTooltipText = GetTooltipModule(r, 48)
        End If
      End With
      Next i

      bDisabled = (r.v(SCU_PREFIX & "PMCON1_ADC_DIS") = 1) Or IsClocktoohigh(r) Or _
                  Not (r.v(sRegPre & "QMR0_ENGT") = 1 Or r.v(sRegPre & "CRMR1_ENGT") = 1) Or _
                  Not (r.v(sRegPre & "PRAR_ASEN0") = 1 Or r.v(sRegPre & "PRAR_ASEN1") = 1) Or _
                  r.v(sRegPre & "RCR2_IEN") = 0

      For i = 0 To 1
      With c("optRes2Intr_" & i)
         .Enabled = Not (bDisabled)
         .Value = -CInt(r.v(sRegPre & "EVINPR_EVINP6") = i)
      End With

      With e("optRes2Intr_" & i)
        If (bDisabled) Then
              .DisabledTooltipText = GetTooltipModule(r, 48)
        End If
      End With
      Next i

      bDisabled = (r.v(SCU_PREFIX & "PMCON1_ADC_DIS") = 1) Or IsClocktoohigh(r) Or _
                  Not (r.v(sRegPre & "QMR0_ENGT") = 1 Or r.v(sRegPre & "CRMR1_ENGT") = 1) Or _
                  Not (r.v(sRegPre & "PRAR_ASEN0") = 1 Or r.v(sRegPre & "PRAR_ASEN1") = 1) Or _
                  r.v(sRegPre & "RCR3_IEN") = 0

      For i = 0 To 1
      With c("optRes3Intr_" & i)
         .Enabled = Not (bDisabled)
         .Value = -CInt(r.v(sRegPre & "EVINPR_EVINP7") = i)
      End With

      With e("optRes3Intr_" & i)
        If (bDisabled) Then
              .DisabledTooltipText = GetTooltipModule(r, 48)
        End If
      End With
     Next i

  End If
  OnShowPageResultRegister = True
  Exit Function

OnShowPageResultRegisterError:
  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 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 pos As Long
 Dim r As ProjectData
  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, 4400, 800, CAPTION_FRA_USE_INIT)) Then Exit Function
      If (Not ps.AddCheck("chkADC_USE_Init", 200, 250, 2100, 325, "ADC_vInit")) Then Exit Function
      If (Not ps.AddText("txtADC_NAME_Init", 2300, 250, 1800, 315)) Then Exit Function

    '-------------------------------
    ' frame: fra_CFile
    '-------------------------------
    If (Not ps.AddFrame("fra_CFile", 4600, 100, 3950, 800, CAPTION_FRA_CFILE)) Then Exit Function
      If (Not ps.AddText("txtADC_CFile", 1600, 280, 2100, 325)) Then Exit Function
      If (Not ps.AddLabel("lblADC_CFile", 0, 200, 250, 1250, 275, CAPTION_LBL_CFILE)) Then Exit Function

    '-------------------------------
    ' frame: fraLibrary1
    '-------------------------------
    If (Not ps.AddFrame("fraFunLibrary1", 100, 950, 8475, 700, "Function Library")) Then Exit Function
    pos = 0
    ' Functions and Macros
    'If (Not ps.AddCheck("chkADC_USE_Isr", 200, 270 + pos * 300, 1000, 380, "ADC_vIsr")) Then Exit Function
    If (IsCpuTypeOK(r)) Then
       If (Not ps.AddCheck("chkADC_USE_Isr", 200, 270 + pos * 300, 2000, 380, "SHINT_viXINTR6Isr")) Then Exit Function
    Else
       If (Not ps.AddCheck("chkADC_USE_Isr", 200, 270 + pos * 300, 1000, 380, "ADC_vIsr")) Then Exit Function
    End If
    
    
    If (Not ps.AddText("txtADC_NAME_Isr", 4500, 300 + pos * 300, 3800, 315)) Then Exit Function
    If (Not ps.AddFrame("fraFunLibrary2", 100, 1700, 8475, 3700, "Function Library (Sequential Source)")) Then Exit Function
    pos = 0
    
    If (Not ps.AddCheck("chkADC_USE_SeqCEV", 200, 270 + pos * 300, 1400, 380, "ADC_vClearEV")) Then Exit Function
    If (Not ps.AddText("txtADC_NAME_SeqCEV", 4500, 300 + pos * 300, 3800, 315)) Then Exit Function
    pos = pos + 1
    
    If (Not ps.AddCheck("chkADC_USE_SeqTREV", 200, 270 + pos * 300, 2000, 380, "ADC_vSeqSoftTrig")) Then Exit Function
    If (Not ps.AddText("txtADC_NAME_SeqTREV", 4500, 300 + pos * 300, 3800, 315)) Then Exit Function
    pos = pos + 1
    
    If (Not ps.AddCheck("chkADC_USE_SeqFLUSH", 200, 270 + pos * 300, 2400, 380, "ADC_vQueFlush")) Then Exit Function
    If (Not ps.AddText("txtADC_NAME_SeqFLUSH", 4500, 300 + pos * 300, 3800, 315)) Then Exit Function
    pos = pos + 1

    If (Not ps.AddCheck("chkADC_USE_SeqCLRV", 200, 270 + pos * 300, 2500, 380, "ADC_vClearVBits")) Then Exit Function
    If (Not ps.AddText("txtADC_NAME_SeqCLRV", 4500, 300 + pos * 300, 3800, 315)) Then Exit Function
    pos = pos + 1

    If (Not ps.AddCheck("chkADC_USE_SeqREQCHNR", 200, 270 + pos * 300, 2500, 380, "ADC_vStartSeqReqChNum")) Then Exit Function
    If (Not ps.AddText("txtADC_NAME_SeqREQCHNR", 4500, 300 + pos * 300, 3800, 315)) Then Exit Function
    pos = pos + 1

    If (Not ps.AddCheck("chkADC_USE_SeqSrcFillLevel", 200, 270 + pos * 300, 2300, 380, "ADC_ubGetSeqSrcFillLevel")) Then Exit Function
    If (Not ps.AddText("txtADC_NAME_SeqSrcFillLevel", 4500, 300 + pos * 300, 3800, 315)) Then Exit Function
    pos = pos + 1

    If (Not ps.AddCheck("chkADC_USE_SeqSrcEvent", 200, 270 + pos * 300, 2300, 380, "ADC_ubGetSeqSrcEvent")) Then Exit Function
    If (Not ps.AddText("txtADC_NAME_SeqSrcEvent", 4500, 300 + pos * 300, 3800, 315)) Then Exit Function
    pos = pos + 1

    If (Not ps.AddCheck("chkADC_USE_SeqSrcQueueEmpty", 200, 270 + pos * 300, 2900, 380, "ADC_ubGetQueueEmpty")) Then Exit Function
    If (Not ps.AddText("txtADC_NAME_SeqSrcQueueEmpty", 4500, 300 + pos * 300, 3800, 315)) Then Exit Function
    pos = pos + 1

    If (Not ps.AddCheck("chkADC_USE_SeqSrcReqChNum", 200, 270 + pos * 300, 2600, 380, "ADC_ubGetQueueReqChNum")) Then Exit Function
    If (Not ps.AddText("txtADC_NAME_SeqSrcReqChNum", 4500, 300 + pos * 300, 3800, 315)) Then Exit Function
    pos = pos + 1
        
    If (Not ps.AddCheck("chkADC_USE_SeqSrcReqChValid", 200, 270 + pos * 300, 2600, 380, "ADC_ubGetSeqReqChValid")) Then Exit Function
    If (Not ps.AddText("txtADC_NAME_SeqSrcReqChValid", 4500, 300 + pos * 300, 3800, 315)) Then Exit Function
    pos = pos + 1
       
    If (Not ps.AddCheck("chkADC_USE_SeqSrcQueExtTrg", 200, 270 + pos * 300, 2800, 380, "ADC_ubGetQueueExternalTrigger")) Then Exit Function
    If (Not ps.AddText("txtADC_NAME_SeqSrcQueExtTrg", 4500, 300 + pos * 300, 3800, 315)) Then Exit Function
    
  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 i As Integer
  Dim j As Integer
  Dim r As ProjectData
  Dim c As Collection
  Dim e As Collection
  Dim bDisabled As Boolean
  Dim func As FunctionClass
  Dim sName As String
  Dim vIndex As Variant

    Dim sVarPre As String
    Dim sRegPre As String

  sVarPre = "ADC"
  sRegPre = sVarPre & "_"

  Set r = ps.ProjectData
  Set c = ps.ControlCollection
  Set e = ps.ExtenderCollection
  Set func = New FunctionClass
  
If (Pagename = "Functions") Then
    Call RefreshFunctionDescriptions(func, r)

  Select Case Controlname
        Case "chkADC_USE_Init"
            r.v("ADC_USE_Init") = v(1)
                     
        Case "txtADC_NAME_Init"
            If (IsInputFormatOK(v(1), FORMAT_FUNCTIONS, c("chkADC_USE_Init").Caption)) Then
                r.v("ADC_NAME_Init") = v(1)
            Else
                Exit Function
            End If
        
        Case "txtADC_CFile"
            If (IsInputFormatOK(v(1), FORMAT_FILES, c("lblADC_CFile").Caption)) Then
                r.v("ADC_CFile") = v(1)
            Else
               Exit Function
            End If
    End Select     ' case Controlname
    
        If ((r.v(SCU_PREFIX & "PMCON1_ADC_DIS") = 1) Or _
              (r.v(sRegPre & "PRAR_ASEN0") = 0) And (r.v(sRegPre & "PRAR_ASEN1") = 0) Or _
              (r.v(sRegPre & "QMR0_ENGT") = 0) And (r.v(sRegPre & "CRMR1_ENGT") = 0)) Then
            r.v("ADC_USE_Init") = 0
        End If

    If (Not UpdateFunction(ps, Controlname, v, "Isr")) Then Exit Function
    
    If (Not UpdateFunction(ps, Controlname, v, "SeqCEV")) Then Exit Function
    If (Not UpdateFunction(ps, Controlname, v, "SeqTREV")) Then Exit Function
    If (Not UpdateFunction(ps, Controlname, v, "SeqFLUSH")) Then Exit Function
    If (Not UpdateFunction(ps, Controlname, v, "SeqCLRV")) Then Exit Function
    If (Not UpdateFunction(ps, Controlname, v, "SeqREQCHNR")) Then Exit Function
    If (Not UpdateFunction(ps, Controlname, v, "SeqSrcFillLevel")) Then Exit Function
    If (Not UpdateFunction(ps, Controlname, v, "SeqSrcEvent")) Then Exit Function
    If (Not UpdateFunction(ps, Controlname, v, "SeqSrcQueueEmpty")) Then Exit Function
    If (Not UpdateFunction(ps, Controlname, v, "SeqSrcReqChNum")) Then Exit Function
    If (Not UpdateFunction(ps, Controlname, v, "SeqSrcReqChValid")) Then Exit Function
    If (Not UpdateFunction(ps, Controlname, v, "SeqSrcQueExtTrg")) Then Exit Function
    
    '-------------------------------------------------------------------------
    ' page: Functions (show)
    '-------------------------------------------------------------------------
    Call RefreshFunctionDescriptions(func, r)

    '-------------------------------------------------------------------------
    ' control: chkADC_USE_Init (show)
    '-------------------------------------------------------------------------
    bDisabled = (r.v(SCU_PREFIX & "PMCON1_ADC_DIS") = 1) Or _
                 Not (((r.v(sRegPre & "QMR0_ENGT") = 1) And (r.v(sRegPre & "PRAR_ASEN0") = 1)) Or _
                 ((r.v(sRegPre & "CRMR1_ENGT") = 1) And (r.v(sRegPre & "PRAR_ASEN1") = 1)))
'    bDisabled = (r.v(SCU_PREFIX & "PMCON1_ADC_DIS") = 1)
    
    c("chkADC_USE_Init").Enabled = Not bDisabled
    c("chkADC_USE_Init").Value = -CInt(r.v("ADC_USE_Init") = 1)
    
    With e("chkADC_USE_Init")
        If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (IsModuleClockDisabled(r, "")) Then
                .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleClockDisabled(r, vIndex)
            ElseIf (IsClocktoohigh(r)) Then
                .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleClocktooHigh(r)
            ElseIf Not (r.v(sRegPre & "PRAR_ASEN0") = 1 Or r.v(sRegPre & "PRAR_ASEN1") = 1) Then
                .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip("the arbitration slot is not enabled")
            ElseIf ((r.v(sRegPre & "CRMR1_ENGT") = 0) Or (r.v(sRegPre & "QMR0_ENGT") = 0)) Then
                .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip("the sequential or parallel source is not enabled")
            End If
        Else
            .EnabledTooltipText = FormatFunctionToolTip(r, func, "ADC_NAME_Init")
        End If
    End With

    '-------------------------------------------------------------------------
    ' control: txtADC_NAME_Init (show)
    '-------------------------------------------------------------------------
    With c("txtADC_NAME_Init")
        bDisabled = (r.v("ADC_USE_Init") = 0)
        .Enabled = Not bDisabled
        .Text = FormatTextOutput(r.s("ADC_NAME_Init"), "S")
    End With

    With e("txtADC_NAME_Init")
        If (bDisabled) Then
               .DisabledTooltipText = FormatNormalToolTip(TOOLTIP_DISABLED_FUNC_NAME)
        End If
    End With
  
    If (Not ShowFunction(ps, v, func, "Isr")) Then Exit Function
    
    If (Not ShowFunction(ps, v, func, "SeqCEV")) Then Exit Function
    If (Not ShowFunction(ps, v, func, "SeqTREV")) Then Exit Function
    
    If (Not ShowFunction(ps, v, func, "SeqFLUSH")) Then Exit Function
    If (Not ShowFunction(ps, v, func, "SeqCLRV")) Then Exit Function
    If (Not ShowFunction(ps, v, func, "SeqREQCHNR")) Then Exit Function
    If (Not ShowFunction(ps, v, func, "SeqSrcFillLevel")) Then Exit Function
    If (Not ShowFunction(ps, v, func, "SeqSrcEvent")) Then Exit Function
    If (Not ShowFunction(ps, v, func, "SeqSrcQueueEmpty")) Then Exit Function
    If (Not ShowFunction(ps, v, func, "SeqSrcReqChNum")) Then Exit Function
    If (Not ShowFunction(ps, v, func, "SeqSrcReqChValid")) Then Exit Function
    If (Not ShowFunction(ps, v, func, "SeqSrcQueExtTrg")) Then Exit Function

    '-------------------------------------------------------------------------
    ' control: txtADC_CFile (show)
    '-------------------------------------------------------------------------

    With c("lblADC_CFile")
        bDisabled = (r.v("ADC_USE_Init") = 0)
        .Enabled = Not bDisabled
    End With

    With e("lblADC_CFile")
        If (bDisabled) Then
            .DisabledTooltipText = FormatNormalToolTip(TOOLTIP_DISABLED_CFILE_NAME)
        End If
    End With

    With c("txtADC_CFile")
        bDisabled = (r.v("ADC_USE_Init") = 0)
        .Enabled = Not bDisabled
        .Text = FormatTextOutput(r.v("ADC_CFile"), "S")
    End With

    With e("txtADC_CFile")
        If (bDisabled) Then
            .DisabledTooltipText = FormatNormalToolTip(TOOLTIP_DISABLED_CFILE_NAME)
        End If
    End With

  End If
  OnShowPageFunctions = True
  Exit Function

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

'Functions2
'*****************************************************************************
'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 OnLoadPageFunctions2(ps As Peripherals) As Boolean
  On Error Resume Next
  OnLoadPageFunctions2 = False

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

  OnLoadPageFunctions2 = 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 OnChangingPageFunctions2(ps As Peripherals, Pagename As String) As Boolean
  On Error Resume Next

 Dim pos As Long
 
  OnChangingPageFunctions2 = False

  If (Not ps.ExtenderCollection("Functions(2)").Loaded) And (Pagename = "Functions(2)") Then
    ps.ExtenderCollection("Functions(2)").Loaded = True
  
    '-------------------------------
    ' frame: fraLibrary2
    '-------------------------------
    If (Not ps.AddFrame("fraFunLibrary3", 100, 100, 8475, 1550, "Function Library (Parallel Source)")) Then Exit Function
    pos = 0

    ' Functions and Macros
    If (Not ps.AddCheck("chkADC_USE_ParLDEV", 200, 200 + pos * 300, 2100, 380, "ADC_vSetLoadEvent")) Then Exit Function
    If (Not ps.AddText("txtADC_NAME_ParLDEV", 4500, 200 + pos * 300, 3800, 315)) Then Exit Function
    pos = pos + 1
    
    If (Not ps.AddCheck("chkADC_USE_ParCLRPND", 200, 200 + pos * 300, 2100, 380, "ADC_vClearPendingBits")) Then Exit Function
    If (Not ps.AddText("txtADC_NAME_ParCLRPND", 4500, 200 + pos * 300, 3800, 315)) Then Exit Function
    pos = pos + 1

    If (Not ps.AddCheck("chkADC_USE_ParREQCH", 200, 200 + pos * 300, 2400, 380, "ADC_vStartParReqChNum")) Then Exit Function
    If (Not ps.AddText("txtADC_NAME_ParREQCH", 4500, 200 + pos * 300, 3800, 315)) Then Exit Function
    pos = pos + 1
    
    If (Not ps.AddCheck("chkADC_USE_ParConvPending", 200, 200 + pos * 300, 2400, 380, "ADC_ubGetParConvChNum")) Then Exit Function
    If (Not ps.AddText("txtADC_NAME_ParConvPending", 4500, 200 + pos * 300, 3800, 315)) Then Exit Function
    
    
    If (Not ps.AddFrame("fraFunLibrary4", 100, 1700, 8475, 3650, "")) Then Exit Function
    pos = 0
   
  
    If (Not ps.AddCheck("chkADC_USE_Busy", 200, 200 + pos * 300, 2400, 380, "ADC_ubBusy")) Then Exit Function
    If (Not ps.AddText("txtADC_NAME_Busy", 4500, 200 + pos * 300, 3800, 315)) Then Exit Function
    pos = pos + 1
    
    If (Not ps.AddCheck("chkADC_USE_SamplePhase", 200, 200 + pos * 300, 2400, 380, "ADC_ubSamplePhase")) Then Exit Function
    If (Not ps.AddText("txtADC_NAME_SamplePhase", 4500, 200 + pos * 300, 3800, 315)) Then Exit Function
    pos = pos + 1
    
    If (Not ps.AddCheck("chkADC_USE_GetConvChNum", 200, 200 + pos * 300, 2400, 380, "ADC_ubGetConvChNum")) Then Exit Function
    If (Not ps.AddText("txtADC_NAME_GetConvChNum", 4500, 200 + pos * 300, 3800, 315)) Then Exit Function
    pos = pos + 1
    
'    If (Not ps.AddCheck("chkADC_USE_ReadResultData", 200, 200 + pos * 300, 2400, 380, "ADC_uwGetResultData")) Then Exit Function
'    If (Not ps.AddText("txtADC_NAME_ReadResultData", 4500, 200 + pos * 300, 3800, 315)) Then Exit Function
'    pos = pos + 1
'
'    If (Not ps.AddCheck("chkADC_USE_ReadResultChNum", 200, 200 + pos * 300, 2400, 380, "ADC_ubGetResultChNum")) Then Exit Function
'    If (Not ps.AddText("txtADC_NAME_ReadResultChNum", 4500, 200 + pos * 300, 3800, 315)) Then Exit Function
'    pos = pos + 1
    
    If (Not ps.AddCheck("chkADC_USE_ClrValidFlag", 200, 200 + pos * 300, 2400, 380, "ADC_vClearValidFlag")) Then Exit Function
    If (Not ps.AddText("txtADC_NAME_ClrValidFlag", 4500, 200 + pos * 300, 3800, 315)) Then Exit Function
    pos = pos + 1
    
    
    If (Not ps.AddCheck("chkADC_USE_GetChIntrFlag", 200, 200 + pos * 300, 2500, 380, "ADC_ubGetChInterruptFlag")) Then Exit Function
    If (Not ps.AddText("txtADC_NAME_GetChIntrFlag", 4500, 200 + pos * 300, 3800, 315)) Then Exit Function
    pos = pos + 1

    If (Not ps.AddCheck("chkADC_USE_SetChIntr", 200, 200 + pos * 300, 2500, 380, "ADC_vSetChInterruptFlag")) Then Exit Function
    If (Not ps.AddText("txtADC_NAME_SetChIntr", 4500, 200 + pos * 300, 3800, 315)) Then Exit Function
    pos = pos + 1

    If (Not ps.AddCheck("chkADC_USE_ClrChIntr", 200, 200 + pos * 300, 2500, 380, "ADC_vClearChInterruptFlag")) Then Exit Function
    If (Not ps.AddText("txtADC_NAME_ClrChIntr", 4500, 200 + pos * 300, 3800, 315)) Then Exit Function
    pos = pos + 1

    If (Not ps.AddCheck("chkADC_USE_GetEventIntrFlag", 200, 200 + pos * 300, 2500, 380, "ADC_ubGetEventInterruptFlag")) Then Exit Function
    If (Not ps.AddText("txtADC_NAME_GetEventIntrFlag", 4500, 200 + pos * 300, 3800, 315)) Then Exit Function
    pos = pos + 1

    If (Not ps.AddCheck("chkADC_USE_SetEventIntr", 200, 200 + pos * 300, 2500, 380, "ADC_vSetEventInterruptFlag")) Then Exit Function
    If (Not ps.AddText("txtADC_NAME_SetEventIntr", 4500, 200 + pos * 300, 3800, 315)) Then Exit Function
    pos = pos + 1

    If (Not ps.AddCheck("chkADC_USE_ClrEventIntrFlag", 200, 200 + pos * 300, 2500, 300, "ADC_vClearEventInterruptFlag")) Then Exit Function
    If (Not ps.AddText("txtADC_NAME_ClrEventIntrFlag", 4500, 200 + pos * 300, 3800, 300)) Then Exit Function
    pos = pos + 1
        
  End If

  OnChangingPageFunctions2 = 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 OnShowPageFunctions2(ps As Peripherals, Controlname As String, Pagename As String, v() As Variant) As Boolean
  On Error GoTo OnShowPageFunctions2Error

  OnShowPageFunctions2 = False
    
  Dim r As ProjectData
  Dim c As Collection
  Dim e As Collection
  Dim bDisabled As Boolean
  Dim func As FunctionClass
  Dim sName As String

  Set r = ps.ProjectData
  Set c = ps.ControlCollection
  Set e = ps.ExtenderCollection
  Set func = New FunctionClass
  
If (Pagename = "Functions(2)") Then
    Call RefreshFunctionDescriptions(func, r)
    
    If (Not UpdateFunction(ps, Controlname, v, "ParLDEV")) Then Exit Function
    If (Not UpdateFunction(ps, Controlname, v, "ParCLRPND")) Then Exit Function
    If (Not UpdateFunction(ps, Controlname, v, "ParREQCH")) Then Exit Function
    If (Not UpdateFunction(ps, Controlname, v, "ParConvPending")) Then Exit Function
    
    If (Not UpdateFunction(ps, Controlname, v, "Busy")) Then Exit Function
    If (Not UpdateFunction(ps, Controlname, v, "SamplePhase")) Then Exit Function
    If (Not UpdateFunction(ps, Controlname, v, "GetConvChNum")) Then Exit Function
'    If (Not UpdateFunction(ps, Controlname, v, "ReadResultData")) Then Exit Function
'    If (Not UpdateFunction(ps, Controlname, v, "ReadResultChNum")) Then Exit Function
    If (Not UpdateFunction(ps, Controlname, v, "ClrValidFlag")) Then Exit Function

    If (Not UpdateFunction(ps, Controlname, v, "GetChIntrFlag")) Then Exit Function
    If (Not UpdateFunction(ps, Controlname, v, "SetChIntr")) Then Exit Function
    If (Not UpdateFunction(ps, Controlname, v, "ClrChIntr")) Then Exit Function
    If (Not UpdateFunction(ps, Controlname, v, "GetEventIntrFlag")) Then Exit Function
    If (Not UpdateFunction(ps, Controlname, v, "SetEventIntr")) Then Exit Function
    If (Not UpdateFunction(ps, Controlname, v, "ClrEventIntrFlag")) Then Exit Function
    '-------------------------------------------------------------------------
    ' page: Functions2 (show)
    '-------------------------------------------------------------------------
    Call RefreshFunctionDescriptions(func, r)
    '-------------------------------------------------------------------------
    ' control: chkADC_USE_Init (show)
    '-------------------------------------------------------------------------
    bDisabled = ((r.v(SCU_PREFIX & "PMCON1_ADC_DIS") = 0)) And (r.v("ADC_USE_Init") = 1)


    If (Not ShowFunction(ps, v, func, "ParLDEV")) Then Exit Function
    If (Not ShowFunction(ps, v, func, "ParCLRPND")) Then Exit Function
    If (Not ShowFunction(ps, v, func, "ParREQCH")) Then Exit Function
    If (Not ShowFunction(ps, v, func, "ParConvPending")) Then Exit Function
    
    If (Not ShowFunction(ps, v, func, "Busy")) Then Exit Function
    If (Not ShowFunction(ps, v, func, "SamplePhase")) Then Exit Function
    If (Not ShowFunction(ps, v, func, "GetConvChNum")) Then Exit Function
'    If (Not ShowFunction(ps, v, func, "ReadResultData")) Then Exit Function
'    If (Not ShowFunction(ps, v, func, "ReadResultChNum")) Then Exit Function
    If (Not ShowFunction(ps, v, func, "ClrValidFlag")) Then Exit Function
    
    If (Not ShowFunction(ps, v, func, "GetChIntrFlag")) Then Exit Function
    If (Not ShowFunction(ps, v, func, "SetChIntr")) Then Exit Function
    If (Not ShowFunction(ps, v, func, "ClrChIntr")) Then Exit Function
    If (Not ShowFunction(ps, v, func, "GetEventIntrFlag")) Then Exit Function
    If (Not ShowFunction(ps, v, func, "SetEventIntr")) Then Exit Function
    If (Not ShowFunction(ps, v, func, "ClrEventIntrFlag")) Then Exit Function

  End If
  OnShowPageFunctions2 = True
  Exit Function

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

'Functions3
'*****************************************************************************
'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 OnLoadPageFunctions3(ps As Peripherals) As Boolean
  On Error Resume Next
  OnLoadPageFunctions3 = False

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

  OnLoadPageFunctions3 = 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 OnChangingPageFunctions3(ps As Peripherals, Pagename As String) As Boolean
  On Error Resume Next

 Dim pos As Long
 
  OnChangingPageFunctions3 = False

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

    If (Not ps.AddFrame("fraFunLibrary5", 100, 100, 8475, 2800, "Function Library (Result)")) Then Exit Function
    pos = 0

    ' Functions and Macros
    If (Not ps.AddCheck("chkADC_USE_ReadResultData0", 200, 200 + pos * 300, 2500, 380, "ADC_uwGetResultData0")) Then Exit Function
    If (Not ps.AddText("txtADC_NAME_ReadResultData0", 4500, 200 + pos * 300, 3800, 315)) Then Exit Function
    pos = pos + 1

    If (Not ps.AddCheck("chkADC_USE_ReadResultData1", 200, 200 + pos * 300, 2500, 380, "ADC_uwGetResultData1")) Then Exit Function
    If (Not ps.AddText("txtADC_NAME_ReadResultData1", 4500, 200 + pos * 300, 3800, 315)) Then Exit Function
    pos = pos + 1

    If (Not ps.AddCheck("chkADC_USE_ReadResultData2", 200, 200 + pos * 300, 2500, 380, "ADC_uwGetResultData2")) Then Exit Function
    If (Not ps.AddText("txtADC_NAME_ReadResultData2", 4500, 200 + pos * 300, 3800, 315)) Then Exit Function
    pos = pos + 1

    If (Not ps.AddCheck("chkADC_USE_ReadResultData3", 200, 200 + pos * 300, 2500, 380, "ADC_uwGetResultData3")) Then Exit Function
    If (Not ps.AddText("txtADC_NAME_ReadResultData3", 4500, 200 + pos * 300, 3800, 315)) Then Exit Function
    pos = pos + 1

    If (Not ps.AddCheck("chkADC_USE_ReadResultChNum0", 200, 200 + pos * 300, 2500, 380, "ADC_ubGetResultChNum0")) Then Exit Function
    If (Not ps.AddText("txtADC_NAME_ReadResultChNum0", 4500, 200 + pos * 300, 3800, 315)) Then Exit Function
    pos = pos + 1
    
    If (Not ps.AddCheck("chkADC_USE_ReadResultChNum1", 200, 200 + pos * 300, 2500, 380, "ADC_ubGetResultChNum1")) Then Exit Function
    If (Not ps.AddText("txtADC_NAME_ReadResultChNum1", 4500, 200 + pos * 300, 3800, 315)) Then Exit Function
    pos = pos + 1
  
    If (Not ps.AddCheck("chkADC_USE_ReadResultChNum2", 200, 200 + pos * 300, 2500, 380, "ADC_ubGetResultChNum2")) Then Exit Function
    If (Not ps.AddText("txtADC_NAME_ReadResultChNum2", 4500, 200 + pos * 300, 3800, 315)) Then Exit Function
    pos = pos + 1
  
    If (Not ps.AddCheck("chkADC_USE_ReadResultChNum3", 200, 200 + pos * 300, 2500, 380, "ADC_ubGetResultChNum3")) Then Exit Function
    If (Not ps.AddText("txtADC_NAME_ReadResultChNum3", 4500, 200 + pos * 300, 3800, 315)) Then Exit Function
    pos = pos + 1
  
  End If

  OnChangingPageFunctions3 = 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 OnShowPageFunctions3(ps As Peripherals, Controlname As String, Pagename As String, v() As Variant) As Boolean
  On Error GoTo OnShowPageFunctions3Error

  OnShowPageFunctions3 = False
    
  Dim r As ProjectData
  Dim c As Collection
  Dim e As Collection
  Dim bDisabled As Boolean
  Dim func As FunctionClass
  Dim sName As String

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

If (Pagename = "Functions(3)") Then
    Call RefreshFunctionDescriptions(func, r)

    If (Not UpdateFunction(ps, Controlname, v, "ReadResultData0")) Then Exit Function
    If (Not UpdateFunction(ps, Controlname, v, "ReadResultData1")) Then Exit Function
    If (Not UpdateFunction(ps, Controlname, v, "ReadResultData2")) Then Exit Function
    If (Not UpdateFunction(ps, Controlname, v, "ReadResultData3")) Then Exit Function
    
    If (Not UpdateFunction(ps, Controlname, v, "ReadResultChNum0")) Then Exit Function
    If (Not UpdateFunction(ps, Controlname, v, "ReadResultChNum1")) Then Exit Function
    If (Not UpdateFunction(ps, Controlname, v, "ReadResultChNum2")) Then Exit Function
    If (Not UpdateFunction(ps, Controlname, v, "ReadResultChNum3")) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: Functions2 (show)
    '-------------------------------------------------------------------------
    Call RefreshFunctionDescriptions(func, r)
    '-------------------------------------------------------------------------
    ' control: chkADC_USE_Init (show)
    '-------------------------------------------------------------------------
    bDisabled = ((r.v(SCU_PREFIX & "PMCON1_ADC_DIS") = 0)) And (r.v("ADC_USE_Init") = 1)


    If (Not ShowFunction(ps, v, func, "ReadResultData0")) Then Exit Function
    If (Not ShowFunction(ps, v, func, "ReadResultData1")) Then Exit Function
    If (Not ShowFunction(ps, v, func, "ReadResultData2")) Then Exit Function
    If (Not ShowFunction(ps, v, func, "ReadResultData3")) Then Exit Function
    
    If (Not ShowFunction(ps, v, func, "ReadResultChNum0")) Then Exit Function
    If (Not ShowFunction(ps, v, func, "ReadResultChNum1")) Then Exit Function
    If (Not ShowFunction(ps, v, func, "ReadResultChNum2")) Then Exit Function
    If (Not ShowFunction(ps, v, func, "ReadResultChNum3")) Then Exit Function

  End If
  OnShowPageFunctions3 = True
  Exit Function

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

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

  Dim r As ProjectData
  Dim c As Collection

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

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

  '---------------------------------------------------------------------
  ' control: txtADC_NAME_.. (action)
  '---------------------------------------------------------------------
  If (Controlname = "txtADC_NAME_" & sName) Then
    If (IsInputFormatOK(v(1), FORMAT_FUNCTIONS, c("chkADC_USE_" & sName).Caption)) Then
        r.v("ADC_NAME_" & sName) = v(1)
    Else
        Exit Function
    End If
  End If

  UpdateFunction = True
ExitLabel:
End Function


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

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

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

        Case "Isr"      ' ISR functions are always disabled
            bDisabled = True
        
        Case Else
            bDisabled = (r.v("ADC_USE_Init") = 0)

    End Select

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


  With e("chkADC_USE_" & sName)
    If (bDisabled) Then
        ' tooltip if control is disabled
        Select Case sName
            
            Case "Isr"      ' ISR functions are always disabled
                .DisabledTooltipText = TOOLTIP_DISABLED_ISR & vbCrLf & FormatFunctionToolTip(r, func, "ADC_NAME_" & sName)

            Case Else
                If (IsModuleClockDisabled(r, vIndex)) Then
                      .DisabledTooltipText = TOOLTIP_DISABLED_IF
                      .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleClockDisabled(r, vIndex)
                Else
                    .DisabledTooltipText = GetDisabledFunctionToolTipEntry(func, "ADC_NAME_" & sName)
                    .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
                End If
        End Select
    Else
        ' tooltip if control is enabled
        .EnabledTooltipText = FormatFunctionToolTip(r, func, "ADC_NAME_" & sName)
    End If
  End With

  '-------------------------------------------------------------------------
  ' control: txtADC_NAME_... (show)
  '-------------------------------------------------------------------------
  With c("txtADC_NAME_" & sName)
    bDisabled = c("chkADC_USE_" & sName).Value = 0
    '.Enabled = Not bDisabled
    If ((sName = "Isr") And (IsCpuTypeOK(r))) Then
       '.Enabled = bDisabled
        .Enabled = False  ' Added by jag on 6/4/6 in order to make function name to be disabled even if the interrupt is not selected.
    Else
       .Enabled = Not bDisabled
    End If
    .Text = FormatTextOutput(r.s("ADC_NAME_" & sName), "S")
  End With

  With e("txtADC_NAME_" & sName)
    If (bDisabled) Then
        '.DisabledToolTipText = FormatNormalToolTip(TOOLTIP_DISABLED_FUNC_NAME)
        If ((sName = "Isr") And (IsCpuTypeOK(r))) Then
          .DisabledTooltipText = FormatNormalToolTip(TOOLTIP_DISABLED_FUNC_SHAREDISR)
        Else
          .DisabledTooltipText = FormatNormalToolTip(TOOLTIP_DISABLED_FUNC_NAME)
        End If
    End If
  End With

  ShowFunction = True
ExitLabel:
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 e As Collection
  Dim iChannel As Long

  OnChangingPageParameters = False

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

    '-------------------------------------------------------------------------
    ' frame: frmCAPCOMx_HFile
    '-------------------------------------------------------------------------
    If (Not ps.AddFrame("fraADC_HFile", 100, 100, 4150, 700, CAPTION_FRA_HFILE)) Then Exit Function
      If (Not ps.AddText("txtADC_HFile", 1475, 250, 2500, 325)) Then Exit Function
      If (Not ps.AddLabel("lblADC_HFile", 0, 200, 300, 1250, 300, CAPTION_LBL_HFILE)) Then Exit Function
        
    If (Not ps.AddFrame("fraParameters1", 100, 900, 4150, 4400, CAPTION_FRA_PARAMETERS1)) Then Exit Function
    ' Functions and Macros
      For iChannel = 0 To 7
       If (Not ps.AddLabel("lblChannel" & iChannel, 0, 200, 370 + iChannel * 300, 1575, 380, "CHANNEL_" & iChannel)) Then Exit Function
        If (Not ps.AddText("txtChannel" & iChannel, 1825, 300 + iChannel * 300, 1900, 315)) Then Exit Function
      Next iChannel
  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 bDisabled As Boolean
  Dim iChannel As Integer

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


  If (Pagename = "Parameters") Then
    '-------------------------------------------------------------------------
    ' page: Parameters (action)
    '-------------------------------------------------------------------------
    Select Case Controlname
        Case "txtADC_HFile"
            If (IsInputFormatOK(v(1), FORMAT_FILES, c("lblADC_HFile").Caption)) Then
                r.v("ADC_HFile") = v(1)
            End If

        Case Else
            For iChannel = 0 To 7
                If (Controlname = "txtChannel" & iChannel) Then
                    If (IsInputFormatOK(v(1), FORMAT_PARAMETERS, c("lblChannel" & iChannel).Caption)) Then
                        r.v("ADC_PARA_CHANNEL_" & iChannel) = v(1)
                    Else
                        Exit Function
                    End If
                End If
            Next iChannel
    
    End Select

    '-------------------------------------------------------------------------
    ' page: Parameters (show)
    '-------------------------------------------------------------------------
    '-------------------------------------------------------------------------
    ' control: lblADC_HFile (show)
    '-------------------------------------------------------------------------
    With c("lblADC_HFile")
      bDisabled = (r.v("ADC_USE_Init") = 0)
      .Enabled = Not bDisabled
    End With

    With e("lblADC_HFile")
      If (bDisabled) Then
        .DisabledTooltipText = FormatNormalToolTip(TOOLTIP_DISABLED_HFILE_NAME)
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: txtADC_HFile (show)
    '-------------------------------------------------------------------------
    With c("txtADC_HFile")
      bDisabled = (r.v("ADC_USE_Init") = 0)
      .Enabled = Not bDisabled
      .Text = FormatTextOutput(r.v("ADC_HFile"), "S")
    End With

    With e("txtADC_HFile")
      If (bDisabled) Then
        .DisabledTooltipText = FormatNormalToolTip(TOOLTIP_DISABLED_HFILE_NAME)
      End If
    End With

    '-------------------------------------------------------------------------
    For iChannel = 0 To 7

        bDisabled = (r.v("ADC_USE_Init") = 0) Or (r.v("ADC_USE_CHANNEL_" & iChannel) = 0)
        With c("txtChannel" & iChannel)
            .Enabled = Not bDisabled
            .Text = FormatTextOutput(r.v("ADC_PARA_CHANNEL_" & iChannel), "S")
        End With
        With e("txtChannel" & iChannel)
            If (bDisabled) Then
                .DisabledTooltipText = TOOLTIP_DISABLED_PARAMETER
                If (r.v("ADC_USE_Init") = 0) Then
                    .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
                End If
                If (r.v("ADC_USE_CHANNEL_" & iChannel) = 0) Then
                    .DisabledTooltipText = .DisabledTooltipText & _
                    FormatDisabledToolTip("analog input AN" & iChannel & " is not used")
                End If
            End If
        End With
        c("lblChannel" & iChannel).Enabled = Not bDisabled

    Next iChannel

  End If         ' if Pagename

  OnShowPageParameters = True
  Exit Function

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