'#Uses "..\classes\FunctionClass.cls"
'#Uses "..\classes\ParameterClass.cls
'#Uses "..\include\Const.inc"
'#Uses "..\include\Format.inc"
'#Uses "..\include\Global.inc"
'#Uses "..\include\Pages.inc"
'#Uses "..\include\Port.inc"
'#Uses "include.inc"

Option Explicit

'*****************************************************************************
' Module:
'        ASC
'-----------------------------------------------------------------------------
' Description:
'        This file contains functions which are create controls for the
'        module 'ASC'.
'        Furthermore it contains functions for the event handling of
'        these controls.
'
'-----------------------------------------------------------------------------
' History:
'                 
'        Rev. Author         Date        Description
'        ---------------------------------------------------------------------
'        1.0  rkt            10.12.99    initialize version
'        1.1  ste            04.02.00    final version
'        1.2  ste            09.03.00    - new handling for pages "Functions" and 
'                                          "Parameters" added
'                                        - IrDA mode deleted
'
'        1.3  ahe            08.10.00    final version
'                                        automatic calculation of FDV
'                                        - changes action chkFDE 
'                                        - changes show txtFD_Value 
'
'        1.4  ste            14.11.00    register names changed:
'                                        _SRCTB   =>   _TBSRC
'                                        _SRCT    =>   _TSRC
'                                        _SRCR    =>   _RSRC
'                                        _SRCE    =>   _ESRC
'                                        _BG_RL   =>   _BG_BR_VALUE
'                                        _FDV_FD  =>   _FDV_FD_VALUE
'                                        _RBUF_RD =>   _RBUF_RD_VALUE
'                                        _TBUF_TD =>   _TBUF_TD_VALUE
'                                        xxCLC_RMC now with 255 divider
'        ---------------------------------------------------------------------
'        3.0  ste            25.01.01    final version for S-GOLDv1
'
'        ---------------------------------------------------------------------
'        4.0  ahe            14.02.01    final version for Pegasus
'
'        4.1  ahe            08.08.02     - neu interrupt page
'                                         - changed page name
'        4.2  ste            24.02.03    caption for module clock changed
'
'*****************************************************************************

Const TOOLTIP_DISABLED_IF_ASYNC_MODE_SELECTED =  "the asynchronous mode is selected"
Const TOOLTIP_DISABLED_IF_SYNC_MODE_SELECTED =   "the synchronous mode is selected"


'*****************************************************************************
'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: Module Clock
    '-------------------------------------------------------------------------
    If (Not OnLoadPageModuleClock(ps)) Then Exit Function

    '-------------------------------------------------------------------------
    'page: Pin Selection
    '-------------------------------------------------------------------------
    If (Not OnLoadPagePinSelection (ps)) Then Exit Function

    '-------------------------------------------------------------------------
    'page: Autobaud
    '-------------------------------------------------------------------------
    If (Not OnLoadPageAutobaud (ps)) Then Exit Function

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

    '-------------------------------------------------------------------------
    ' page: FIFO
    '-------------------------------------------------------------------------
    If (Not OnLoadPageFIFO(ps)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: BaudrateASCx
    '-------------------------------------------------------------------------
    If (Not OnLoadPageBaudrateASCx(ps)) Then Exit Function

    '-------------------------------------------------------------------------
    'page: IrDA
    '-------------------------------------------------------------------------
    If (Not OnLoadPageIrDA (ps)) Then Exit Function

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

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

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

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

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

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

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

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

    OnChangingPage = False
    
    '-------------------------------------------------------------------------
    'page: Module Clock
    '-------------------------------------------------------------------------
    If (Not OnChangingPageModuleClock (ps, Pagename)) Then Exit Function

    '-------------------------------------------------------------------------
    'page: Pin Selection
    '-------------------------------------------------------------------------
    If (Not OnChangingPagePinSelection (ps, Pagename)) Then Exit Function

    '-------------------------------------------------------------------------
    'page: Autobaud
    '-------------------------------------------------------------------------
    If (Not OnChangingPageAutobaud (ps, Pagename)) Then Exit Function

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

    '-------------------------------------------------------------------------
    'page: FIFO
    '-------------------------------------------------------------------------
    If (Not OnChangingPageFIFO (ps, Pagename)) Then Exit Function

    '-------------------------------------------------------------------------
    'page: BaudrateASCx
    '-------------------------------------------------------------------------
    If (Not OnChangingPageBaudrateASCx (ps, Pagename)) Then Exit Function

    '-------------------------------------------------------------------------
    'page: IrDA
    '-------------------------------------------------------------------------
    If (Not OnChangingPageIrDA (ps, Pagename)) Then Exit Function

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

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

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

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

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

    '-------------------------------------------------------------------------
    'page: Notes
    '-------------------------------------------------------------------------
    If (Not OnChangingPageNotes (ps, Pagename, sVarPre)) Then Exit Function


    OnChangingPage = True
    Exit Function

OnChangingPageError:
    Exit Function
End Function


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

    Dim vIndex As Variant
    Dim sVarPre As String 

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

    OnShow = False

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

    '-------------------------------------------------------------------------
    ' page: Pin Selection
    '-------------------------------------------------------------------------
    If (Not OnShowPagePinSelection(ps, Controlname, Pagename, v)) Then Exit Function

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

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

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

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

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

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

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

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

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

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


    OnShow = True
    Exit Function

OnShowError:
    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

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

    '-------------------------------------------------------------------------
    ' buttons: Autobaud
    '-------------------------------------------------------------------------
    If (Not OnButtonClickOnPageAutobaud(ps, Controlname)) Then Exit Function

    OnClick = True
    Exit Function

OnClickError:
    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, "ASCx\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
  Dim r As ProjectData
  Dim vIndex As Variant

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

  If Not(GetASCxDisebleBitName(r, vIndex) = "") Then
      If (Not ps.AddPage("Module Clock")) Then Exit Function
  End If

  OnLoadPageModuleClock = True
End Function



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

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

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

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

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

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

      End If
  End If

  OnChangingPageModuleClock = True
End Function



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

  OnShowPageModuleClock = False

  Dim r As ProjectData
  Dim c As Object
  Dim e As Object
  Dim bDisabled As Boolean
  Dim sVarPre As String
  Dim vIndex As Variant

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

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

  If Not(GetASCxDisebleBitName(r, vIndex) = "") Then
      If (Pagename = "Module Clock") Then
        '-------------------------------------------------------------------------
        ' page: ModuleClock (action)
        '-------------------------------------------------------------------------
        Select Case (Controlname)
            '---------------------------------------------------------------------
            ' control: optPERDISx_0 (action)
            '---------------------------------------------------------------------
            Case "optPERDISx_0"
                 r.v("SYSCON3_" & GetASCxDisebleBitName(r, vIndex)) = 0

            '---------------------------------------------------------------------
            ' control: optPERDISx_1 (action)
            '---------------------------------------------------------------------
            Case "optPERDISx_1"
                 r.v("SYSCON3_" & GetASCxDisebleBitName(r, vIndex)) = 1
                 Call SetASCxToDefault(r, vIndex)

          Case Else
        End Select

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

        '-------------------------------------------------------------------------
        ' control: optPERDISx_0 (show)
        '-------------------------------------------------------------------------
        With c("optPERDISx_0")
          bDisabled = False
          .Enabled = Not(bDisabled)
          .Value = -CInt(r.v("SYSCON3_" & GetASCxDisebleBitName(r, vIndex)) = 0)
        End With

        With e("optPERDISx_0")
          If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            .DisabledTooltipText = .DisabledTooltipText & FormatDisabledTooltip("")
          End If
        End With

        '-------------------------------------------------------------------------
        ' control: optPERDISx_1 (show)
        '-------------------------------------------------------------------------
        With c("optPERDISx_1")
          bDisabled = False
          .Enabled = Not(bDisabled)
          .Value = -CInt(r.v("SYSCON3_" & GetASCxDisebleBitName(r, vIndex)) = 1)
        End With

        With e("optPERDISx_1")
          If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            .DisabledTooltipText = .DisabledTooltipText & FormatDisabledTooltip("")
          End If
        End With

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

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

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

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


      End If
  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 OnLoadPagePinSelection(ps As Object) As Boolean
  On Error Resume Next

  OnLoadPagePinSelection = False

  If (Not ps.AddPage("Pin Selection")) Then Exit Function

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

  OnChangingPagePinSelection = False

  Dim v As String
  Dim sVarPre As String
  Dim vIndex As Variant

  vIndex = ps.Parameters.v("x")
  sVarPre = "ASC" & vIndex
  
  If (Not ps.ExtenderCollection("Pin Selection").Loaded) And (Pagename = "Pin Selection") Then
    ps.ExtenderCollection("Pin Selection").Loaded = True

    '-------------------------------
    ' frame: frmGM
    '-------------------------------
    If (Not ps.AddFrame("frmGM",100,100, 4150, 1375, "General Operating Mode (M)")) Then Exit Function
        If (Not ps.AddOption("optGM_0", 200, 350, 3800, 300, "Full-duplex asynchronous operating modes")) Then Exit Function
        If (Not ps.AddOption("optGM_1", 200, 825, 3800, 300, "Half-duplex 8-bit synchronous operating mode")) Then Exit Function

    '-------------------------------
    ' frame: frmPinSelection
    '-------------------------------
    If (Not ps.AddFrame("frmPinSelection",4400,100, 4150, 1375, "Alternate Pin Selection")) Then Exit Function
        If (Not ps.AddCheck("chk" & sVarPre & "_TxD_1", 200, 350, 3800, 300, "")) Then Exit Function
        If (Not ps.AddCheck("chk" & sVarPre & "_RxD_1", 200, 825, 3800, 300, "")) Then Exit Function


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

  OnShowPagePinSelection = False

  Dim r As ProjectData
  Dim c As Object
  Dim e As Object
  Dim bDisabled As Boolean
  Dim vIndex As Variant
  Dim sVarPre As String
  Dim sRegPre As String

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

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

  If (Pagename = "Pin Selection") Then
    '-------------------------------------------------------------------------
    ' page: PinSelection (action)
    '-------------------------------------------------------------------------

    Select Case (Controlname)
        '---------------------------------------------------------------------
        ' control: optGM_0 (action)
        '---------------------------------------------------------------------
        Case "optGM_0"
             Call SetPageAutobaudToDefault(r, vIndex)
             Call SetAscMode(r, vIndex, 1)
             If (GetPinFunction(r, sVarPre & "_RxD_1_O") = 2) Then
                Call ReleaseAlternateOutputPin(r, sVarPre & "_RxD_1_O")
                Call RequestAlternateInputPin(r, sVarPre & "_RxD_1_I")
             End If

        '---------------------------------------------------------------------
        ' control: optGM_1 (action)
        '---------------------------------------------------------------------
        Case "optGM_1"
              Call SetPageAutobaudToDefault(r, vIndex)
             Call SetAscMode(r, vIndex, 0)
             If (GetPinFunction(r, sVarPre & "_RxD_1_I") = 1) Then
                Call ReleaseAlternateInputPin(r, sVarPre & "_RxD_1_I")
                Call RequestAlternateOutputPin(r, sVarPre & "_RxD_1_O")
             End If

        '---------------------------------------------------------------------
        ' control: chk...TxD_1 (action)
        '---------------------------------------------------------------------
        Case "chk" & sVarPre & "_TxD_1"
            If (v(1) = 1) Then
                Call RequestAlternateOutputPin(r, sVarPre & "_TxD_1")
            Else
                Call ReleaseAlternateOutputPin(r, sVarPre & "_TxD_1")
                Call SetASCxToDefault(r, vIndex) 
            End If

        '---------------------------------------------------------------------
        ' control: chk...RxD_1 (action)
        '---------------------------------------------------------------------
        Case "chk" & sVarPre & "_RxD_1"
            If (v(1) = 1) Then
                If (r.v(sRegPre & "CON_M") = 0) Then
                    Call RequestAlternateOutputPin(r, sVarPre & "_RxD_1_O")
                Else
                    Call RequestAlternateInputPin(r, sVarPre & "_RxD_1_I")
                End If
            Else
                If (r.v(sRegPre & "CON_M") = 0) Then
                    Call ReleaseAlternateOutputPin(r, sVarPre & "_RxD_1_O")
                Else
                    Call ReleaseAlternateInputPin(r, sVarPre & "_RxD_1_I")
                End If
                Call SetASCxToDefault(r, vIndex) 
            End If

      Case Else
    End Select

    '-------------------------------------------------------------------------
    ' page: PinSelection (show)
    '-------------------------------------------------------------------------
    '-------------------------------------------------------------------------
    ' control: optGM_0 (show)
    '-------------------------------------------------------------------------
    With c("optGM_0")
      ' disable condition
      bDisabled = IsModuleClockDisabled(r, vIndex)
      .Enabled = Not(bDisabled)
      ' show condition
      .Value = (r.v(sRegPre & "CON_M") > 0)
    End With

    With e("optGM_0")
      If (bDisabled) Then
        ' tooltip if control is disabled 
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleClockDisabled(r, vIndex)
      Else
        ' tooltip if control is enabled 
      End If
    End With
             
    '-------------------------------------------------------------------------
    ' control: optGM_1 (show)
    '-------------------------------------------------------------------------
    With c("optGM_1")
      ' disable condition
      bDisabled = IsModuleClockDisabled(r, vIndex)
      .Enabled = Not(bDisabled)
      ' show condition
      .Value = (r.v(sRegPre & "CON_M") = 0)
    End With

    With e("optGM_1")
      If (bDisabled) Then
        ' tooltip if control is disabled 
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleClockDisabled(r, vIndex)
      Else
        ' tooltip if control is enabled 
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: chk...TxD_1 (show)
    '-------------------------------------------------------------------------
    With c("chk" & sVarPre & "_TxD_1")
      ' disable condition
      bDisabled = IsModuleClockDisabled(r, vIndex) Or _
                  Not(IsAlternateOutputPinFree(r, sVarPre & "_TxD_1") = True)
      .Enabled = Not(bDisabled)
      .Caption = "Use pin TxDA" & vIndex & " (" & GetPinName(sVarPre & "_TxD_1") & ")"
      ' show condition
      .Value = -CInt(GetPinFunction(r, sVarPre & "_TxD_1") = 2)
    End With

    With e("chk" & sVarPre & "_TxD_1")
      If (bDisabled) Then
        ' tooltip if control is disabled 
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (IsModuleClockDisabled(r, vIndex)) Then
            .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleClockDisabled(r, vIndex)
        End If
        If (Not(IsAlternateOutputPinFree(r, sVarPre & "_TxD_1") = True)) Then
            .DisabledToolTipText = .DisabledToolTipText & _
              GetDisabledAlternatePinTooltip(r, sVarPre & "_TxD_1")
        End If
      Else
        ' tooltip if control is enabled 
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: chk...RxD_1 (show)
    '-------------------------------------------------------------------------
    With c("chk" & sVarPre & "_RxD_1")
      ' disable condition
      bDisabled = IsModuleClockDisabled(r, vIndex) Or _
                  (Not(IsAlternateOutputPinFree(r, sVarPre & "_RxD_1_O") = True) And _
                   Not(IsAlternateInputPinFree(r, sVarPre & "_RxD_1_I") = True))
      .Enabled = Not(bDisabled)
      .Caption = "Use pin RxDA" & vIndex & " (" & GetPinName(sVarPre & "_RxD_1_O") & ")"
      ' show condition
      .Value = -CInt(GetPinFunction(r, sVarPre & "_RxD_1_O") = 2 Or _
                     GetPinFunction(r, sVarPre & "_RxD_1_I") = 1)
    End With

    With e("chk" & sVarPre & "_RxD_1")
      If (bDisabled) Then
        ' tooltip if control is disabled 
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (IsModuleClockDisabled(r, vIndex)) Then
            .DisabledToolTipText = .DisabledToolTipText & _
              GetTooltipModuleClockDisabled(r, vIndex)
        End If
        If (Not(IsAlternateOutputPinFree(r, sVarPre & "_RxD_1_O") = True) And _
                   Not(IsAlternateInputPinFree(r, sVarPre & "_RxD_1_I") = True)) Then
            .DisabledToolTipText = .DisabledToolTipText & _
              GetDisabledAlternatePinTooltip(r, sVarPre & "_RxD_1_O")
        End If
      Else
        ' tooltip if control is enabled 
      End If
    End With


  End If

  OnShowPagePinSelection = True
  Exit Function

OnShowPagePinSelectionError:
  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 'Autobaud'.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnLoadPageAutobaud(ps As Object) As Boolean
  On Error Resume Next

  Dim r As ProjectData 
  Dim vIndex As Variant
  Set r = ps.ProjectData
  vIndex = ps.Parameters.v("x")

  OnLoadPageAutobaud = False
  If (IsAutobaudAvailable(r, vIndex)) Then
    If (Not ps.AddPage("Autobaud")) Then Exit Function
  End If

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

  Dim r As ProjectData 
  Dim vIndex As Variant
  Set r = ps.ProjectData
  vIndex = ps.Parameters.v("x")

  OnChangingPageAutobaud = False
  
  If (IsAutobaudAvailable(r, vIndex)) Then
    If (Not ps.ExtenderCollection("Autobaud").Loaded) And (Pagename = "Autobaud") Then
      ps.ExtenderCollection("Autobaud").Loaded = True
    
    '-------------------------------
    ' frame: frmABEN
    '-------------------------------
    If (Not ps.AddFrame("frmABEN",100,100, 4200, 850, "Autobaud Detection")) Then Exit Function
        If (Not ps.AddCheck("chkABEN", 200, 300, 3000, 375, "Enable autobaud detection (ABEN)")) Then Exit Function

    '-------------------------------
    ' frame: frmAUREN
    '-------------------------------
    If (Not ps.AddFrame("frmAUREN",4450,100, 4100, 850, "Automatic Autobaud Control")) Then Exit Function
        If (Not ps.AddCheck("chkAUREN", 200, 300, 3250, 400, "Enable the receiver after a successful autobaud detection (AUREN)")) Then Exit Function

    '-------------------------------
    ' frame: frmBRsel
    '-------------------------------
    If (Not ps.AddFrame("frmBRsel",100,1050, 4200, 1000, "Baud Rate Selection")) Then Exit Function
        If (Not ps.AddButton("btnSeCa", 500, 350, 3000, 450, "Set Autobaud Detection Baud Rates")) Then Exit Function

    '-------------------------------
    ' frame: frmABEM
    '-------------------------------
    If (Not ps.AddFrame("frmABEM",4450,1050, 4100, 1650, "Autobaud Echo Mode (ABEM)")) Then Exit Function
        If (Not ps.AddOption("optABEM_0", 200, 300, 1975, 300, "Disable the echo mode")) Then Exit Function
        If (Not ps.AddOption("optABEM_1", 200, 700, 3650, 400, "Enable the echo mode only during autobaud detection")) Then Exit Function
        If (Not ps.AddOption("optABEM_2", 200, 1200, 2700, 300, "Enable the echo mode always")) Then Exit Function

    '-------------------------------
    ' frame: frmInterruptGeneration
    '-------------------------------
    If (Not ps.AddFrame("frmInterruptGeneration",100,2150, 4200, 1850, "Interrupt Generation Control")) Then Exit Function
        If (Not ps.AddCheck("chkABDETEN", 200, 300, 3550, 400, "Enable interrupt generation after successful autobaud detection (ABDETEN)")) Then Exit Function
        If (Not ps.AddCheck("chkFCDETEN", 200, 800, 3950, 400, "Enable interrupt generation also after first character of two-byte frame detection (FCDETEN)")) Then Exit Function
        If (Not ps.AddCheck("chkABSTEN", 200, 1300, 3250, 400, "Enable interrupt generation after a start bit has been detected (ABSTEN)")) Then Exit Function

    '-------------------------------
    ' frame: frmInv
    '-------------------------------
    If (Not ps.AddFrame("frmInv",4450,2800, 4100, 1200, "Inverter Control")) Then Exit Function
        If (Not ps.AddCheck("chkTXINV", 200, 300, 2600, 300, "Enable transmit inverter (TXINV)")) Then Exit Function
        If (Not ps.AddCheck("chkRXINV", 200, 750, 2600, 300, "Enable receive inverter (RXINV)")) Then Exit Function

    '-------------------------------
    ' frame: frmInterrupts
    '-------------------------------
    If (Not ps.AddFrame("frmInterrupts",100,4100, 4200, 1100, "Interrupt Control")) Then Exit Function
        If (Not ps.AddCheck("chkABIE", 200, 450, 3100, 300, "Enable autobaud interrupt (IE)")) Then Exit Function

    '-------------------------------
    ' frame: frmRA
    '-------------------------------
    If (Not ps.AddFrame("frmRA",4450,4100, 4100, 1100, "Baud Rate generator Run Control")) Then Exit Function
        If (Not ps.AddCheck("chkR", 200, 400, 3650, 380, "Start autobaud detection after inizialization (R)")) Then Exit Function

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

  OnShowPageAutobaud = False

  Dim r As ProjectData
  Dim c As Collection
  Dim e As Collection
  Dim bDisabled As Boolean
  Dim bDisabledClockOrPins As Boolean
  
  Dim sRegPre As String
  Dim sVarPre As String
  Dim vIndex As Variant
  Dim i As Integer
  Dim sDisabledTooltip As String
  Dim sDisabledClockOrPinsTooltip As String

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

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

  If (IsAutobaudAvailable(r, vIndex)) Then
    If (Pagename = "Autobaud") Then
      '-------------------------------------------------------------------------
      ' page: Autobaud (action)
      '-------------------------------------------------------------------------
      Select Case (Controlname)

          '---------------------------------------------------------------------
          ' control: chkABEN (action)
          '---------------------------------------------------------------------
          Case "chkABEN"
               r.v(sRegPre & "ABCON_ABEN") = v(1)
               If v(1) = 1 Then
                 Call SetAscMode(r, vIndex, 7)
                 r.v(sRegPre & "CON_ODD") = 0
                 r.v(sRegPre & "CON_STP") = 0
                 r.v(sRegPre & "CON_LB") = 0
                 r.v(sRegPre & "CON_REN") = 0
'                 r.v(sRegPre & "CON_FDE") = 0
                 Call SetDefaultFDVForAutobaud(r, vIndex)
               Else
                 Call SetPageAutobaudToDefault(r, vIndex)
                 r.v(sRegPre & "FDV_FD_VALUE") = 0
                 r.v(sRegPre & "CON_FDE") = 0
                 Call UpdateASCxBaudrate(r, vIndex)
                 Call UpdateIrDA(r, vIndex)
               End If

          '---------------------------------------------------------------------
          ' control: chkAUREN (action)
          '---------------------------------------------------------------------
          Case "chkAUREN"
               r.v(sRegPre & "ABCON_AUREN") = v(1)
               If (v(1) = 1) Then
                 r.v(sRegPre & "CON_REN") = 0
               End If

          '---------------------------------------------------------------------
          ' control: chkABDETEN (action)
          '---------------------------------------------------------------------
          Case "chkABDETEN"
               r.v(sRegPre & "ABCON_ABDETEN") = v(1)
               If v(1) = 0 Then
                 Call DisableSRN(r, sVarPre, sRegPre &  "ABIC", "Autobaud")
                 r.v(sRegPre & "ABCON_FCDETEN") = 0
                 r.v(sRegPre & "ABCON_ABSTEN") = 0
                 r.v(sVarPre & "_USE_GetAutobaudStatus") = 0
               End If

          '---------------------------------------------------------------------
          ' control: chkFCDETEN (action)
          '---------------------------------------------------------------------
          Case "chkFCDETEN"
               r.v(sRegPre & "ABCON_FCDETEN") = v(1)

          '---------------------------------------------------------------------
          ' control: chkABSTEN (action)
          '---------------------------------------------------------------------
          Case "chkABSTEN"
               r.v(sRegPre & "ABCON_ABSTEN") = v(1)
               'If v(1) = 0 Then
               '  Call DisableSRN(r, sVarPre, sRegPre &  "ABSTSRC", "AutobaudStart")
               'End If

          '---------------------------------------------------------------------
          ' control: chkABIE (action)
          '---------------------------------------------------------------------
          Case "chkABIE"
               If v(1) = 1 Then
                 Call EnableSRN(r, sVarPre, sRegPre &  "ABIC", "Autobaud")
                 r.v(sVarPre & "_USE_GetAutobaudStatus") = 0
               Else
                 Call DisableSRN(r, sVarPre, sRegPre &  "ABIC", "Autobaud")
               End If

          '---------------------------------------------------------------------
          ' control: optABEM_0 (action)
          '---------------------------------------------------------------------
          Case "optABEM_0"
               r.v(sRegPre & "ABCON_ABEM") = 0

          '---------------------------------------------------------------------
          ' control: optABEM_1 (action)
          '---------------------------------------------------------------------
          Case "optABEM_1"
               r.v(sRegPre & "ABCON_ABEM") = 1

          '---------------------------------------------------------------------
          ' control: optABEM_2 (action)
          '---------------------------------------------------------------------
          Case "optABEM_2"
               r.v(sRegPre & "ABCON_ABEM") = 2

          '---------------------------------------------------------------------
          ' control: chkTXINV (action)
          '---------------------------------------------------------------------
          Case "chkTXINV"
               r.v(sRegPre & "ABCON_TXINV") = v(1)

          '---------------------------------------------------------------------
          ' control: chk5 (action)
          '---------------------------------------------------------------------
          Case "chkRXINV"
               r.v(sRegPre & "ABCON_RXINV") = v(1)

          '---------------------------------------------------------------------
          ' control: chkR (action)
          '---------------------------------------------------------------------
          Case "chkR"
               r.v(sRegPre & "CON_R") = v(1)

        Case Else
      End Select

      '-------------------------------------------------------------------------
      ' page: Autobaud (show)
      '-------------------------------------------------------------------------
      ' save the disabled condition for the module clock and the pins
      If (IsSynchronMode(r, vIndex)) Then 
        bDisabledClockOrPins = True
        sDisabledClockOrPinsTooltip = FormatDisabledTooltip("synchronous mode is selected")
      Else
        bDisabledClockOrPins = IsModuleClockDisabled(r, vIndex) Or _
          IsPinInterfaceDeselected(r, vIndex)      ' save the tooltip for the module clock and the pins

        sDisabledClockOrPinsTooltip = GetTooltipModuleClockDisabled(r, vIndex)

        sDisabledClockOrPinsTooltip = sDisabledClockOrPinsTooltip & _
          GetTooltipPinInterfaceDeselected(r, vIndex)

      End If

      bDisabled = bDisabledClockOrPins Or r.v(sRegPre & "ABCON_ABEN") = 0 
      sDisabledTooltip = TOOLTIP_DISABLED_IF
      sDisabledTooltip = sDisabledTooltip & sDisabledClockOrPinsTooltip
      If (r.v(sRegPre & "ABCON_ABEN") = 0) Then
        sDisabledTooltip = sDisabledTooltip & FormatDisabledTooltip("autobaud detection mode is not enabled")
      End If
      
      Call SetDefaultPropertiesForAllControlsOnFrame(c("frmAUREN").Caption, c, e, bDisabled, sDisabledTooltip, "")
      Call SetDefaultPropertiesForAllControlsOnFrame(c("frmBRsel").Caption, c, e, bDisabled, sDisabledTooltip, "")
      Call SetDefaultPropertiesForAllControlsOnFrame(c("frmABEM").Caption, c, e, bDisabled, sDisabledTooltip, "")
      Call SetDefaultPropertiesForAllControlsOnFrame(c("frmInv").Caption, c, e, bDisabled, sDisabledTooltip, "")
      Call SetDefaultPropertiesForAllControlsOnFrame(c("frmRA").Caption, c, e, bDisabled, sDisabledTooltip, "")

      '-------------------------------------------------------------------------
      ' control: chkABEN (show)
      '-------------------------------------------------------------------------
      With c("chkABEN")
        bDisabled = bDisabledClockOrPins
        .Enabled = Not(bDisabled)
        .Value = -CInt(r.v(sRegPre & "ABCON_ABEN") = 1)
      End With

      With e("chkABEN")
        If (bDisabled) Then
          .DisabledTooltipText = TOOLTIP_DISABLED_IF
          .DisabledTooltipText = .DisabledTooltipText & sDisabledClockOrPinsTooltip
        End If
      End With

      '-------------------------------------------------------------------------
      ' control: chkAUREN (show)
      '-------------------------------------------------------------------------
      With c("chkAUREN")
        .Value = -CInt(r.v(sRegPre & "ABCON_AUREN") = 1)
      End With

      '-------------------------------------------------------------------------
      ' control: optABEM_0 (show)
      '-------------------------------------------------------------------------
      With c("optABEM_0")
        .Value = -CInt(r.v(sRegPre & "ABCON_ABEM") = 0)
      End With

      '-------------------------------------------------------------------------
      ' control: optABEM_1 (show)
      '-------------------------------------------------------------------------
      With c("optABEM_1")
        .Value = -CInt(r.v(sRegPre & "ABCON_ABEM") = 1)
      End With

      '-------------------------------------------------------------------------
      ' control: optABEM_2 (show)
      '-------------------------------------------------------------------------
      With c("optABEM_2")
        .Value = -CInt(r.v(sRegPre & "ABCON_ABEM") = 2)
      End With

      '-------------------------------------------------------------------------
      ' control: chkTXINV (show)
      '-------------------------------------------------------------------------
      With c("chkTXINV")
        .Value = -CInt(r.v(sRegPre & "ABCON_TXINV") = 1)
      End With

      '-------------------------------------------------------------------------
      ' control: chkRXINV (show)
      '-------------------------------------------------------------------------
      With c("chkRXINV")
        .Value = -CInt(r.v(sRegPre & "ABCON_RXINV") = 1)
      End With

      '-------------------------------------------------------------------------
      ' control: chkR (show)
      '-------------------------------------------------------------------------
      With c("chkR")
        .Value = -CInt(r.v(sRegPre & "CON_R") = 1 And r.v(sRegPre & "ABCON_ABEN") = 1)
      End With

      '-------------------------------------------------------------------------
      ' control: btnSeCa (show)
      '-------------------------------------------------------------------------
      With c("btnSeCa")
      End With

      '-------------------------------------------------------------------------
      ' control: chkABDETEN (show)
      '-------------------------------------------------------------------------
      With c("chkABDETEN")
        bDisabled = bDisabledClockOrPins Or r.v(sRegPre & "ABCON_ABEN") = 0
        .Enabled = Not(bDisabled)
        .Value = -CInt(r.v(sRegPre & "ABCON_ABDETEN") = 1)
      End With

      With e("chkABDETEN")
        If (bDisabled) Then
          .DisabledTooltipText = TOOLTIP_DISABLED_IF
          .DisabledTooltipText = .DisabledTooltipText & sDisabledClockOrPinsTooltip
          If (r.v(sRegPre & "ABCON_ABEN") = 0) Then
            .DisabledTooltipText = .DisabledTooltipText & FormatDisabledTooltip("autobaud detection mode is not enabled")
          End If
        End If
      End With

      '-------------------------------------------------------------------------
      ' control: chkABSTEN (show)
      '-------------------------------------------------------------------------
      With c("chkABSTEN")
        bDisabled = bDisabledClockOrPins Or r.v(sRegPre & "ABCON_ABEN") = 0 Or r.v(sRegPre & "ABCON_ABDETEN") = 0
        .Enabled = Not(bDisabled)
        .Value = -CInt(r.v(sRegPre & "ABCON_ABSTEN") = 1)
      End With

      With e("chkABSTEN")
        If (bDisabled) Then
          .DisabledTooltipText = TOOLTIP_DISABLED_IF
          .DisabledTooltipText = .DisabledTooltipText & sDisabledClockOrPinsTooltip
          If (r.v(sRegPre & "ABCON_ABEN") = 0) Then
            .DisabledTooltipText = .DisabledTooltipText & FormatDisabledTooltip("autobaud detection mode is not enabled")
          End If
          If (r.v(sRegPre & "ABCON_ABDETEN") = 0) Then
            .DisabledTooltipText = .DisabledTooltipText & FormatDisabledTooltip("interrupt generation after successful autobaud detection is disabled (ABDETEN = 0)")
          End If
        End If
      End With

      '-------------------------------------------------------------------------
      ' control: chkFCDETEN (show)
      '-------------------------------------------------------------------------
      With c("chkFCDETEN")
        bDisabled = bDisabledClockOrPins Or r.v(sRegPre & "ABCON_ABEN") = 0 Or r.v(sRegPre & "ABCON_ABDETEN") = 0
        .Enabled = Not(bDisabled)
        .Value = -CInt(r.v(sRegPre & "ABCON_FCDETEN") = 1)
      End With

      With e("chkFCDETEN")
        If (bDisabled) Then
          .DisabledTooltipText = TOOLTIP_DISABLED_IF
          .DisabledTooltipText = .DisabledTooltipText & sDisabledClockOrPinsTooltip
          If (r.v(sRegPre & "ABCON_ABEN") = 0) Then
            .DisabledTooltipText = .DisabledTooltipText & FormatDisabledTooltip("autobaud detection mode is not enabled")
          End If
          If (r.v(sRegPre & "ABCON_ABDETEN") = 0) Then
            .DisabledTooltipText = .DisabledTooltipText & FormatDisabledTooltip("interrupt generation after successful autobaud detection is disabled (ABDETEN = 0)")
          End If
        End If
      End With

      '-------------------------------------------------------------------------
      ' control: chkABIE (show)
      '-------------------------------------------------------------------------
      With c("chkABIE")
        bDisabled = bDisabledClockOrPins Or r.v(sRegPre & "ABCON_ABEN") = 0 Or r.v(sRegPre & "ABCON_ABDETEN") = 0
        .Enabled = Not(bDisabled)
        .Value = -CInt(r.v(sRegPre & "ABIC_IE") = 1)
      End With

      With e("chkABIE")
        If (bDisabled) Then
          .DisabledTooltipText = TOOLTIP_DISABLED_IF
          .DisabledTooltipText = .DisabledTooltipText & sDisabledClockOrPinsTooltip
          If (r.v(sRegPre & "ABCON_ABEN") = 0) Then
            .DisabledTooltipText = .DisabledTooltipText & FormatDisabledTooltip("autobaud detection mode is not enabled")
          End If
          If (r.v(sRegPre & "ABCON_ABDETEN") = 0) Then
            .DisabledTooltipText = .DisabledTooltipText & FormatDisabledTooltip("interrupt generation after successful autobaud detection is disabled (ABDETEN = 0)")
          End If
        End If
      End With


    End If
  End If

  OnShowPageAutobaud = True
  Exit Function

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


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

  OnButtonClickOnPageAutobaud = False

  Dim vIndex As Variant
  Dim AutoBaudTableP As Peripherals

  vIndex = ps.Parameters.v("x")   
  
  Select Case (Controlname)
    '---------------------------------------------------------------------
    ' control: btnSeCa (action)
    '---------------------------------------------------------------------
    Case "btnSeCa"
         Set AutoBaudTableP = New Peripherals
         AutoBaudTableP.Parameters.Add ("x")
         AutoBaudTableP.Parameters.v("x") = vIndex
         Set AutoBaudTableP.ProjectData = ps.ProjectData
         AutoBaudTableP.Caption = "Autobaud Detection Baud Rates"
         AutoBaudTableP.Scriptfile = DefGetPath("Scripts") & "ASCx\BaudRateTable.DAVE"
         AutoBaudTableP.Show
    Case Else
  End Select

  OnButtonClickOnPageAutobaud = True
  Exit Function

OnButtonClickOnPageAutobaudError:
  Errorbox "Can not process the click", 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 'Control'.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnLoadPageControl(ps As Object) As Boolean
  On Error Resume Next

  OnLoadPageControl = False

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

  OnLoadPageControl = True
End Function


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

  Dim v As String
  Dim sVarPre As String
  Dim vIndex As Variant
  Dim r As ProjectData
  Dim iTop As Integer
  Dim iNext As Integer

  Set r = ps.ProjectData

  vIndex = ps.Parameters.v("x")
  sVarPre = "ASC" & Format$(vIndex)

  
  If (Not ps.ExtenderCollection("Control").Loaded) And (Pagename = "Control") Then
    ps.ExtenderCollection("Control").Loaded = True
  
    '-------------------------------
    ' frame: frmM
    '-------------------------------
    If (Not ps.AddFrame("frmM",100,100, 3300, 3360, "Mode Control (M)")) Then Exit Function
        If (IsIrDAAvailable(r, vIndex)) Then
          If (Not ps.AddOption("optM_2", 200, 2800, 3000, 300, "IrDA mode, 8-bit data (asynchronous)")) Then Exit Function
          iNext = 400
        Else
          ' this is only a dummy control for better handling
          If (Not ps.AddOption("optM_2", 200, 5800, 3000, 300, "")) Then Exit Function
          iNext = 500
        End If 
        iTop = 400
        If (Not ps.AddOption("optM_0", 200, iTop, 3000, 300, "8-bit data (synchronous)")) Then Exit Function
        iTop = iTop + iNext
        If (Not ps.AddOption("optM_1", 200, iTop, 3000, 300, "8-bit data (asynchronous)")) Then Exit Function
        iTop = iTop + iNext
        If (Not ps.AddOption("optM_3", 200, iTop, 3000, 300, "7-bit data + parity (asynchronous)")) Then Exit Function
        iTop = iTop + iNext
        If (Not ps.AddOption("optM_4", 200, iTop, 3000, 300, "9-bit data (asynchronous)")) Then Exit Function
        iTop = iTop + iNext
        If (Not ps.AddOption("optM_5", 200, iTop, 3000, 300, "8-bit data + wake up (asynchronous)")) Then Exit Function
        ' this is only a dummy control for better handling
        If (Not ps.AddOption("optM_6", 200, 5800, 3000, 300, "")) Then Exit Function
        iTop = iTop + iNext
        If (Not ps.AddOption("optM_7", 200, iTop, 3000, 300, "8-bit data + parity (asynchronous)")) Then Exit Function

    '-------------------------------
    ' frame: frmReceiver
    '-------------------------------
    If (Not ps.AddFrame("frmReceiver",3600,100, 2250, 900, "Receiver Enable")) Then Exit Function
        If (Not ps.AddCheck("chkREN", 200, 350, 1950, 300, "Enable receiver (REN)")) Then Exit Function

    '-------------------------------
    ' frame: frmLB
    '-------------------------------
    If (Not ps.AddFrame("frmLB",6000,100, 2550, 900, "Loopback Mode")) Then Exit Function
        If (Not ps.AddCheck("chkLB", 200, 350, 2300, 300, "Enable loopback mode (LB)")) Then Exit Function

    '-------------------------------
    ' frame: frmSTP
    '-------------------------------
    If (Not ps.AddFrame("frmSTP",3600,1150, 2250, 1150, "Stop Bit Selection (STP)")) Then Exit Function
        If (Not ps.AddOption("optSTP_0", 200, 350, 1300, 300, "One stop bit")) Then Exit Function
        If (Not ps.AddOption("optSTP_1", 200, 700, 1300, 300, "Two stop bits")) Then Exit Function

    '-------------------------------
    ' frame: frmODD
    '-------------------------------
    If (Not ps.AddFrame("frmODD",6000,1150, 2550, 1150, "Parity Selection (ODD)")) Then Exit Function
        If (Not ps.AddOption("optODD_0", 200, 350, 1300, 300, "Even parity")) Then Exit Function
        If (Not ps.AddOption("optODD_1", 200, 700, 1300, 300, "Odd parity")) Then Exit Function

    '-------------------------------
    ' frame: frmERR
    '-------------------------------
    If (IsIrDAAvailable(r, vIndex)) Then
      If (Not ps.AddFrame("frmERR",120,3600, 3300, 1680, "Error Check / Invert Receiver Input")) Then Exit Function
    Else
      If (Not ps.AddFrame("frmERR",120,3600, 3300, 1680, "Error Check")) Then Exit Function
    End If
        If (Not ps.AddCheck("chkOEN", 200, 300, 2880, 300, "Enable overrun check (OEN)")) Then Exit Function
        If (Not ps.AddCheck("chkFEN", 200, 750, 2880, 300, "Enable framing check (FEN)")) Then Exit Function
        If (Not ps.AddCheck("chkPEN", 200, 1250, 2880, 300, "")) Then Exit Function

    '-------------------------------
    ' frame: frmIC
    '-------------------------------
    If (Not ps.AddFrame("frmIC",3600,2450, 4950, 2850, "Interrupts")) Then Exit Function
        If (Not ps.AddCheck("chkTSRC", 200, 350, 2650, 300, "Enable transmit interrupt (IE)")) Then Exit Function
        If (Not ps.AddCheck("chkTBSRC", 200, 1000, 3200, 300, "Enable transmit buffer interrupt (IE)")) Then Exit Function
        If (Not ps.AddCheck("chkRSRC", 200, 1650, 2850, 300, "Enable receive interrupt (IE)")) Then Exit Function
        If (Not ps.AddCheck("chkESRC", 200, 2300, 2600, 300, "Enable error interrupt (IE)")) Then Exit Function

  End If
  OnChangingPageControl = True
End Function


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

  OnShowPageControl = False

  Dim r As ProjectData
  Dim c As Collection
  Dim e As Collection
  Dim bDisabled As Boolean
  Dim bDisabledClockOrPinsOrAutoBaud As Boolean
  Dim bDisabledClockOrPins As Boolean
  Dim sDisabledClockOrPinsOrAutoBaudTooltip As String
  Dim sDisabledClockOrPinsTooltip As String
  Dim i As Integer
  
  Dim sRegPre As String
  Dim sVarPre As String
  Dim vIndex As Variant

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


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

  If (Pagename = "Control") Then
    '-------------------------------------------------------------------------
    ' page: Control (action)
    '-------------------------------------------------------------------------
    Select Case (Controlname)
        '---------------------------------------------------------------------
        ' control: optM_0 (action)
        '---------------------------------------------------------------------
        Case "optM_0"
                 Call SetAscMode(r, vIndex, 0)
             
        '---------------------------------------------------------------------
        ' control: optM_1 (action)
        '---------------------------------------------------------------------
        Case "optM_1"
                 Call SetAscMode(r, vIndex, 1)

        '---------------------------------------------------------------------
        ' control: optM_3 (action)
        '---------------------------------------------------------------------
        Case "optM_3"
                 Call SetAscMode(r, vIndex, 3)

        '---------------------------------------------------------------------
        ' control: optM_4 (action)
        '---------------------------------------------------------------------
        Case "optM_4"
                 Call SetAscMode(r, vIndex, 4)

        '---------------------------------------------------------------------
        ' control: optM_5 (action)
        '---------------------------------------------------------------------
        Case "optM_5"
                 Call SetAscMode(r, vIndex, 5)

        '---------------------------------------------------------------------
        ' control: optM_7 (action)
        '---------------------------------------------------------------------
        Case "optM_7"
                 Call SetAscMode(r, vIndex, 7)

        '---------------------------------------------------------------------
        ' control: optM_2 (action)
        '---------------------------------------------------------------------
        Case "optM_2"
                 Call SetAscMode(r, vIndex, 2)

        '---------------------------------------------------------------------
        ' control: chkREN (action)
        '---------------------------------------------------------------------
        Case "chkREN"
             r.v(sRegPre & "CON_REN") = v(1)

        '---------------------------------------------------------------------
        ' control: chkLB (action)
        '---------------------------------------------------------------------
        Case "chkLB"
             r.v(sRegPre & "CON_LB") = v(1)

        '---------------------------------------------------------------------
        ' control: chkOEN (action)
        '---------------------------------------------------------------------
        Case "chkOEN"
             r.v(sRegPre & "CON_OEN") = v(1)
             Call ReleaseErrorInterrupt(r, vIndex)

        '---------------------------------------------------------------------
        ' control: chkFEN (action)
        '---------------------------------------------------------------------
        Case "chkFEN"
             r.v(sRegPre & "CON_FEN") = v(1)
             Call ReleaseErrorInterrupt(r, vIndex)

        '---------------------------------------------------------------------
        ' control: chkPEN (action)
        '---------------------------------------------------------------------
        Case "chkPEN"
             r.v(sRegPre & "CON_PEN_RXDI") = v(1)
             Call ReleaseErrorInterrupt(r, vIndex)

        '---------------------------------------------------------------------
        ' control: optSTP_0 (action)
        '---------------------------------------------------------------------
        Case "optSTP_0"
             r.v(sRegPre & "CON_STP") = 0

        '---------------------------------------------------------------------
        ' control: optSTP_1 (action)
        '---------------------------------------------------------------------
        Case "optSTP_1"
             r.v(sRegPre & "CON_STP") = 1

        '---------------------------------------------------------------------
        ' control: optODD_0 (action)
        '---------------------------------------------------------------------
        Case "optODD_0"
             r.v(sRegPre & "CON_ODD") = 0

        '---------------------------------------------------------------------
        ' control: optODD_1 (action)
        '---------------------------------------------------------------------
        Case "optODD_1"
             r.v(sRegPre & "CON_ODD") = 1

        '---------------------------------------------------------------------
        ' control: chkTSRC (action)
        '---------------------------------------------------------------------
        Case "chkTSRC"
             If v(1) = 1 Then
               r.v(sVarPre & "_USE_TxDataReady") = 0
               Call EnableSRN(r, sVarPre, sRegPre & "TIC", "Tx")
             Else
               Call DisableSRN(r, sVarPre, sRegPre &  "TIC", "Tx")
             End If

        '---------------------------------------------------------------------
        ' control: chkTBSRC (action)
        '---------------------------------------------------------------------
        Case "chkTBSRC"
             If v(1) = 1 Then
               r.v(sVarPre & "_USE_TxBufFree") = 0
               Call EnableSRN(r, sVarPre, sRegPre &  "TBIC", "TxBuffer")
             Else
               Call DisableSRN(r, sVarPre, sRegPre &  "TBIC", "TxBuffer")
             End If

        '---------------------------------------------------------------------
        ' control: chkRSRC (action)
        '---------------------------------------------------------------------
        Case "chkRSRC"
             If v(1) = 1 Then
               r.v(sVarPre & "_USE_RxDataReady") = 0
               Call EnableSRN(r, sVarPre, sRegPre &  "RIC", "Rx")
             Else
               Call DisableSRN(r, sVarPre, sRegPre &  "RIC", "Rx")
             End If

        '---------------------------------------------------------------------
        ' control: chkESRC (action)
        '---------------------------------------------------------------------
        Case "chkESRC"
             If v(1) = 1 Then
                r.v(sVarPre & "_USE_ErrorCheck") = 0
               Call EnableSRN(r, sVarPre, sRegPre &  "EIC", "Error")
             Else
               Call DisableSRN(r, sVarPre, sRegPre &  "EIC", "Error")
             End If

      Case Else
    End Select

    '-------------------------------------------------------------------------
    ' page: Control (show)
    '-------------------------------------------------------------------------
    ' save the disabled condition for the module clock and the pins
    bDisabledClockOrPins = IsModuleClockDisabled(r, vIndex) Or IsPinInterfaceDeselected(r, vIndex)      ' save the tooltip for the module clock and the pins
    ' save the disabled condition for the module clock, the pins and the autobaud mode
    bDisabledClockOrPinsOrAutoBaud = bDisabledClockOrPins Or IsAutobaudSelected(r, vIndex)

    ' save the tooltip for the module clock and the pins
    sDisabledClockOrPinsTooltip = GetTooltipModuleClockDisabled(r, vIndex)
    sDisabledClockOrPinsTooltip = sDisabledClockOrPinsTooltip & GetTooltipPinInterfaceDeselected(r, vIndex)

    ' save the tooltip for the module clock, the pins and the autobaud mode
    sDisabledClockOrPinsOrAutoBaudTooltip = sDisabledClockOrPinsTooltip & GetTooltipAutobaudSelected(r, vIndex)

    '-------------------------------------------------------------------------
    ' control: optM_0 (show)
    '-------------------------------------------------------------------------
    With c("optM_0")
      If (IsSynchronMode(r, vIndex)) Then 
        bDisabled = bDisabledClockOrPinsOrAutoBaud 
      Else
        bDisabled = True
      End If
      .Enabled = Not(bDisabled)
      .Value = -CInt(r.v(sRegPre & "CON_M") = 0)
    End With

    With e("optM_0")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (IsSynchronMode(r, vIndex)) Then
          .DisabledTooltipText = .DisabledTooltipText & sDisabledClockOrPinsOrAutoBaudTooltip
        Else
          .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip("asynchronous mode is selected")         
        End If
      End If
    End With


    For i = 1 To 7
      '-------------------------------------------------------------------------
      ' control: optM_x (show)  (x = 1-5)
      '-------------------------------------------------------------------------
      With c("optM_" & i)
        If (Not IsSynchronMode(r, vIndex)) Then 
          bDisabled = bDisabledClockOrPinsOrAutoBaud 
        Else
          bDisabled = True
        End If
        .Enabled = Not(bDisabled)
        .Value = -CInt(r.v(sRegPre & "CON_M") = i)
      End With

      With e("optM_" & i)
        If (bDisabled) Then
          .DisabledTooltipText = TOOLTIP_DISABLED_IF
          If (Not IsSynchronMode(r, vIndex)) Then
            .DisabledTooltipText = .DisabledTooltipText & sDisabledClockOrPinsOrAutoBaudTooltip
          Else
            .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip("synchronous mode is selected")         
          End If
        End If
      End With
    Next i


    '-------------------------------------------------------------------------
    ' control: chkREN (show)
    '-------------------------------------------------------------------------
    With c("chkREN")
      If (IsSynchronMode(r, vIndex)) Then 
        bDisabled = True
      Else
        bDisabled = bDisabledClockOrPinsOrAutoBaud 
      End If
      .Enabled = Not(bDisabled)
      .Value = -CInt(r.v(sRegPre & "CON_REN") = 1)
    End With

    With e("chkREN")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (IsSynchronMode(r, vIndex)) Then
          .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip("synchronous mode is selected")         
        Else
          .DisabledTooltipText = .DisabledTooltipText & sDisabledClockOrPinsOrAutoBaudTooltip
        End If
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: chkLB (show)
    '-------------------------------------------------------------------------
    With c("chkLB")
      If (IsSynchronMode(r, vIndex)) Then
        bDisabled = True
      Else
        bDisabled = bDisabledClockOrPinsOrAutoBaud 
      End If
      .Enabled = Not(bDisabled)
      .Value = -CInt(r.v(sRegPre & "CON_LB") = 1)
    End With

    With e("chkLB")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (IsSynchronMode(r, vIndex)) Then
          .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip("synchronous mode is selected")         
        Else
          .DisabledTooltipText = .DisabledTooltipText & sDisabledClockOrPinsOrAutoBaudTooltip
        End If
      End If
    End With

    For i = 0 To 1
      '-------------------------------------------------------------------------
      ' control: optSTP_x (show) (x = 0,1)
      '-------------------------------------------------------------------------
      With c("optSTP_" & i)
        bDisabled = bDisabledClockOrPinsOrAutoBaud Or IsSynchronMode(r, vIndex) Or r.v(sRegPre & "CON_M") = 2
        .Enabled = Not(bDisabled)
        .Value = -CInt(r.v(sRegPre & "CON_STP") = i)
      End With

      With e("optSTP_" & i)
        If (bDisabled) Then
          .DisabledTooltipText = TOOLTIP_DISABLED_IF
          If (IsSynchronMode(r, vIndex)) Then
            .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip("synchronous mode is selected")
          Else
            .DisabledTooltipText = .DisabledTooltipText & sDisabledClockOrPinsOrAutoBaudTooltip
          End If
          If (r.v(sRegPre & "CON_M") = 2) Then ' if IrDA mode
            .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip("IrDA mode is selected")
          End If
        End If
      End With
    Next i

    For i = 0 To 1
      '-------------------------------------------------------------------------
      ' control: optODD_x (show) (x = 0,1)
      '-------------------------------------------------------------------------
      With c("optODD_" & i)
        bDisabled = bDisabledClockOrPinsOrAutoBaud Or (r.v(sRegPre & "CON_M") <> 3 And  r.v(sRegPre & "CON_M") <> 7)
        .Enabled = Not(bDisabled)
        .Value = -CInt(r.v(sRegPre & "CON_ODD") = i)
      End With

      With e("optODD_" & i)
        If (bDisabled) Then
          .DisabledTooltipText = TOOLTIP_DISABLED_IF
          If (IsSynchronMode(r, vIndex)) Then
            .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip("synchronous mode is selected")
          Else
            .DisabledTooltipText = .DisabledTooltipText & sDisabledClockOrPinsOrAutoBaudTooltip
            If (r.v(sRegPre & "CON_M") <> 3 And  r.v(sRegPre & "CON_M") <> 7) Then
              .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip("no asynchronous mode with parity check is selected")
            End If
          End If
        End If
      End With
    Next i

    '-------------------------------------------------------------------------
    ' control: chkOEN (show)
    '-------------------------------------------------------------------------
    With c("chkOEN")
      bDisabled = bDisabledClockOrPins 
      .Enabled = Not(bDisabled)
      .Value = -CInt(r.v(sRegPre & "CON_OEN") = 1)
    End With

    With e("chkOEN")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        .DisabledTooltipText = .DisabledTooltipText & sDisabledClockOrPinsTooltip
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: chkFEN (show)
    '-------------------------------------------------------------------------
    With c("chkFEN")
      bDisabled = IsSynchronMode(r, vIndex) Or bDisabledClockOrPins
      .Enabled = Not(bDisabled)
      .Value = -CInt(r.v(sRegPre & "CON_FEN") = 1)
    End With

    With e("chkFEN")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (IsSynchronMode(r, vIndex)) Then
          .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip("synchronous mode is selected")
        Else
          .DisabledTooltipText = .DisabledTooltipText & sDisabledClockOrPinsTooltip
        End If
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: chkPEN (show)
    '-------------------------------------------------------------------------
    With c("chkPEN")
      bDisabled =  bDisabledClockOrPins Or Not((r.v(sRegPre & "CON_M") = 3 Or r.v(sRegPre & "CON_M") = 2 Or r.v(sRegPre & "CON_M") = 7))
      .Enabled = Not(bDisabled)
      If (r.v(sRegPre & "CON_M") = 2) Then
        .Caption = "Invert receiver input (RXDI)"
      Else
        .Caption = "Enable parity check (PEN)"
      End If
      .Value = -CInt(r.v(sRegPre & "CON_PEN_RXDI") = 1)
    End With
 
    With e("chkPEN")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        If (IsSynchronMode(r, vIndex)) Then
          .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip("synchronous mode is selected")
        Else
          .DisabledTooltipText = .DisabledTooltipText & sDisabledClockOrPinsTooltip
          If Not(r.v(sRegPre & "CON_M") = 3 Or r.v(sRegPre & "CON_M") = 7 OR r.v(sRegPre & "CON_M") = 2) Then
            .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip("no asynchronous mode with parity check is selected")
          End If
        End If
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: chkTSRC (show)
    '-------------------------------------------------------------------------
    With c("chkTSRC")
      bDisabled = bDisabledClockOrPins
      .Enabled = Not(bDisabled)
      .Value = -CInt(r.v(sRegPre & "TIC_IE") = 1)	  
    End With

    With e("chkTSRC")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        .DisabledTooltipText = .DisabledTooltipText & sDisabledClockOrPinsTooltip
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: chkTBSRC (show)
    '-------------------------------------------------------------------------
    With c("chkTBSRC")
      bDisabled = bDisabledClockOrPins
      .Enabled = Not(bDisabled)
      .Value = -CInt(r.v(sRegPre & "TBIC_IE") = 1)	  
    End With

    With e("chkTBSRC")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        .DisabledTooltipText = .DisabledTooltipText & sDisabledClockOrPinsTooltip
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: chkRSRC (show)
    '-------------------------------------------------------------------------
    With c("chkRSRC")
      bDisabled = bDisabledClockOrPins
      .Enabled = Not(bDisabled)
      .Value = -CInt(r.v(sRegPre & "RIC_IE") = 1)	  
    End With

    With e("chkRSRC")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        .DisabledTooltipText = .DisabledTooltipText & sDisabledClockOrPinsTooltip
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: chkESRC (show)
    '-------------------------------------------------------------------------
    With c("chkESRC")
      bDisabled = bDisabledClockOrPins Or IsErrorCheckDisabled(r, vIndex) 
      .Enabled = Not(bDisabled)
      .Value = -CInt(r.v(sRegPre & "EIC_IE") = 1)	  
    End With

    With e("chkESRC")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        .DisabledTooltipText = .DisabledTooltipText & sDisabledClockOrPinsTooltip
        If (IsErrorCheckDisabled(r, vIndex)) Then
   	      .DisabledTooltipText = .DisabledTooltipText & FormatDisabledTooltip("no error check is enabled")
        End If
      End If
    End With

  End If

  OnShowPageControl = True
  Exit Function

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


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

  Dim r As ProjectData 
  Dim vIndex As Variant
  Set r = ps.ProjectData
  vIndex = ps.Parameters.v("x")

  OnLoadPageFIFO = False
  If (IsFIFOAvailable(r, vIndex)) Then
    If (Not ps.AddPage("FIFO")) Then Exit Function
  End If

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

  OnChangingPageFIFO = False

  Dim r As ProjectData 
  Dim vIndex As Variant
  Set r = ps.ProjectData
  vIndex = ps.Parameters.v("x")

  If (IsFIFOAvailable(r, vIndex)) Then
    If (Not ps.ExtenderCollection("FIFO").Loaded) And (Pagename = "FIFO") Then
      ps.ExtenderCollection("FIFO").Loaded = True
    
      '-------------------------------
      ' frame: frmRXFEN
      '-------------------------------
      If (Not ps.AddFrame("frmRXFEN",100,100, 4100, 950, "Receive FIFO Enable")) Then Exit Function
          If (Not ps.AddCheck("chkRXFEN", 200, 350, 2900, 380, "Enable the reveive FIFO (RXFEN)")) Then Exit Function

      '-------------------------------
      ' frame: frmTXFEN
      '-------------------------------
      If (Not ps.AddFrame("frmTXFEN",4400,100, 4150, 950, "Transmit FIFO Enable")) Then Exit Function
          If (Not ps.AddCheck("chkTXFEN", 200, 350, 2900, 380, "Enable the transmit FIFO (TXFEN)")) Then Exit Function

      '-------------------------------
      ' frame: frmRXTMEN
      '-------------------------------
      If (Not ps.AddFrame("frmRXTMEN",100,1200, 4100, 1100, "Receive FIFO Transparent Mode Enable")) Then Exit Function
          If (Not ps.AddCheck("chkRXTMEN", 200, 400, 3450, 400, "Enable the receive FIFO transparent mode (RXTMEN)")) Then Exit Function

      '-------------------------------
      ' frame: frmTXTMEN
      '-------------------------------
      If (Not ps.AddFrame("frmTXTMEN",4400,1200, 4150, 1100, "Transmit FIFO Transparent Mode")) Then Exit Function
          If (Not ps.AddCheck("chkTXTMEN", 200, 400, 3500, 400, "Enable the transmit FIFO transparent mode (TXTMEN)")) Then Exit Function

      '-------------------------------
      ' frame: frmRXFITL
      '-------------------------------
      If (Not ps.AddFrame("frmRXFITL",100,2450, 4100, 1150, "Receive FIFO Interrupt Trigger Level")) Then Exit Function
          If (Not ps.AddLabel("lblRXFITL", 0, 200, 450, 1575, 405, "Interrupt trigger level (RXFITL)")) Then Exit Function
          If (Not ps.AddCombo("cboRXFITL", 1900, 500, 2000, 315)) Then Exit Function

      '-------------------------------
      ' frame: frmTXFITL
      '-------------------------------
      If (Not ps.AddFrame("frmTXFITL",4400,2450, 4150, 1150, "Transmit FIFO Interrupt Trigger Level")) Then Exit Function
          If (Not ps.AddLabel("lblTXFITL", 0, 200, 450, 1575, 405, "Interrupt trigger level (TXFITL)")) Then Exit Function
          If (Not ps.AddCombo("cboTXFITL", 1900, 500, 2000, 315)) Then Exit Function

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

  OnShowPageFIFO = False

  Dim r As ProjectData
  Dim c As Object
  Dim e As Object
  Dim bDisabled As Boolean
  Dim vIndex As Variant
  Dim sVarPre As String
  Dim sRegPre As String
  Dim bDisabledClockOrPins As Boolean
  Dim sDisabledClockOrPinsTooltip As String
  Dim i As Integer

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

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

  If (IsFIFOAvailable(r, vIndex)) Then
    If (Pagename = "FIFO") Then
      '-------------------------------------------------------------------------
      ' page: FIFO (action)
      '-------------------------------------------------------------------------
      Select Case (Controlname)
          '---------------------------------------------------------------------
          ' control: chkRXFEN (action)
          '---------------------------------------------------------------------
          Case "chkRXFEN"
               r.v(sRegPre & "RXFCON_RXFEN") = v(1)
               If (v(1) = 0) Then
                 r.v(sRegPre & "RXFCON_RXTMEN") = 0
                 r.v(sVarPre & "_USE_FlushRxFIFO") = 0
                 r.v(sVarPre & "_USE_GetRxFIFOFillingLevel") = 0
               End If

          '---------------------------------------------------------------------
          ' control: chkTXFEN (action)
          '---------------------------------------------------------------------
          Case "chkTXFEN"
               r.v(sRegPre & "TXFCON_TXFEN") = v(1)
               If (v(1) = 0) Then
                 r.v(sRegPre & "TXFCON_TXTMEN") = 0
                 r.v(sVarPre & "_USE_FlushTxFIFO") = 0
                 r.v(sVarPre & "_USE_GetTxFIFOFillingLevel") = 0
               End If

          '---------------------------------------------------------------------
          ' control: chkRXTMEN (action)
          '---------------------------------------------------------------------
          Case "chkRXTMEN"
               r.v(sRegPre & "RXFCON_RXTMEN") = v(1)
               r.v(sRegPre & "RXFCON_RXFITL") = 8

          '---------------------------------------------------------------------
          ' control: chkTXTMEN (action)
          '---------------------------------------------------------------------
          Case "chkTXTMEN"
               r.v(sRegPre & "TXFCON_TXTMEN") = v(1)
               r.v(sRegPre & "TXFCON_TXFITL") = 8

          '---------------------------------------------------------------------
          ' control: cboRXFITL (action)
          '---------------------------------------------------------------------
          Case "cboRXFITL"
              For i = 1 To 8
                If (v(1) = "Trigger level = " & i) Then
                  r.v(sRegPre & "RXFCON_RXFITL") = i
                  Exit For
                End If
              Next i

          '---------------------------------------------------------------------
          ' control: cboTXFITL (action)
          '---------------------------------------------------------------------
          Case "cboTXFITL"
              For i = 1 To 8
                If (v(1) = "Trigger level = " & i) Then
                  r.v(sRegPre & "TXFCON_TXFITL") = i
                  Exit For
                End If
              Next i

          Case Else
      End Select

      '-------------------------------------------------------------------------
      ' page: FIFO (show)
      '-------------------------------------------------------------------------
      ' save the disabled condition for the module clock and the pins
      bDisabledClockOrPins = IsModuleClockDisabled(r, vIndex) Or IsPinInterfaceDeselected(r, vIndex)      ' save the tooltip for the module clock and the pins

      ' save the tooltip for the module clock and the pins
      sDisabledClockOrPinsTooltip = GetTooltipModuleClockDisabled(r, vIndex)
      sDisabledClockOrPinsTooltip = sDisabledClockOrPinsTooltip & GetTooltipPinInterfaceDeselected(r, vIndex)

      '-------------------------------------------------------------------------
      ' control: chkRXFEN (show)
      '-------------------------------------------------------------------------
      With c("chkRXFEN")
        bDisabled = bDisabledClockOrPins
        .Enabled = Not(bDisabled)
        .Value = -CInt(r.v(sRegPre & "RXFCON_RXFEN") = 1)
      End With

      With e("chkRXFEN")
        If (bDisabled) Then
          .DisabledTooltipText = TOOLTIP_DISABLED_IF
          .DisabledTooltipText = .DisabledTooltipText & sDisabledClockOrPinsTooltip
        End If
      End With

      '-------------------------------------------------------------------------
      ' control: chkTXFEN (show)
      '-------------------------------------------------------------------------
      With c("chkTXFEN")
        bDisabled = bDisabledClockOrPins
        .Enabled = Not(bDisabled)
        .Value = -CInt(r.v(sRegPre & "TXFCON_TXFEN") = 1)
      End With

      With e("chkTXFEN")
        If (bDisabled) Then
          .DisabledTooltipText = TOOLTIP_DISABLED_IF
          .DisabledTooltipText = .DisabledTooltipText & sDisabledClockOrPinsTooltip
        End If
      End With

      '-------------------------------------------------------------------------
      ' control: chkRXTMEN (show)
      '-------------------------------------------------------------------------
      With c("chkRXTMEN")
        bDisabled = bDisabledClockOrPins Or r.v(sRegPre & "RXFCON_RXFEN") = 0
        .Enabled = Not(bDisabled)
        .Value = -CInt(r.v(sRegPre & "RXFCON_RXTMEN") = 1)
      End With

      With e("chkRXTMEN")
        If (bDisabled) Then
          .DisabledTooltipText = TOOLTIP_DISABLED_IF
          .DisabledTooltipText = .DisabledTooltipText & sDisabledClockOrPinsTooltip
          If (r.v(sRegPre & "RXFCON_RXFEN") = 0) Then
            .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip("the receive FIFO is not enabled")         
          End If
        End If
      End With

      '-------------------------------------------------------------------------
      ' control: chkTXTMEN (show)
      '-------------------------------------------------------------------------
      With c("chkTXTMEN")
        bDisabled = bDisabledClockOrPins Or r.v(sRegPre & "TXFCON_TXFEN") = 0
        .Enabled = Not(bDisabled)
        .Value = -CInt(r.v(sRegPre & "TXFCON_TXTMEN") = 1)
      End With

      With e("chkTXTMEN")
        If (bDisabled) Then
          .DisabledTooltipText = TOOLTIP_DISABLED_IF
          .DisabledTooltipText = .DisabledTooltipText & sDisabledClockOrPinsTooltip
          If (r.v(sRegPre & "TXFCON_TXFEN") = 0) Then
            .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip("the transmit FIFO is not enabled")         
          End If
        End If
      End With

      '-------------------------------------------------------------------------
      ' control: cboRXFITL (show)
      '-------------------------------------------------------------------------
      With c("cboRXFITL")
        ' disable condition
        bDisabled = bDisabledClockOrPins Or r.v(sRegPre & "RXFCON_RXFEN") = 0 Or r.v(sRegPre & "RXFCON_RXTMEN") = 1
        .Enabled = Not(bDisabled)
        .Clear
        For i = 1 To 8
          .AddItem "Trigger level = " & i
        Next i
        .ListIndex = r.v(sRegPre & "RXFCON_RXFITL") - 1
      End With

      With e("cboRXFITL")
        If (bDisabled) Then
          .DisabledTooltipText = TOOLTIP_DISABLED_IF
          .DisabledTooltipText = .DisabledTooltipText & sDisabledClockOrPinsTooltip
          If (r.v(sRegPre & "RXFCON_RXFEN") = 0) Then
            .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip("the receive FIFO is not enabled")         
          End If
          If (r.v(sRegPre & "RXFCON_RXTMEN") = 1) Then
            .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip("the receive FIFO transparent mode is enabled")         
          End If
        End If
      End With

      '-------------------------------------------------------------------------
      ' control: lblRXFITL (show)
      '-------------------------------------------------------------------------
      With c("lblRXFITL")
        ' same as for cboRXFITL
        .Enabled = Not(bDisabled)
      End With

      With e("lblRXFITL")
        If (bDisabled) Then
          .DisabledTooltipText = e("cboRXFITL").DisabledTooltipText
        End If
      End With

      '-------------------------------------------------------------------------
      ' control: cboTXFITL (show)
      '-------------------------------------------------------------------------
      With c("cboTXFITL")
        ' disable condition
        bDisabled = bDisabledClockOrPins Or r.v(sRegPre & "TXFCON_TXFEN") = 0 Or r.v(sRegPre & "TXFCON_TXTMEN") = 1
        .Enabled = Not(bDisabled)
        .Clear
        For i = 1 To 8
          .AddItem "Trigger level = " & i
        Next i
        .ListIndex = r.v(sRegPre & "TXFCON_TXFITL") - 1
      End With

      With e("cboTXFITL")
        If (bDisabled) Then
          .DisabledTooltipText = TOOLTIP_DISABLED_IF
          .DisabledTooltipText = .DisabledTooltipText & sDisabledClockOrPinsTooltip
          If (r.v(sRegPre & "TXFCON_TXFEN") = 0) Then
            .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip("the transmit FIFO is not enabled")         
          End If
          If (r.v(sRegPre & "TXFCON_TXTMEN") = 1) Then
            .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip("the transmit FIFO transparent mode is enabled")         
          End If
        End If
      End With

      '-------------------------------------------------------------------------
      ' control: lblTXFITL (show)
      '-------------------------------------------------------------------------
      With c("lblTXFITL")
        ' same as for cboTXFITL
        .Enabled = Not(bDisabled)
      End With

      With e("lblTXFITL")
        If (bDisabled) Then
          .DisabledTooltipText = e("cboTXFITL").DisabledTooltipText
        End If
      End With

    End If
  End If

  OnShowPageFIFO = True
  Exit Function

OnShowPageFIFOError:
  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 'BaudrateASCx'.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnLoadPageBaudrateASCx(ps As Object) As Boolean
  On Error Resume Next

  OnLoadPageBaudrateASCx = False

  If (Not ps.AddPage("Baud Rate")) Then Exit Function

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

  OnChangingPageBaudrateASCx = False
  
  If (Not ps.ExtenderCollection("Baud Rate").Loaded) And (Pagename = "Baud Rate") Then
    ps.ExtenderCollection("Baud Rate").Loaded = True
  

    '-------------------------------
    ' frame: frmBRS/FDE
    '-------------------------------
    If (Not ps.AddFrame("frmBRS/FDE",100,100, 4750, 1750, "Baud Rate Selection Bit (BRS) / Fractional Divider (FDE)")) Then Exit Function
        If (Not ps.AddOption("optBRS_0", 200, 350, 3125, 300, "Additionally reduce serial clock to 2")) Then Exit Function
        If (Not ps.AddOption("optBRS_1", 200, 800, 3100, 300, "Additionally reduce serial clock to 3")) Then Exit Function
        If (Not ps.AddCheck("chkFDE", 200, 1250, 4450, 300, "Use fractional divider as prescaler for baud rate timer (FDE)")) Then Exit Function

    '-------------------------------
    ' frame: frmR
    '-------------------------------
    If (Not ps.AddFrame("frmR",5075,100, 3425, 1750, "Baud Rate Generator Run Control (R)")) Then Exit Function
        If (Not ps.AddOption("optR_0", 200, 550, 3100, 300, "Disable baud rate generator")) Then Exit Function
        If (Not ps.AddOption("optR_1", 200, 1050, 3100, 300, "Enable baud rate generator")) Then Exit Function

    '-------------------------------
    ' frame: frmBaudrate
    '-------------------------------
    If (Not ps.AddFrame("frmBaudrate",100,2000, 8400, 3200, "Baud Rate")) Then Exit Function
        If (Not ps.AddLabel("lblReqBR", 0, 200, 650, 2200, 300, "")) Then Exit Function
        If (Not ps.AddLabel("lblRealBR0", 0, 4400, 650, 1775, 300, "")) Then Exit Function
        If (Not ps.AddLabel("lblMinBR0", 0, 200, 1850, 1875, 300, "")) Then Exit Function
        If (Not ps.AddLabel("lblMaxBR0", 0, 200, 2450, 1825, 300, "")) Then Exit Function
        If (Not ps.AddLabel("lblFD_VALUE", 0, 200, 1250, 1975, 300, "Fractional divider (n / 512)")) Then Exit Function
        If (Not ps.AddText("txtReqBR", 2400, 600, 1100, 300)) Then Exit Function
        If (Not ps.AddText("txtFD_VALUE", 2400, 1200, 1100, 300)) Then Exit Function
        If (Not ps.AddLabel("lblMinBR1", 1, 2400, 1800, 1100, 300, "")) Then Exit Function
        If (Not ps.AddLabel("lblMaxBR1", 1, 2400, 2400, 1100, 300, "")) Then Exit Function
        If (Not ps.AddLabel("lblRealBR1", 1, 6600, 600, 1000, 300, "")) Then Exit Function
        If (Not ps.AddLabel("lblPerc0", 0, 4400, 1250, 2025, 300, "Percentage of deviation [%]")) Then Exit Function
        If (Not ps.AddLabel("lblBR_VALUE", 0, 4400, 1850, 2025, 300, "Reload value (RL)")) Then Exit Function
        If (Not ps.AddLabel("lblPerc1", 1, 6600, 1200, 1000, 300, "")) Then Exit Function
        If (Not ps.AddText("txtBR_VALUE", 6600, 1800, 1000, 300)) Then Exit Function

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

  OnShowPageBaudrateASCx = False

  Dim r As ProjectData
  Dim c As Object
  Dim e As Object
  Dim bDisabled As Boolean
  Dim bDisabledClockOrPinsOrAutoBaud As Boolean
  Dim bDisabledClockOrPins As Boolean
  Dim sDisabledClockOrPinsOrAutoBaudTooltip As String
  Dim sDisabledClockOrPinsTooltip As String

  Dim sRegPre As String
  Dim sVarPre As String
  Dim vIndex As Variant
  Dim Baudrate As UnitType
  Dim MaxBaudRate As UnitType

  vIndex = ps.Parameters.v("x")
  sVarPre = "ASC" & Format$(vIndex)
  sRegPre = "ASC" & Format$(vIndex) & "_"
  

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

  If (Pagename = "Baud Rate") Then
    '-------------------------------------------------------------------------
    ' page: BaudrateASCx (action)
    '-------------------------------------------------------------------------
    Select Case (Controlname)
        '---------------------------------------------------------------------
        ' control: optBRS_0 (action)
        '---------------------------------------------------------------------
        Case "optBRS_0"
             r.v(sRegPre & "CON_BRS") = 0           
             Call UpdateASCxBaudrate(r, vIndex)

        '---------------------------------------------------------------------
        ' control: optBRS_1 (action)
        '---------------------------------------------------------------------
        Case "optBRS_1"
             r.v(sRegPre & "CON_BRS") = 1
             Call UpdateASCxBaudrate(r, vIndex)

        '---------------------------------------------------------------------
        ' control: chkFDE (action)
        '---------------------------------------------------------------------
        Case "chkFDE"
             r.v(sRegPre & "CON_FDE") = v(1)
             Call UpdateASCxBaudrate(r, vIndex)
             
        '---------------------------------------------------------------------
        ' control: optR_0 (action)
        '---------------------------------------------------------------------
        Case "optR_0"
             r.v(sRegPre & "CON_R") = 0
 
        '---------------------------------------------------------------------
        ' control: optR_1 (action)
        '---------------------------------------------------------------------
        Case "optR_1"
             r.v(sRegPre & "CON_R") = 1

        '---------------------------------------------------------------------
        ' control: txtReqBR (action)
        '---------------------------------------------------------------------
        Case "txtReqBR"
             Baudrate = ConvertBaudrate(r.v(sVarPre & "_Baudrate"))
             MaxBaudRate = ConvertBaudrate(GetASCxMaxBaudrate(r, vIndex))

             If (IsInputFormatOK(v(1), "F", c("lblReqBR").Caption, , )) Then
               If (IsInputValueOK(Format(v(1) * Baudrate.dDivider, ASC_PRECISION), Format(GetASCxMinBaudrate(r, vIndex), ASC_PRECISION), Format(Format(GetASCxMaxBaudrate(r, vIndex)/MaxBaudRate.dDivider, ASC_PRECISION) * MaxBaudRate.dDivider, ASC_PRECISION) )) Then
                 r.d(sVarPre & "_Baudrate") = v(1) * Baudrate.dDivider  ' convert to baud
                 Call UpdateASCxBaudrate(r, vIndex)
                 Call UpdateIrDA(r, vIndex)
               Else
                 Exit Function
               End If
             Else
                 Exit Function
             End If

        '---------------------------------------------------------------------
        ' control: txtFD_VALUE (action)
        '---------------------------------------------------------------------
        Case "txtFD_VALUE"
             If (IsInputFormatOK(v(1), "D", c("lblFD_VALUE").Caption, 0, 511)) Then
               r.v(sRegPre & "FDV_FD_VALUE") = v(1)
               Call UpdateASCxBaudrate(r, vIndex)
               Call UpdateIrDA(r, vIndex)
             Else
                 Exit Function
             End If

        '---------------------------------------------------------------------
        ' control: txtBR_VALUE (action)
        '---------------------------------------------------------------------
        Case "txtBR_VALUE"
             If (IsInputFormatOK(v(1), "H4", c("lblBR_VALUE").Caption, GetMinBR_Value(r, vIndex), 8191)) Then
               r.l(sRegPre & "BG_BR_VALUE") = v(1)
               r.d(sVarPre & "_Baudrate") = GetASCxRealBaudrate(r, vIndex)
               Call UpdateIrDA(r, vIndex)
             Else
                 Exit Function
             End If

      Case Else
    End Select

    '-------------------------------------------------------------------------
    ' page: BaudrateASCx (show)
    '-------------------------------------------------------------------------
    ' save the disabled condition for the module clock and the pins
    bDisabledClockOrPins = IsModuleClockDisabled(r, vIndex) Or IsPinInterfaceDeselected(r, vIndex)      ' save the tooltip for the module clock and the pins
    ' save the disabled condition for the module clock, the pins and the autobaud mode
    bDisabledClockOrPinsOrAutoBaud = bDisabledClockOrPins Or IsAutobaudSelected(r, vIndex)

    ' save the tooltip for the module clock and the pins
    sDisabledClockOrPinsTooltip = GetTooltipModuleClockDisabled(r, vIndex)
    sDisabledClockOrPinsTooltip = sDisabledClockOrPinsTooltip & GetTooltipPinInterfaceDeselected(r, vIndex)

    ' save the tooltip for the module clock, the pins and the autobaud mode
    sDisabledClockOrPinsOrAutoBaudTooltip = sDisabledClockOrPinsTooltip & GetTooltipAutobaudSelected(r, vIndex)

'    Call SetDefaultPropertiesForAllControlsOnFrame(c("frmM").Caption, c, e, bDisabledClockOrPinsOrAutoBaud, TOOLTIP_DISABLED_IF & sDisabledClockOrPinsOrAutoBaudTooltip, "")

    '-------------------------------------------------------------------------
    ' control: optBRS_0 (show)
    '-------------------------------------------------------------------------
    With c("optBRS_0")
      bDisabled = bDisabledClockOrPinsOrAutoBaud Or r.v(sRegPre & "CON_FDE") = 1
      .Enabled = Not(bDisabled)
      .Value = -CInt(r.v(sRegPre & "CON_BRS") = 0)
    End With

    With e("optBRS_0")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        .DisabledTooltipText = .DisabledTooltipText & sDisabledClockOrPinsOrAutoBaudTooltip
        If (r.v(sRegPre & "CON_FDE") = 1) Then
          .DisabledTooltipText = .DisabledTooltipText & FormatDisabledTooltip("fraction divider (FDE) is used")
        End If
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: optBRS_1 (show)
    '-------------------------------------------------------------------------
    With c("optBRS_1")
      bDisabled = bDisabledClockOrPinsOrAutoBaud Or r.v(sRegPre & "CON_FDE") = 1
      .Enabled = Not(bDisabled)
      .Value = -CInt(r.v(sRegPre & "CON_BRS") = 1)
    End With

    With e("optBRS_1")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        .DisabledTooltipText = .DisabledTooltipText & sDisabledClockOrPinsOrAutoBaudTooltip
        If (r.v(sRegPre & "CON_FDE") = 1) Then
          .DisabledTooltipText = .DisabledTooltipText & FormatDisabledTooltip("fraction divider (FDE) is used")
        End If
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: chkFDE (show)
    '-------------------------------------------------------------------------
    With c("chkFDE")
      bDisabled = bDisabledClockOrPinsOrAutoBaud Or IsSynchronMode(r, vIndex)
      .Enabled = Not(bDisabled)
     .Value = -CInt(r.v(sRegPre & "CON_FDE") = 1)
    End With

    With e("chkFDE")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        .DisabledTooltipText = .DisabledTooltipText & sDisabledClockOrPinsOrAutoBaudTooltip
        If (IsSynchronMode(r, vIndex)) Then
          .DisabledTooltipText = .DisabledTooltipText & FormatDisabledTooltip("synchronous mode is selected")
        End If
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: optR_0 (show)
    '-------------------------------------------------------------------------
    With c("optR_0")
      bDisabled = bDisabledClockOrPinsOrAutoBaud
      .Enabled = Not(bDisabled)
      .Value = -CInt(r.v(sRegPre & "CON_R") = 0)
    End With

    With e("optR_0")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        .DisabledTooltipText = .DisabledTooltipText & sDisabledClockOrPinsOrAutoBaudTooltip
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: optR_1 (show)
    '-------------------------------------------------------------------------
    With c("optR_1")
      bDisabled = bDisabledClockOrPinsOrAutoBaud
      .Enabled = Not(bDisabled)
      .Value = -CInt(r.v(sRegPre & "CON_R") = 1)
    End With

    With e("optR_1")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        .DisabledTooltipText = .DisabledTooltipText & sDisabledClockOrPinsOrAutoBaudTooltip
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: txtReqBR (show)
    '-------------------------------------------------------------------------
    With c("txtReqBR")
      bDisabled = bDisabledClockOrPinsOrAutoBaud
      .Enabled = Not(bDisabled)
      If (bDisabled) Then
        .Text = CALCULATION_NOT_POSSIBLE
        c("lblReqBR").Caption = "Required baud rate [baud]"
      Else
        Baudrate = ConvertBaudrate(r.d(sVarPre & "_Baudrate"))
        .Text = Format(Baudrate.dValue, ASC_PRECISION)
        c("lblReqBR").Caption = "Required baud rate [" & Baudrate.sUnit & "]"
      End If
    End With

    With e("txtReqBR")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        .DisabledTooltipText = .DisabledTooltipText & sDisabledClockOrPinsOrAutoBaudTooltip
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: lblReqBR (show)
    '-------------------------------------------------------------------------
    With c("lblReqBR")
      ' same as for "txtReqBR"
      .Enabled = Not(bDisabled)
    End With

    With e("lblReqBR")
      If (bDisabled) Then
        ' tooltip if control is disabled 
        .DisabledTooltipText = e("txtReqBR").DisabledToolTipText
      Else
        ' tooltip if control is enabled 
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: txtFD_VALUE (show)
    '-------------------------------------------------------------------------
    With c("txtFD_VALUE")
      bDisabled = True
      .Enabled = Not(bDisabled)
      If (r.v(sRegPre & "CON_FDE") = 0) Then
        .Text = CALCULATION_NOT_POSSIBLE
      Else
        .Text = r.v(sRegPre & "FDV_FD_VALUE")
      End If
    End With

    With e("txtFD_VALUE")
      If (bDisabled) Then
        .DisabledTooltipText = ""
        .DisabledTooltipText = .DisabledTooltipText & FormatNormalTooltip("This value will be set by DAvE if the fractional divider is enabled.")
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: lblFD_VALUE (show)
    '-------------------------------------------------------------------------
    With c("lblFD_VALUE")
      ' same as for "txtFD_VALUE"
      .Enabled = Not(bDisabled)
    End With

    With e("lblFD_VALUE")
      If (bDisabled) Then
        ' tooltip if control is disabled 
        .DisabledTooltipText = e("txtFD_VALUE").DisabledToolTipText
      Else
        ' tooltip if control is enabled 
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: lblMinBR1 (show)
    '-------------------------------------------------------------------------
    With c("lblMinBR1")
      bDisabled = bDisabledClockOrPinsOrAutoBaud
      .Enabled = Not(bDisabled)
      If (bDisabled) Then
        .Caption = CALCULATION_NOT_POSSIBLE
        c("lblMinBR0").Caption = "Min. baud rate [baud]"
      Else
        Baudrate = ConvertBaudrate(GetASCxMinBaudrate(r, vIndex))
        .Caption = Format(Baudrate.dValue, ASC_PRECISION)
        c("lblMinBR0").Caption = "Min. baud rate [" & Baudrate.sUnit & "]"
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: lblMinBR0 (show)
    '-------------------------------------------------------------------------
    With c("lblMinBR0")
      ' same as for "lblMinBR1"
      .Enabled = Not(bDisabled)
    End With

    With e("lblMinBR0")
      If (bDisabled) Then
        ' tooltip if control is disabled 
'        .DisabledTooltipText = e("lblMinBR1").DisabledToolTipText
      Else
        ' tooltip if control is enabled 
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: lblMaxBR1 (show)
    '-------------------------------------------------------------------------
    With c("lblMaxBR1")
      bDisabled = bDisabledClockOrPinsOrAutoBaud
      .Enabled = Not(bDisabled)
      If (bDisabled) Then
        .Caption = CALCULATION_NOT_POSSIBLE
        c("lblMaxBR0").Caption = "Max. baud rate [baud]"
      Else
        Baudrate = ConvertBaudrate(GetASCxMaxBaudrate(r, vIndex))
        .Caption = Format(Baudrate.dValue, ASC_PRECISION)
        c("lblMaxBR0").Caption = "Max. baud rate [" & Baudrate.sUnit & "]"
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: lblMaxBR0 (show)
    '-------------------------------------------------------------------------
    With c("lblMaxBR0")
      ' same as for "lblMaxBR1"
      .Enabled = Not(bDisabled)
    End With

    With e("lblMaxBR0")
      If (bDisabled) Then
        ' tooltip if control is disabled 
'        .DisabledTooltipText = e("lblMaxBR1").DisabledToolTipText
      Else
        ' tooltip if control is enabled 
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: lblRealBR1 (show)
    '-------------------------------------------------------------------------
    With c("lblRealBR1")
      bDisabled = bDisabledClockOrPinsOrAutoBaud
      .Enabled = Not(bDisabled)
      If (bDisabled) Then
        .Caption = CALCULATION_NOT_POSSIBLE
        c("lblRealBR0").Caption = "Real baud rate [baud]"
      Else
        Baudrate = ConvertBaudrate(GetASCxRealBaudrate(r, vIndex))
        .Caption = Format(Baudrate.dValue, ASC_PRECISION)
        c("lblRealBR0").Caption = "Real baud rate [" & Baudrate.sUnit & "]"
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: lblRealBR0 (show)
    '-------------------------------------------------------------------------
    With c("lblRealBR0")
      ' same as for "lblRealBR1"
      .Enabled = Not(bDisabled)
    End With

    With e("lblRealBR0")
      If (bDisabled) Then
        ' tooltip if control is disabled 
'        .DisabledTooltipText = e("lblRealBR1").DisabledToolTipText
      Else
        ' tooltip if control is enabled 
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: lblPerc1 (show)
    '-------------------------------------------------------------------------
    With c("lblPerc1")
      bDisabled = bDisabledClockOrPinsOrAutoBaud
      .Enabled = Not(bDisabled)
      If (bDisabled) Then
        .Caption = CALCULATION_NOT_POSSIBLE
      Else
        .Caption = Format((Format(GetASCxRealBaudrate(r, vIndex), ASC_PRECISION) - Format(r.d(sVarPre & "_Baudrate"), ASC_PRECISION)) / Format(r.d(sVarPre & "_Baudrate"), ASC_PRECISION) * 100, ASC_PRECISION)
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: lblPerc0 (show)
    '-------------------------------------------------------------------------
    With c("lblPerc0")
      ' same as for "lblPerc1"
      .Enabled = Not(bDisabled)
    End With

    With e("lblPerc0")
      If (bDisabled) Then
        ' tooltip if control is disabled 
'        .DisabledTooltipText = e("lblPerc1").DisabledToolTipText
      Else
        ' tooltip if control is enabled 
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: txtBR_VALUE (show)
    '-------------------------------------------------------------------------
    With c("txtBR_VALUE")
      bDisabled = bDisabledClockOrPinsOrAutoBaud
      .Enabled = Not(bDisabled)
      If (bDisabled) Then
        .Text = CALCULATION_NOT_POSSIBLE
      Else
        .Text = FormatTextOutput(r.v(sRegPre & "BG_BR_VALUE"), "H4")
      End If
    End With

    With e("txtBR_VALUE")
      If (bDisabled) Then
        .DisabledTooltipText = TOOLTIP_DISABLED_IF
        .DisabledTooltipText = .DisabledTooltipText & sDisabledClockOrPinsOrAutoBaudTooltip
      End If
    End With

    '-------------------------------------------------------------------------
    ' control: lblBR_VALUE (show)
    '-------------------------------------------------------------------------
    With c("lblBR_VALUE")
      ' same as for "txtBR_VALUE"
      .Enabled = Not(bDisabled)
    End With

    With e("lblBR_VALUE")
      If (bDisabled) Then
        ' tooltip if control is disabled 
        .DisabledTooltipText = e("txtBR_VALUE").DisabledToolTipText
      Else
        ' tooltip if control is enabled 
      End If
    End With


  End If

  OnShowPageBaudrateASCx = True
  Exit Function

OnShowPageBaudrateASCxError:
  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 'IrDA'.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnLoadPageIrDA(ps As Object) As Boolean
  On Error Resume Next
  Dim r As ProjectData 
  Dim vIndex As Variant
  Set r = ps.ProjectData
  vIndex = ps.Parameters.v("x")

  OnLoadPageIrDA = False
  If (IsIrDAAvailable(r, vIndex)) Then
    If (Not ps.AddPage("IrDA")) Then Exit Function
  End If

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

  OnChangingPageIrDA = False

  Dim r As ProjectData 
  Dim vIndex As Variant
  Set r = ps.ProjectData
  vIndex = ps.Parameters.v("x")

  If (IsIrDAAvailable(r, vIndex)) Then 
    If (Not ps.ExtenderCollection("IrDA").Loaded) And (Pagename = "IrDA") Then
      ps.ExtenderCollection("IrDA").Loaded = True
    
      '-------------------------------
      ' frame: frmIRPW
      '-------------------------------
      If (Not ps.AddFrame("frmIRPW",100,100, 8400, 1500, "IrDA Pulse Width Selection (IRPW)")) Then Exit Function
          If (Not ps.AddOption("optIRPW_0", 200, 400, 3650, 300, "IrDA pulse width is 3/16 of the bit time (fixed)")) Then Exit Function
          If (Not ps.AddOption("optIRPW_1", 200, 850, 4600, 300, "IrDA pulse width is defined by PW")) Then Exit Function

      '-------------------------------
      ' frame: frmPulsWidth
      '-------------------------------
      If (Not ps.AddFrame("frmPulsWidth",100,1800, 8400, 3200, "Pulse Width")) Then Exit Function
          If (Not ps.AddText("txtEingabe", 2650, 550, 1000, 315)) Then Exit Function
          If (Not ps.AddLabel("lblEingabe", 0, 200, 600, 2350, 310, "xxxx")) Then Exit Function
          If (Not ps.AddLabel("lbl_box_Real", 1, 2650, 1200, 1000, 305, "xxxx")) Then Exit Function
          If (Not ps.AddLabel("lbl_txt_Real", 0, 200, 1200, 2350, 310, "xxxx")) Then Exit Function
          If (Not ps.AddLabel("lbl_box_Perc", 1, 2650, 1800, 1000, 305, "xxxx")) Then Exit Function
          If (Not ps.AddLabel("lbl_txt_Perc", 0, 200, 1800, 2100, 310, "Percentage of deviation [%]")) Then Exit Function
          If (Not ps.AddLabel("lbl_box_Fest", 1, 7000, 600, 1000, 305, "xxxx")) Then Exit Function
          If (Not ps.AddLabel("lbl_txt_Fest", 0, 5100, 600, 1575, 310, "xxxx")) Then Exit Function
          If (Not ps.AddText("txtPW", 2650, 2400, 1000, 315)) Then Exit Function
          If (Not ps.AddLabel("lblPW", 0, 200, 2450, 2350, 310, "Pulse width value (PW)")) Then Exit Function

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

  OnShowPageIrDA = False

  Dim r As ProjectData
  Dim c As Object
  Dim e As Object
  Dim bDisabled As Boolean
  Dim sRegPre As String
  Dim sVarPre As String
  Dim vIndex As Variant
  Dim bDisabledClockOrPinsOrAutoBaud As Boolean
  Dim bDisabledClockOrPins As Boolean
  Dim sDisabledClockOrPinsOrAutoBaudTooltip As String
  Dim sDisabledClockOrPinsTooltip As String
  Dim sDisabledTooltipText As String 

  vIndex = ps.Parameters.v("x")
  sRegPre = "ASC" & Format$(vIndex) & "_"
  sVarPre = "ASC" & Format$(vIndex)

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

  If (IsIrDAAvailable(r, vIndex)) Then 
    If (Pagename = "IrDA") Then
      '-------------------------------------------------------------------------
      ' page: ASCIrDA (action)
      '-------------------------------------------------------------------------
      Select Case (Controlname)
          '---------------------------------------------------------------------
          ' control: optIRPW_0 (action)
          '---------------------------------------------------------------------
          Case "optIRPW_0"
               r.v(sRegPre & "PMW_IRPW") = 0
               r.v(sRegPre & "PMW_PW_VALUE") = 2
               r.v(sVarPre & "_IRDA_REQ") = GetIrDARealPW(r, vIndex)

          '---------------------------------------------------------------------
          ' control: optIRPW_1 (action)
          '---------------------------------------------------------------------
          Case "optIRPW_1"
               r.v(sRegPre & "PMW_IRPW") = 1
               r.v(sVarPre & "_IRDA_REQ") = 1.627
               Call UpdateIrDA(r, vIndex)

          '---------------------------------------------------------------------
          ' control: txtPW (action)
          '---------------------------------------------------------------------
          Case "txtPW"
               If (IsInputFormatOK(v(1), "H2", c("lblPW").Caption, Format(GetIrDAMinPW_V(r, vIndex), ASC_PRECISION), Format(GetIrDAMaxPW_V(r, vIndex), ASC_PRECISION))) Then
                 r.v(sRegPre & "PMW_PW_VALUE") = v(1)
                 r.v(sVarPre & "_IRDA_REQ") = GetIrDARealPW(r, vIndex)
               Else
                 Exit Function
               End If

          '---------------------------------------------------------------------
          ' control: txtEingabe (action)
          '---------------------------------------------------------------------
          Case "txtEingabe"
               If (IsInputFormatOK(v(1), "F", c("lblEingabe").Caption, Format(GetIrDAReqMin(r, vIndex), ASC_PRECISION), Format(GetIrDAReqMax(r, vIndex), ASC_PRECISION))) Then
                 r.v(sVarPre & "_IRDA_REQ") = v(1)
                 Call UpdateIrDA(r, vIndex)
               Else
                 Exit Function
               End If

        Case Else
      End Select

      '-------------------------------------------------------------------------
      ' page: ASCIrDA (show)
      '-------------------------------------------------------------------------
      ' save the disabled condition for the module clock and the pins
      bDisabledClockOrPins = IsModuleClockDisabled(r, vIndex) Or IsPinInterfaceDeselected(r, vIndex)      ' save the tooltip for the module clock and the pins
      ' save the disabled condition for the module clock, the pins and the autobaud mode
      bDisabledClockOrPinsOrAutoBaud = bDisabledClockOrPins Or IsAutobaudSelected(r, vIndex)

      ' save the tooltip for the module clock and the pins
      sDisabledClockOrPinsTooltip = GetTooltipModuleClockDisabled(r, vIndex)
      sDisabledClockOrPinsTooltip = sDisabledClockOrPinsTooltip & GetTooltipPinInterfaceDeselected(r, vIndex)

      ' save the tooltip for the module clock, the pins and the autobaud mode
      sDisabledClockOrPinsOrAutoBaudTooltip = sDisabledClockOrPinsTooltip & GetTooltipAutobaudSelected(r, vIndex)

      bDisabled = bDisabledClockOrPinsOrAutoBaud Or r.v(sRegPre & "CON_M") <> 2
      sDisabledTooltipText = TOOLTIP_DISABLED_IF
      sDisabledTooltipText = sDisabledTooltipText & sDisabledClockOrPinsOrAutoBaudTooltip
      If (r.v(sRegPre & "CON_M") <> 2) Then
        sDisabledTooltipText = sDisabledTooltipText & FormatDisabledTooltip("IrDA mode not selected")
      End If

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

      '-------------------------------------------------------------------------
      ' control: optIRPW_0 (show)
      '-------------------------------------------------------------------------
      With c("optIRPW_0")
        .Value = -CInt(r.v(sRegPre & "PMW_IRPW") = 0)
      End With

      '-------------------------------------------------------------------------
      ' control: optIRPW_1 (show)
      '-------------------------------------------------------------------------
      With c("optIRPW_1")
        .Value = -CInt(r.v(sRegPre & "PMW_IRPW") = 1)
      End With

      '-------------------------------------------------------------------------
      ' control: txtEingabe (show)
      '-------------------------------------------------------------------------
      With c("txtEingabe")
        If (r.v(sRegPre & "CON_M") = 2) Then
          .Text = Format(r.v(sVarPre & "_IRDA_REQ"), ASC_PRECISION)
        Else
          .Text = CALCULATION_NOT_POSSIBLE
        End If
      End With

      '-------------------------------------------------------------------------
      ' control: lblEngabe (show)
      '-------------------------------------------------------------------------
      With c("lblEingabe")
        If (r.v(sRegPre & "PMW_IRPW") = 0) Then
          .Caption = "Required min. puls width [s]"
        Else
          .Caption = "Required puls width [s]"
        End If
      End With

      '-------------------------------------------------------------------------
      ' control: lbl_box_Real (show)
      '-------------------------------------------------------------------------
      With c("lbl_box_Real")
        If (r.v(sRegPre & "CON_M") = 2) Then
          .Caption = Format(GetIrDARealPW(r, vIndex), ASC_PRECISION)
        Else
          .Caption = CALCULATION_NOT_POSSIBLE
        End If
      End With

      '-------------------------------------------------------------------------
      ' control: lbl_txt_Real (show)
      '-------------------------------------------------------------------------
      With c("lbl_txt_Real")
        If (r.v(sRegPre & "PMW_IRPW") = 0) Then
          .Caption = "Real min. puls width [s]"
        Else
          .Caption = "Real puls width [s]"
        End If
      End With

      '-------------------------------------------------------------------------
      ' control: lbl_box_Perc (show)
      '-------------------------------------------------------------------------
      With c("lbl_box_Perc")
        If (r.v(sRegPre & "CON_M") = 2) Then
          .Caption = Format((GetIrDARealPW(r, vIndex) - r.v(sVarPre & "_IRDA_REQ")) * _
                             100 / r.v(sVarPre & "_IRDA_REQ"), ASC_PRECISION)
        Else
          .Caption = CALCULATION_NOT_POSSIBLE
        End If
      End With

      '-------------------------------------------------------------------------
      ' control: lbl_txt_Perc (show)
      '-------------------------------------------------------------------------
      With c("lbl_txt_Perc")
      End With

      '-------------------------------------------------------------------------
      ' control: lbl_box_Fest (show)
      '-------------------------------------------------------------------------
      With c("lbl_box_Fest")
        If (r.v(sRegPre & "CON_M") = 2) Then
          .Caption = Format(GetIrDAPW(r, vIndex), ASC_PRECISION)
        Else
          .Caption = CALCULATION_NOT_POSSIBLE
        End If
      End With

      '-------------------------------------------------------------------------
      ' control: lbl_txt_Fest (show)
      '-------------------------------------------------------------------------
      With c("lbl_txt_Fest")
        If (r.v(sRegPre & "PMW_IRPW") = 0) Then
          .Caption = "Puls width [s]"
        Else
          .Caption = "Min. puls width [s]"
        End If
      End With

      '-------------------------------------------------------------------------
      ' control: txtPW (show)
      '-------------------------------------------------------------------------
      With c("txtPW")
        If (r.v(sRegPre & "CON_M") = 2) Then
          .Text = FormatTextOutput(r.v(sRegPre & "PMW_PW_VALUE"), "H2")
        Else
          .Text = CALCULATION_NOT_POSSIBLE
        End If
      End With

      '-------------------------------------------------------------------------
      ' control: lblPW (show)
      '-------------------------------------------------------------------------
      With c("lblPW")
      End With


    End If
  End If

  OnShowPageIrDA = True
  Exit Function

OnShowPageIrDAError:
  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

  OnChangingPageFunctions = False

  Dim r As ProjectData 
  Dim vIndex As Variant
  Dim sVarPre As String
  Dim n As String
  Dim i As Integer
  Dim aFunctions(1 To 16) As String

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

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

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

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

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

    ' Functions and Macros
    i = Lbound(aFunctions)
    aFunctions(i) = "SendData"
    i = i + 1
    aFunctions(i) = "GetData"
    i = i + 1
    aFunctions(i) = "Tx"
    i = i + 1
    aFunctions(i) = "Rx"
    i = i + 1
    aFunctions(i) = "Error"
    i = i + 1
    aFunctions(i) = "TxBuffer"
    i = i + 1
    aFunctions(i) = "TxDataReady"
    i = i + 1
    aFunctions(i) = "TxBufFree"
    i = i + 1
    aFunctions(i) = "RxDataReady"
    i = i + 1
    aFunctions(i) = "ErrorCheck"
    If (IsAutobaudAvailable(r, vIndex)) Then
      i = i + 1
      aFunctions(i) = "Autobaud"
      i = i + 1
      aFunctions(i) = "GetAutobaudStatus"
    End If

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

    '-------------------------------------------------------------------------
    ' frame: frmLibrary2
    '-------------------------------------------------------------------------
    ' initialize the array
    For i = Lbound(aFunctions) To Ubound(aFunctions)
      aFunctions(i) = ""
    Next i

    ' Functions and Macros
    i = Lbound(aFunctions)
    aFunctions(i) = "ReceiverOn"
    i = i + 1
    aFunctions(i) = "ReceiverOff"
    i = i + 1
    aFunctions(i) = "SendSlaveAdr"
    i = i + 1
    aFunctions(i) = "OwnAddress"
    i = i + 1
    aFunctions(i) = "WakeUp"
    i = i + 1
    aFunctions(i) = "GotoSleep"
    i = i + 1
    aFunctions(i) = "SetBaudrate"
    i = i + 1
    aFunctions(i) = "StopBaudGen"
    i = i + 1
    aFunctions(i) = "StartBaudGen"
    If (IsFIFOAvailable(r, vIndex)) Then
      i = i + 1
      aFunctions(i) = "FlushRxFIFO"
      i = i + 1
      aFunctions(i) = "GetRxFIFOFillingLevel"
      i = i + 1
      aFunctions(i) = "FlushTxFIFO"
      i = i + 1
      aFunctions(i) = "GetTxFIFOFillingLevel"
    End If


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

  End If

  OnChangingPageFunctions = True
End Function


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

  OnShowPageFunctions = False
    
  Dim r As ProjectData
  Dim c As Collection
  Dim e As Collection
  Dim bDisabled As Boolean
  Dim func As FunctionClass
  Dim sName As String
  Dim sRegPre As String
  Dim sVarPre As String
  Dim vIndex As Variant
  Dim d As String
  Dim bDisabledClockOrPinsOrAutoBaud As Boolean
  Dim bDisabledClockOrPins As Boolean
  Dim sDisabledClockOrPinsOrAutoBaudTooltip As String
  Dim sDisabledClockOrPinsTooltip As String

  vIndex = ps.Parameters.v("x")
  sRegPre = "ASC" & Format$(vIndex) & "_"
  sVarPre = "ASC" & Format$(vIndex)


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

  Set func = New FunctionClass

  If (Pagename = "Functions") Then

    '-------------------------------------------------------------------------
    ' page: Functions (action)
    '-------------------------------------------------------------------------
    RefreshFunctionDescriptions(vIndex, func, r)

    If (Not UpdateFunction(sVarPre, ps, func , Controlname, v)) Then Exit Function

    '-------------------------------------------------------------------------
    ' page: Functions (show)
    '-------------------------------------------------------------------------
    ' save the disabled condition for the module clock and the pins
    bDisabledClockOrPins = IsModuleClockDisabled(r, vIndex) Or IsPinInterfaceDeselected(r, vIndex)      ' save the tooltip for the module clock and the pins
    ' save the disabled condition for the module clock, the pins and the autobaud mode
    bDisabledClockOrPinsOrAutoBaud = bDisabledClockOrPins Or IsAutobaudSelected(r, vIndex)

    ' save the tooltip for the module clock and the pins
    sDisabledClockOrPinsTooltip = GetTooltipModuleClockDisabled(r, vIndex)
    sDisabledClockOrPinsTooltip = sDisabledClockOrPinsTooltip & GetTooltipPinInterfaceDeselected(r, vIndex)

    ' save the tooltip for the module clock, the pins and the autobaud mode
    sDisabledClockOrPinsOrAutoBaudTooltip = sDisabledClockOrPinsTooltip & GetTooltipAutobaudSelected(r, vIndex)

    Set func = New FunctionClass
    RefreshFunctionDescriptions(vIndex, func, r)

    sName = sVarPre & "_NAME_Init" 
    ' disable condition
    func.Disabled(sName) = bDisabledClockOrPins 
    ' tooltip if control is disabled
    d = GetDisabledFunctionToolTipEntry(func, sName)
    d = d & sDisabledClockOrPinsTooltip
    func.DisabledToolTip(sName) = d


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

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

    sName = sVarPre & "_NAME_Tx" 
    ' disable condition
    func.Disabled(sName) = True
    ' tooltip if control is disabled
    d = TOOLTIP_DISABLED_ISR32
    func.DisabledToolTip(sName) = d
    ' value for the control
    func.Value(sName) = IsISRSelected(r, sVarPre, sRegPre & "TIC", "Tx")

    sName = sVarPre & "_NAME_Rx" 
    ' disable condition
    func.Disabled(sName) = True
    ' tooltip if control is disabled
    d = TOOLTIP_DISABLED_ISR32
    func.DisabledToolTip(sName) = d
    ' value for the control
    func.Value(sName) = IsISRSelected(r, sVarPre, sRegPre & "RIC", "Rx")

    sName = sVarPre & "_NAME_Error" 
    ' disable condition
    func.Disabled(sName) = True
    ' tooltip if control is disabled
    d = TOOLTIP_DISABLED_ISR32
    func.DisabledToolTip(sName) = d
    ' value for the control
    func.Value(sName) = IsISRSelected(r, sVarPre, sRegPre & "EIC", "Error")

    sName = sVarPre & "_NAME_TxBuffer" 
    ' disable condition
    func.Disabled(sName) = True
    ' tooltip if control is disabled
    d = TOOLTIP_DISABLED_ISR32
    func.DisabledToolTip(sName) = d
    ' value for the control
    func.Value(sName) = IsISRSelected(r, sVarPre, sRegPre & "TBIC", "TxBuffer")

    sName = sVarPre & "_NAME_TxDataReady" 
    ' disable condition
    func.Disabled(sName) = r.v(sRegPre & "USE_Init") = 0 Or r.v(sVarPre & "_USE_Tx") = 1
    ' tooltip if control is disabled
    d = GetDisabledFunctionToolTipEntry(func, sName)
    If (r.v(sVarPre & "_USE_Tx") = 1) Then
      d = d & FormatDisabledToolTip("the transmit interrupt is enabled")
    End If
    If (r.v(sVarPre & "_USE_Init") = 0) Then 
      d = d & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
    End If
    func.DisabledToolTip(sName) = d

    sName = sVarPre & "_NAME_TxBufFree" 
    ' disable condition
    func.Disabled(sName) = r.v(sRegPre & "USE_Init") = 0 Or r.v(sVarPre & "_USE_TxBuffer") = 1
    ' tooltip if control is disabled
    d = GetDisabledFunctionToolTipEntry(func, sName)
    If (r.v(sVarPre & "_USE_TxBuffer") = 1) Then
      d = d & FormatDisabledToolTip("the transmit buffer interrupt is enabled")
    End If
    If (r.v(sVarPre & "_USE_Init") = 0) Then 
      d = d & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
    End If
    func.DisabledToolTip(sName) = d

    sName = sVarPre & "_NAME_RxDataReady" 
    ' disable condition
    func.Disabled(sName) = r.v(sRegPre & "USE_Init") = 0 Or r.v(sVarPre & "_USE_Rx") = 1 
    ' tooltip if control is disabled
    d = GetDisabledFunctionToolTipEntry(func, sName)
    If (r.v(sVarPre & "_USE_Rx") = 1) Then
      d = d & FormatDisabledToolTip("the receive interrupt is enabled")
    End If
    If (r.v(sVarPre & "_USE_Init") = 0) Then 
      d = d & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
    End If
    func.DisabledToolTip(sName) = d

    sName = sVarPre & "_NAME_ErrorCheck" 
    ' disable condition
    func.Disabled(sName) = r.v(sRegPre & "USE_Init") = 0 Or r.v(sVarPre & "_USE_Error") = 1 OR IsErrorCheckDisabled(r, vIndex)
    ' tooltip if control is disabled
    d = GetDisabledFunctionToolTipEntry(func, sName)
    If (r.v(sVarPre & "_USE_Error") = 1) Then
      d = d & FormatDisabledToolTip("the error interrupt is enabled")
    End If
    If (IsErrorCheckDisabled(r, vIndex)) Then
	      d = d & FormatDisabledTooltip("no error check is enabled")
    End If
    If (r.v(sVarPre & "_USE_Init") = 0) Then 
      d = d & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
    End If
    func.DisabledToolTip(sName) = d

    If (IsAutobaudAvailable(r, vIndex)) Then
      sName = sVarPre & "_NAME_Autobaud" 
      ' disable condition
      func.Disabled(sName) = True
      ' tooltip if control is disabled
      d = TOOLTIP_DISABLED_ISR32
      func.DisabledToolTip(sName) = d
      ' value for the control
      func.Value(sName) = IsISRSelected(r, sVarPre, sRegPre & "ABIC", "Autobaud")

      sName = sVarPre & "_NAME_GetAutobaudStatus" 
      ' disable condition
      func.Disabled(sName) = Not IsAutobaudSelected(r, vIndex) OR _
                             r.v(sRegPre & "USE_Init") = 0 Or _
                             r.v(sRegPre & "ABCON_ABDETEN") = 0 Or _
                             r.v(sRegPre & "ABIC_IE") = 1
      ' tooltip if control is disabled
      d = GetDisabledFunctionToolTipEntry(func, sName)
      If (Not IsAutobaudSelected(r, vIndex)) Then 
        d = d & FormatDisabledToolTip("the autobaud detection is disabled")
      End If
      If (r.v(sVarPre & "_USE_Init") = 0) Then 
        d = d & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
      End If
      If (r.v(sRegPre & "ABCON_ABDETEN") = 0) Then
        d = d & FormatDisabledToolTip("interrupt generation after successful autobaud detection is disabled")
      End If
      If (r.v(sRegPre & "ABIC_IE") = 1) Then 
        d = d & FormatDisabledToolTip("autobaud interrupt is enabled")
      End If
      func.DisabledToolTip(sName) = d
    End If

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

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

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

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

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

    sName = sVarPre & "_NAME_SendSlaveAdr" 
    ' disable condition
    func.Disabled(sName) = r.v(sRegPre & "USE_Init") = 0 Or r.v(sRegPre & "CON_M") <> 4
    ' tooltip if control is disabled
    d = GetDisabledFunctionToolTipEntry(func, sName)
    If (r.v(sRegPre & "CON_M") <> 4) Then 
      d = d & FormatDisabledToolTip("the 9-bit data asynchronous mode is not selected")
    End If
    If (r.v(sVarPre & "_USE_Init") = 0) Then 
      d = d & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
    End If
    func.DisabledToolTip(sName) = d

    sName = sVarPre & "_NAME_OwnAddress" 
    ' disable condition
    func.Disabled(sName) = r.v(sRegPre & "USE_Init") = 0 Or r.v(sRegPre & "CON_M") <> 5
    ' tooltip if control is disabled
    d = GetDisabledFunctionToolTipEntry(func, sName)
    If (r.v(sRegPre & "CON_M") <> 5) Then 
      d = d & FormatDisabledToolTip("the 8-bit data + wake-up asynchronous mode is not selected")
    End If
    If (r.v(sVarPre & "_USE_Init") = 0) Then 
      d = d & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
    End If
    func.DisabledToolTip(sName) = d

    sName = sVarPre & "_NAME_WakeUp" 
    ' disable condition
    func.Disabled(sName) = r.v(sRegPre & "USE_Init") = 0 Or r.v(sRegPre & "CON_M") <> 5
    ' tooltip if control is disabled
    d = GetDisabledFunctionToolTipEntry(func, sName)
    If (r.v(sRegPre & "CON_M") <> 5) Then 
      d = d & FormatDisabledToolTip("the 8-bit data + wake-up asynchronous mode is not selected")
    End If
    If (r.v(sVarPre & "_USE_Init") = 0) Then 
      d = d & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
    End If
    func.DisabledToolTip(sName) = d

    sName = sVarPre & "_NAME_GotoSleep" 
    ' disable condition
    func.Disabled(sName) = r.v(sRegPre & "USE_Init") = 0 Or r.v(sRegPre & "CON_M") <> 5
    ' tooltip if control is disabled
    d = GetDisabledFunctionToolTipEntry(func, sName)
    If (r.v(sRegPre & "CON_M") <> 5) Then 
      d = d & FormatDisabledToolTip("the 8-bit data + wake-up asynchronous mode is not selected")
    End If
    If (r.v(sVarPre & "_USE_Init") = 0) Then 
      d = d & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
    End If
    func.DisabledToolTip(sName) = d

    If (IsFIFOAvailable(r, vIndex)) Then
      sName = sVarPre & "_NAME_FlushRxFIFO" 
      ' disable condition
      func.Disabled(sName) = r.v(sRegPre & "USE_Init") = 0 Or r.v(sRegPre & "RXFCON_RXFEN") = 0
      ' tooltip if control is disabled
      d = GetDisabledFunctionToolTipEntry(func, sName)
      If (r.v(sRegPre & "RXFCON_RXFEN") = 0) Then 
        d = d & FormatDisabledToolTip("the receive FIFO is not enabled")
      End If
      If (r.v(sVarPre & "_USE_Init") = 0) Then 
        d = d & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
      End If
      func.DisabledToolTip(sName) = d

      sName = sVarPre & "_NAME_GetRxFIFOFillingLevel" 
      ' disable condition
      func.Disabled(sName) = r.v(sRegPre & "USE_Init") = 0 Or r.v(sRegPre & "RXFCON_RXFEN") = 0
      ' tooltip if control is disabled
      d = GetDisabledFunctionToolTipEntry(func, sName)
      If (r.v(sRegPre & "RXFCON_RXFEN") = 0) Then 
        d = d & FormatDisabledToolTip("the receive FIFO is not enabled")
      End If
      If (r.v(sVarPre & "_USE_Init") = 0) Then 
        d = d & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
      End If
      func.DisabledToolTip(sName) = d

      sName = sVarPre & "_NAME_FlushTxFIFO" 
      ' disable condition
      func.Disabled(sName) = r.v(sRegPre & "USE_Init") = 0 Or r.v(sRegPre & "TXFCON_TXFEN") = 0
      ' tooltip if control is disabled
      d = GetDisabledFunctionToolTipEntry(func, sName)
      If (r.v(sRegPre & "TXFCON_TXFEN") = 0) Then 
        d = d & FormatDisabledToolTip("the transmit FIFO is not enabled")
      End If
      If (r.v(sVarPre & "_USE_Init") = 0) Then 
        d = d & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
      End If
      func.DisabledToolTip(sName) = d

      sName = sVarPre & "_NAME_GetTxFIFOFillingLevel" 
      ' disable condition
      func.Disabled(sName) = r.v(sRegPre & "USE_Init") = 0 Or r.v(sRegPre & "TXFCON_TXFEN") = 0
      ' tooltip if control is disabled
      d = GetDisabledFunctionToolTipEntry(func, sName)
      If (r.v(sRegPre & "TXFCON_TXFEN") = 0) Then 
        d = d & FormatDisabledToolTip("the transmit FIFO is not enabled")
      End If
      If (r.v(sVarPre & "_USE_Init") = 0) Then 
        d = d & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
      End If
      func.DisabledToolTip(sName) = d
    End If


    If (Not ShowFunction(sVarPre, ps, func , v)) Then Exit Function

  End If         ' if Pagename


  OnShowPageFunctions = True
  Exit Function

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


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

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

  OnLoadPageParameters = True
End Function


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

  OnChangingPageParameters = False
  Dim r As ProjectData 
  Dim vIndex As Variant
  Dim sVarPre As String
  Dim i As Integer
  Dim aParameters(1 To 16) As String

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


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

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

      '-------------------------------                                                                           
      ' frame: fraParameters1                                                                                    
      '-------------------------------                                                                           
       ' initialize the array                                                                                    
        For i = Lbound(aParameters) To Ubound(aParameters)                                                      
          aParameters(i) = ""                                                                                    
        Next i                                                                                                   
                                                                                                                 
        If (IsAutobaudAvailable(r, vIndex)) Then
          i = Lbound(aParameters)                                                                                  
          aParameters(i) = "AUTOBAUD_WAITING"                                                                      
          i = i + 1                                                                                                
          aParameters(i) = "FIRST_CHARACTER_SMALL"                                                                 
          i = i + 1                                                                                                
          aParameters(i) = "FIRST_CHARACTER_CAPITAL"                                                                 
          i = i + 1                                                                                                
          aParameters(i) = "SECOND_CHARACTER_SMALL"                                                                 
          i = i + 1                                                                                                
          aParameters(i) = "SECOND_CHARACTER_CAPITAL"                                                                 
                                                                                                                   
          If (Not ps.AddFrame("fraParameters1", 100 , 900, 4150, 4400, CAPTION_FRA_PARAMETERS1)) Then Exit Function
            For i = Lbound(aParameters) To Ubound(aParameters)                                                     
              If Not(aParameters(i) = "") Then                                                                     
                If (Not ps.AddText("txt_" & aParameters(i), 200, 300 * i, 3800, 325)) Then Exit Function           
              End If                                                                                               
            Next i                                                                                                 
        End If
  End If

  OnChangingPageParameters = True
End Function


'*****************************************************************************
'Description:
'        This function is called from the OnShow function of the associated
'        module. See the description for the OnShow function of the
'        associated module for details.
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Controlname     control name
'        Pagename        current page name
'        v()             value array
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnShowPageParameters(ps As Peripherals, Controlname As String, Pagename As String, v() As Variant) As Boolean
  On Error Goto OnShowPageParametersError
  OnShowPageParameters = False
    
  Dim r As ProjectData
  Dim c As Collection
  Dim e As Collection
  Dim para As ParameterClass
  Dim vIndex As Variant
  Dim sVarPre As String
  Dim sRegPre As String
  Dim sName As String
  Dim d As String
  Dim i As Integer

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

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


  If (Pagename = "Parameters") Then

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

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


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

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

    If (IsAutobaudAvailable(r, vIndex)) Then
      sName = sVarPre & "_PARA_AUTOBAUD_WAITING" 
      ' disable condition
      para.Disabled(sName) = r.v(sVarPre & "_USE_GetAutobaudStatus") = 0
      ' tooltip if control is disabled
      d = FormatDisabledTooltip("the macro " & r.v(sVarPre & "_NAME_GetAutobaudStatus") & " is not selected")
      para.DisabledToolTip(sName) = d

      sName = sVarPre & "_PARA_FIRST_CHARACTER_SMALL" 
      ' disable condition
      para.Disabled(sName) = r.v(sVarPre & "_USE_GetAutobaudStatus") = 0
      ' tooltip if control is disabled
      d = FormatDisabledTooltip("the macro " & r.v(sVarPre & "_NAME_GetAutobaudStatus") & " is not selected")
      para.DisabledToolTip(sName) = d

      sName = sVarPre & "_PARA_FIRST_CHARACTER_CAPITAL" 
      ' disable condition
      para.Disabled(sName) = r.v(sVarPre & "_USE_GetAutobaudStatus") = 0
      ' tooltip if control is disabled
      d = FormatDisabledTooltip("the macro " & r.v(sVarPre & "_NAME_GetAutobaudStatus") & " is not selected")
      para.DisabledToolTip(sName) = d

      sName = sVarPre & "_PARA_SECOND_CHARACTER_SMALL" 
      ' disable condition
      para.Disabled(sName) = r.v(sVarPre & "_USE_GetAutobaudStatus") = 0
      ' tooltip if control is disabled
      d = FormatDisabledTooltip("the macro " & r.v(sVarPre & "_NAME_GetAutobaudStatus") & " is not selected")
      para.DisabledToolTip(sName) = d

      sName = sVarPre & "_PARA_SECOND_CHARACTER_CAPITAL" 
      ' disable condition
      para.Disabled(sName) = r.v(sVarPre & "_USE_GetAutobaudStatus") = 0
      ' tooltip if control is disabled
      d = FormatDisabledTooltip("the macro " & r.v(sVarPre & "_NAME_GetAutobaudStatus") & " is not selected")
      para.DisabledToolTip(sName) = d
    End If

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

  End If         ' if Pagename

  OnShowPageParameters = True
  Exit Function

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


'*****************************************************************************
'Description:
'        This function returns a formated disabled tooltip if not enough
'        port pins are selected .
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        vIndex          parameter
'-----------------------------------------------------------------------------
'Returns:
'        Formated tooltip
'*****************************************************************************
Function GetTooltipPinInterfaceDeselected(r As ProjectData, vIndex As Variant) As String
  On Error Resume Next
  Dim sVarPre As String
  Dim v As String
  Dim sRegPre As String
  Dim bSecondPinDesel As Boolean
  Dim s As String
  Dim i As Integer

  sVarPre = "ASC" & vIndex
  sRegPre = sVarPre & "_"
  
  GetTooltipPinInterfaceDeselected = ""            
  v = ""
  
  If (GetPinFunction(r, sVarPre & "_TxD_1") <> 2) Then
    v = v & FormatDisabledToolTip("no pin as TxDA" & vIndex & " selected")
  End If
  If (GetPinFunction(r, sVarPre & "_RxD_1_O") <> 2 And _
      GetPinFunction(r, sVarPre & "_RxD_1_I") <> 1 _
      ) Then
    v = v & FormatDisabledToolTip("no pin as RxDA" & vIndex & " selected")
  End If

  GetTooltipPinInterfaceDeselected = v
End Function


'*****************************************************************************
'Description:
'        This function returns the disabled tooltip if the Autobaud mode is 
'        selected.
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the ProjectData object
'        vIndex          parameter
'-----------------------------------------------------------------------------
'Returns:
'        True if the Autobaud mode is selected, else False 
'*****************************************************************************
Function GetTooltipAutobaudSelected(r As ProjectData, vIndex As Variant)	As String
  On Error Resume Next

  Dim sRegPre As String 
  Dim sVarPre As String 

  sRegPre = "ASC" & vIndex & "_"
  sVarPre = "ASC" & vIndex

  GetTooltipAutobaudSelected = ""            
  If (IsAutobaudSelected(r, vIndex)) Then	
    GetTooltipAutobaudSelected =  FormatDisabledToolTip("the autobaud mode is selected")
  End If
End Function


