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

Option Explicit
'*****************************************************************************
' Module:
'        UART1
'-----------------------------------------------------------------------------
' Description:
'        This file contains functions which are create controls for the
'        module 'UART1'.
'        Furthermore it contains functions for the event handling of
'        these controls.
'
'-----------------------------------------------------------------------------
' History:
'
'        Rev. Author         Date        Description
'        ---------------------------------------------------------------------
'        0.1  Sunil          25-10-04    initial version
'        0.2  Sunil          18-11-04    code added to select BRG, when transmitter or
'                                        receiver option is selected.
'        0.3  Sunil          29-12-04    default baudrate is initialized to maximum value.
'                                        (default value of BG is 0x00).
'                                        module prefix added.
'
'*****************************************************************************

'*****************************************************************************
'Description:
'        This function is called from DAvE just before the Peripherals
'        window is shown.
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'-----------------------------------------------------------------------------
'Returns:
'        True            on successful operation
'        False           else
'*****************************************************************************
Private SharedInt As Integer

Function OnLoad(ps As Peripherals) As Boolean
    On Error GoTo OnLoadError

    OnLoad = False

    '***************** Added by jag on 7/4/6 ***************
      If (Not OnLoadPageModuleClock(ps)) Then Exit Function
    '***************** Added by jag on 7/4/6 ***************
    If (Not OnLoadPageUART1(ps)) Then Exit Function
    If (Not OnLoadPageBRG(ps)) Then Exit Function
    If (Not OnLoadPageInterrupts(ps)) Then Exit Function
    If (Not OnLoadPageFunctions(ps)) Then Exit Function
    If (Not OnLoadPageParameters(ps)) Then Exit Function
    If (Not OnLoadPageNotes(ps)) Then Exit Function
    
    ' call function to initialize the menu
    If (Not InitMenu(ps, "UART1\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 successful operation
'        False           else
'*****************************************************************************
Function OnChangingPage(ps As Peripherals, Page As Integer, Pagename As String) As Boolean
    On Error GoTo OnChangingPageError

    OnChangingPage = False
    '*********************** Added by jag on 7/4/6 **********************
     If (Not OnChangingPageModuleClock(ps, Pagename)) Then Exit Function
    '*********************** Added by jag on 7/4/6 **********************
    
    If (Not OnChangingPageUART1(ps, Pagename)) Then Exit Function
    If (Not OnChangingPageBRG(ps, Pagename)) Then Exit Function
    If (Not OnChangingPageInterrupts(ps, Pagename)) Then Exit Function
    If (Not OnChangingPageFunctions(ps, Pagename)) Then Exit Function
    If (Not OnChangingPageParameters(ps, Pagename)) Then Exit Function
    If (Not OnChangingPageNotes(ps, Pagename, "UART1")) 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 successful operation
'        False           else
'*****************************************************************************
Function OnShow(ps As Peripherals, Controlname As String, v() As Variant, Page As Integer, Pagename As String) As Boolean
    On Error Resume Next
     
    OnShow = False
   
    '****************************** Added by jag on 7/4/6 ******************************
       If (Not OnShowPageModuleClock(ps, Controlname, Pagename, v)) Then Exit Function
    '****************************** Added by jag on 7/4/6 ******************************
    If (Not OnShowPageUART1(ps, Controlname, Pagename, v)) Then Exit Function
    If (Not OnShowPageBRG(ps, Controlname, Pagename, v)) Then Exit Function
    If (Not OnShowPageInterrupts(ps, Controlname, Pagename, v)) Then Exit Function
    If (Not OnShowPageFunctions(ps, Controlname, Pagename, v)) Then Exit Function
    If (Not OnShowPageParameters(ps, Controlname, Pagename, v)) Then Exit Function
    If (Not OnShowPageNotes(ps, Controlname, Pagename, "UART1", v)) Then Exit Function

    OnShow = True
End Function

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

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

'*****************************************************************************
'Description:
'        This function is called from DAvE if the user clicks on a menu entry.
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Toolname        name of the entry
'        ToolId          id of the entry
'        Tooltext        additional text of the entry
'-----------------------------------------------------------------------------
'Returns:
'        True            on successful 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, "UART1\Dialog")) Then Exit Function

    OnMenuClick = True
    Exit Function

OnMenuClickError:
    Exit Function
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
      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, " UART1 Disabled Flag (PMCON2) ")) Then Exit Function
            If (Not ps.AddOption("optUART1_DIS_0", 200, 350, 4700, 300, "Enable module; the peripheral is supplied with the clock signal")) Then Exit Function
            If (Not ps.AddOption("optUART1_DIS_1", 200, 825, 4400, 300, "Disable module; the clock input of peripheral is disabled")) Then Exit Function
        '-------------------------------
        ' frame: frmInputClock
        '-------------------------------
        If (Not ps.AddFrame("frmInputClock", 100, 1600, 5400, 1000, "Input Clock")) Then Exit Function
            If (Not ps.AddLabel("lbl_txt_InputClock", 0, 200, 450, 3225, 300, "Input clock of the module [MHz]")) Then Exit Function
            If (Not ps.AddLabel("lbl_box_InputClock", 1, 3550, 400, 1000, 300, "")) Then Exit Function
      End If
'  End If
  OnChangingPageModuleClock = True
End Function
'*****************************************************************************
'Description:
'        This function is called from the OnShow function of the associated
'        module. See the description for the OnShow function of the
'        associated module for details.
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        Controlname     control name
'        Pagename        current page name
'        v()             value array
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnShowPageModuleClock(ps As Object, Controlname As String, Pagename As String, v() As Variant) As Boolean
  On Error GoTo OnShowPageModuleClockError
  OnShowPageModuleClock = False
  Dim r           As ProjectData
  Dim c           As Object
  Dim bDisabled   As Boolean
  Dim e As Object
  Dim vIndex As Variant
  Set r = ps.ProjectData
  Set c = ps.ControlCollection
  Set e = ps.ExtenderCollection
If (Pagename = "Module Clock") Then
      Select Case (Controlname)
         Case "optUART1_DIS_0"
            r.v(SCU_PREFIX & "PMCON2_UART1_DIS") = 0
         Case "optUART1_DIS_1"
            r.v(SCU_PREFIX & "PMCON2_UART1_DIS") = 1
            Call ResetUART1(r)
      End Select
        With c("optUART1_DIS_0")
            bDisabled = False
            .Enabled = Not (bDisabled)
            .Value = -CInt(r.v(SCU_PREFIX & "PMCON2_UART1_DIS") = 0)
        End With
       With c("optUART1_DIS_1")
            bDisabled = False
            .Enabled = Not (bDisabled)
            .Value = -CInt(r.v(SCU_PREFIX & "PMCON2_UART1_DIS") = 1)
        End With
       With c("lbl_txt_InputClock")
            bDisabled = ((r.v(SCU_PREFIX & "PMCON2_UART1_DIS") = 1))
            .Enabled = Not bDisabled
       End With
        With c("lbl_box_InputClock")
            bDisabled = ((r.v(SCU_PREFIX & "PMCON2_UART1_DIS") = 1))
            .Enabled = Not bDisabled
            If (bDisabled) Then
                 .Caption = CALCULATION_NOT_POSSIBLE
                 Else
                .Caption = Format(r.v("MAIN_PCLK"), "00.000")
            End If
        End With
        With e("lbl_box_InputClock")
          If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            '.DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleClockDisabled(r, vIndex)
          End If
        End With
End If
  OnShowPageModuleClock = True
  Exit Function
OnShowPageModuleClockError:
  errorbox "Can not show page", Err.Description
  Exit Function
End Function
'************************************ Added by jag on 7/4/6 ************************************
'-----------------------------------------------------------------------------
' local functions
'-----------------------------------------------------------------------------
'*****************************************************************************
'Description:
'        This function is called from the OnLoad function of the associated
'        module in order to add the page 'ModuleClock'.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Public Function OnLoadPageModuleClock(ps As Object) As Boolean
  On Error Resume Next
  OnLoadPageModuleClock = False
      If (Not ps.AddPage("Module Clock")) Then Exit Function
  OnLoadPageModuleClock = True
End Function
'************************************ Added by jag on 7/4/6 ************************************
    
'-----------------------------------------------------------------------------
' local functions
'-----------------------------------------------------------------------------

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

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

  OnLoadPageUART1 = True
End Function

Public Function OnChangingPageUART1(ps As Peripherals, Pagename As String) As Boolean
  On Error Resume Next
  Dim c As Collection
  OnChangingPageUART1 = False

  If (Not ps.ExtenderCollection("UART1").Loaded) And (Pagename = "UART1") Then
    ps.ExtenderCollection("UART1").Loaded = True
    
    Set c = ps.ControlCollection
    '-------------------------------
    ' frame: fraTransmitter
    '-------------------------------
    If (Not ps.AddFrame("fraTransmitter", 80, 110, 2960, 1300, "Transmitter")) Then Exit Function
        If (Not ps.AddOption("OptNoPinSel", 200, 250, 1750, 380, "No pins are selected")) Then Exit Function
        If (Not ps.AddOption("OptSelP0.4", 200, 550, 1950, 380, "Use pin P0.4 (TXD1_0)")) Then Exit Function
        If (Not ps.AddOption("OptSelP3.1", 200, 850, 1950, 380, "Use pin P3.1 (TXD1_1)")) Then Exit Function

    '-------------------------------
    ' frame: fraReceiver
    '-------------------------------
    If (Not ps.AddFrame("fraReceiver", 3200, 110, 2400, 1300, "Receiver")) Then Exit Function
        If (Not ps.AddOption("optSelNone", 200, 250, 1750, 380, "No pins are selected")) Then Exit Function
        If (Not ps.AddOption("optSelP0.5", 200, 550, 2000, 380, "Use pin P0.5 (RXD1_0)")) Then Exit Function
        If (Not ps.AddOption("optSelP3.2", 200, 850, 2000, 380, "Use pin P3.2 (RXD1_1)")) Then Exit Function
        
    '-------------------------------
    ' frame: fraReceiverEnable
    '-------------------------------
    If (Not ps.AddFrame("fraReceiverEnable", 5760, 110, 2840, 1300, "Receiver Enable")) Then Exit Function
        If (Not ps.AddCheck("chkEnableReceiver", 200, 300, 1890, 380, "Enable receiver (REN_1)")) Then Exit Function
    
    '-------------------------------
    ' frame: fraMode
    '-------------------------------
    If (Not ps.AddFrame("fraMode", 80, 1500, 5500, 2400, "Mode Control (SM0_1, SM1_1)")) Then Exit Function
        If (Not ps.AddOption("OptMode0", 200, 300, 4200, 380, "Mode 0: 8-bit shift register, fixed baud rate (fPCLK/2)")) Then Exit Function
        If (Not ps.AddOption("OptMode1", 200, 699, 5000, 380, "Mode 1: 8-bit shift UART1, variable baud rate (see BRG)")) Then Exit Function
        If (Not ps.AddOption("OptMode2", 200, 1098, 4980, 380, "Mode 2: 9-bit shift UART1, fixed baud rate (fPCLK/64)")) Then Exit Function
        If (Not ps.AddOption("OptMode3", 200, 1498, 5000, 380, "Mode 3: 9-bit shift UART1, variable baud rate (see BRG)")) Then Exit Function
        
'    '-------------------------------
'    ' frame: fraBaudSelect
'    '-------------------------------
'    If (Not ps.AddFrame("fraBaudSelect", 5760, 1500, 2840, 1000, "Baudrate Source")) Then Exit Function
'        If (Not ps.AddOption("OptBRG", 200, 250, 650, 380, "BRG")) Then Exit Function
'        If (Not ps.AddOption("OptTimer1", 200, 580, 850, 380, "Timer 1")) Then Exit Function
'-------------------------------
' frame: fraBaudSelect
'-------------------------------
    If (Not ps.AddFrame("fraBaudSelect", 5760, 1500, 2840, 1000, "Baudrate Source")) Then Exit Function
        If (Not ps.AddOption("OptBRG", 200, 375, 650, 380, "BRG")) Then Exit Function
        
    
    

'    '-------------------------------
'    ' frame: fraInterrupts
'    '-------------------------------
'    If (Not ps.AddFrame("fraInterrupts", 5760, 2600, 2840, 1300, "Interrupts")) Then Exit Function
'        If (Not ps.AddCheck("chkEnableInt", 200, 250, 1850, 380, "Enable interrupt (EX2)")) Then Exit Function
'        If (Not ps.AddCheck("chkValidStopBit", 200, 600, 2490, 660, "Receive interrupt will only be activated if a valid stop bit was received (SM2_1)")) Then Exit Function
    '-------------------------------
    ' frame: fraInterrupts
    '-------------------------------
   If (Not ps.AddFrame("fraInterrupts", 5760, 2600, 2840, 2700, "Interrupts")) Then Exit Function
'        If (Not ps.AddCheck("chkEnableInt", 200, 250, 1850, 380, "Enable interrupt (EX2)")) Then Exit Function
'        If (Not ps.AddCheck("chkRIEN", 200, 600, 2490, 660, "Enable Recieve Interrupt (RIEN)")) Then Exit Function
'        If (Not ps.AddCheck("chkTIEN", 200, 1150, 2490, 660, "Enable Transmit Interrupt (TIEN)")) Then Exit Function
'        If (Not ps.AddCheck("chkValidStopBit", 200, 1800, 2490, 660, "Receive interrupt will only be activated if a valid stop bit was received (SM2_1)")) Then Exit Function
         'If (Not ps.AddCheck("chkRIEN", 200, 250, 2490, 660, "Enable Recieve Interrupt (RIEN)")) Then Exit Function
         'If (Not ps.AddCheck("chkTIEN", 200, 800, 2490, 660, "Enable Transmit Interrupt (TIEN)")) Then Exit Function
         'If (Not ps.AddCheck("chkValidStopBit", 200, 1450, 2490, 660, "Receive interrupt will only be activated if a valid stop bit was received (SM2_1)")) Then Exit Function
         If (Not ps.AddCheck("chkEnableInt", 200, 250, 2490, 660, "Enable Interrupt (EX2)")) Then Exit Function
         If (Not ps.AddCheck("chkValidStopBit", 200, 1000, 2490, 660, "Receive interrupt will only be activated if a valid stop bit was received (SM2_1)")) Then Exit Function

'    '-------------------------------
'    ' frame: fraOptions
'    '-------------------------------
'    If (Not ps.AddFrame("fraOptions", 80, 4000, 2550, 1300, "Options")) Then Exit Function
'        If (Not ps.AddCheck("chkDoubleBaudrate", 200, 260, 2200, 495, "Double baud rate (SMOD) (Note: Only in Mode 2)")) Then Exit Function

'    '-------------------------------
'    ' frame: fraOptions
'    '-------------------------------
'    If (Not ps.AddFrame("fraOptions", 80, 4000, 2550, 1300, "Options")) Then Exit Function
'        If (Not ps.AddCheck("chkDoubleBaudrate", 200, 260, 2200, 495, "Double baud rate (SMOD) (Note: Only in Mode 2)")) Then Exit Function


'    '-------------------------------
'    ' frame: fraIC
'    '-------------------------------
'    If (Not ps.AddFrame("fraOptions", 80, 4000, 2550, 1300, "Interrupt Control")) Then Exit Function
'        If (Not ps.AddCheck("chkRIEN", 200, 260, 2200, 380, "Enable Recieve Interrupt (RIEN)")) Then Exit Function
'        If (Not ps.AddCheck("chkTIEN", 200, 700, 2200, 380, "Enable Transmit Interrupt (TIEN)")) Then Exit Function
    '-------------------------------
    ' frame: fraMultiprocessor
    '-------------------------------
    If (Not ps.AddFrame("fraMultiprocessor", 80, 4000, 2550, 1300, "Multiprocessor")) Then Exit Function
        If (Not ps.AddCheck("chkMultiprocCom", 200, 330, 2100, 380, "Enable multiprocessor communication (SM2_1)")) Then Exit Function

    '-------------------------------
    ' frame: fraRXDO1
    '-------------------------------
    If (Not ps.AddFrame("fraRXDO", 2800, 4000, 2800, 1300, "RXDO1 Pin Selection")) Then Exit Function
        If (Not ps.AddOption("OptRXDONoPinSel", 200, 250, 1750, 380, "No pins are selected")) Then Exit Function
        If (Not ps.AddOption("OptRXDOSelP0.3", 200, 550, 2100, 380, "Use pin P0.3 (RXDO1_0)")) Then Exit Function
        If (Not ps.AddOption("OptRXDOSelP3.0", 200, 850, 2100, 380, "Use pin P3.0 (RXDO1_1)")) Then Exit Function

''-------------------------------
'' frame: fraRXDO
''-------------------------------
'    If (Not ps.AddFrame("fraRXDO", 80, 4000, 5500, 1300, "RXDO1 Pin Selection")) Then Exit Function
'        If (Not ps.AddOption("OptRXDONoPinSel", 200, 250, 1750, 380, "No pins are selected")) Then Exit Function
'        If (Not ps.AddOption("OptRXDOSelP0.3", 200, 550, 2100, 380, "Use pin P0.3 (RXDO1_0)")) Then Exit Function
'        If (Not ps.AddOption("OptRXDOSelP3.0", 200, 850, 2100, 380, "Use pin P3.0 (RXDO1_1)")) Then Exit Function
'




'    '-------------------------------
'    ' frame: fraMultiprocessor
'    '-------------------------------
'    If (Not ps.AddFrame("fraMultiprocessor", 5760, 4000, 2840, 1300, "Multiprocessor")) Then Exit Function
'        If (Not ps.AddCheck("chkMultiprocCom", 200, 330, 2100, 380, "Enable multiprocessor communication (SM2_1)")) Then Exit Function
'
'
'    '-------------------------------
'    ' frame: fraIC
'    '-------------------------------
'    If (Not ps.AddFrame("fraOptions", 5760, 4000, 2840, 1300, "Interrupt Control")) Then Exit Function
'        If (Not ps.AddCheck("chkRIEN", 200, 260, 2200, 380, "Enable Recieve Interrupt (RIEN)")) Then Exit Function
'        If (Not ps.AddCheck("chkTIEN", 200, 700, 2200, 380, "Enable Transmit Interrupt (TIEN)")) Then Exit Function

    
  End If
  OnChangingPageUART1 = 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 successful operation
'        False           else
'*****************************************************************************
Public Function OnShowPageUART1(ps As Peripherals, Controlname As String, Pagename As String, v() As Variant) As Boolean
  On Error GoTo OnShowError

  OnShowPageUART1 = False
  
  Dim vIndex As Variant
  Dim vToolIndex As Variant
  
  Dim r As ProjectData
  Dim c As Collection
  Dim e As Collection
  Dim bPinFree As Boolean
  Dim bDisabled As Boolean

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

  If (Pagename = "UART1") Then
    '-------------------------------------------------------------------------
    ' page: UART1 (action)
    '-------------------------------------------------------------------------
    
    Select Case Controlname
        '------------------------------------------------------------------------------------
        ' Frame Transmitter
        '------------------------------------------------------------------------------------
        Case "OptNoPinSel"
            If r.v("UART1_TxPin_P0.4_Used") = 1 Then
                Call ReleaseAlternateOutputPin(r, "TXD1_0")
                r.v("UART1_TxPin_P0.4_Used") = 0
            End If
            If r.v("UART1_TxPin_P3.1_Used") = 1 Then
                Call ReleaseAlternateOutputPin(r, "TXD1_1")
                r.v("UART1_TxPin_P3.1_Used") = 0
            End If
            Call CheckResetUart(r)
       
            If r.v("UART1_RXDO1_0_Pin_P0.3_Used") = 1 Then
                Call ReleaseAlternateOutputPin(r, "RXDO1_0")
                r.v("UART1_RXDO1_0_Pin_P0.3_Used") = 0
            End If
            If r.v("UART1_RXDO1_1_Pin_P3.0_Used") = 1 Then
                Call ReleaseAlternateOutputPin(r, "RXDO1_1")
                r.v("UART1_RXDO1_1_Pin_P3.0_Used") = 0
            End If
       
        Case "OptSelP0.4"
            r.v("UART1_TxPin_P0.4_Used") = 1
            If r.v("UART1_TxPin_P3.1_Used") = 1 Then
                r.v("UART1_TxPin_P3.1_Used") = 0
                Call ReleaseAlternateOutputPin(r, "TXD1_1")
            End If
            If (r.v(UART1_PREFIX & "BCON_R") = 0) And (GetUartMode(r) <> 0) And (GetUartMode(r) <> 2) Then r.v(UART1_PREFIX & "BCON_R") = 1
            Call RequestAlternateOutputPin(r, "TXD1_0", ALT_FUN3)
        
        Case "OptSelP3.1"
            r.v("UART1_TxPin_P3.1_Used") = 1
            If r.v("UART1_TxPin_P0.4_Used") = 1 Then
                r.v("UART1_TxPin_P0.4_Used") = 0
                Call ReleaseAlternateOutputPin(r, "TXD1_0")
            End If
            If (r.v(UART1_PREFIX & "BCON_R") = 0) And (GetUartMode(r) <> 0) And (GetUartMode(r) <> 2) Then r.v(UART1_PREFIX & "BCON_R") = 1
            Call RequestAlternateOutputPin(r, "TXD1_1", ALT_FUN3)

        '------------------------------------------------------------------------------------
        ' Frame "Receiver"
        '------------------------------------------------------------------------------------
        Case "chkEnableReceiver"
            r.l(UART1_PREFIX & "SCON_REN_1") = v(1)
            If (v(1) = 0) Then
                Call CheckResetUart(r)
            Else
                If (r.v(UART1_PREFIX & "BCON_R") = 0) And (GetUartMode(r) <> 0) And (GetUartMode(r) <> 2) Then r.v(UART1_PREFIX & "BCON_R") = 1
            End If

        Case "optSelNone"
            If r.v("UART1_RxPin_P0.5_Used") = 1 Then
                r.v("UART1_RxPin_P0.5_Used") = 0
                Call ReleaseAlternateInputPin(r, "RXD1_0")
            End If
            If r.v("UART1_RxPin_P3.2_Used") = 1 Then
                r.v("UART1_RxPin_P3.2_Used") = 0
                Call ReleaseAlternateInputPin(r, "RXD1_1")
            End If
            r.v(UART1_PREFIX & "SCON_REN_1") = 0
            r.v(UART1_PREFIX & "SCON_SM2_1") = 0
            r.v(SCU_PREFIX & "MODPISEL1_UR1RIS") = 0
            Call CheckResetUart(r)
        Case "optSelP0.5"
            r.v("UART1_RxPin_P0.5_Used") = 1
            r.v(SCU_PREFIX & "MODPISEL1_UR1RIS") = 0
            Call RequestAlternateInputPin(r, "RXD1_0")
            If r.v("UART1_RxPin_P3.2_Used") = 1 Then
                r.v("UART1_RxPin_P3.2_Used") = 0
                Call ReleaseAlternateInputPin(r, "RXD1_1")
            End If
            
        Case "optSelP3.2"
            r.v("UART1_RxPin_P3.2_Used") = 1
            r.v(SCU_PREFIX & "MODPISEL1_UR1RIS") = 1
            Call RequestAlternateInputPin(r, "RXD1_1")
            If r.v("UART1_RxPin_P0.5_Used") = 1 Then
                r.v("UART1_RxPin_P0.5_Used") = 0
                Call ReleaseAlternateInputPin(r, "RXD1_0")
            End If

        '------------------------------------------------------------------------------------
        ' Frame "Mode Control"
        '------------------------------------------------------------------------------------
        Case "OptMode0"
            Call SetUartMode(r, 0)
            r.v(UART1_PREFIX & "SCON_SM2_1") = 0   ' clear bit, because its meaning is mode dependent
            'r.l(BRG_PREFIX & "PCON_SMOD") = 0
            'r.v(BRG_PREFIX & "FDCON_BGS") = 0 Since these bits are not used in UART1
            r.l(UART1_PREFIX & "BCON_R") = 0
                        
        Case "OptMode1"
            Call SetUartMode(r, 1)
            Call ResetBRG(r)
            If (r.v(UART1_PREFIX & "BCON_R") = 0) And (GetUartMode(r) <> 2) Then r.v(UART1_PREFIX & "BCON_R") = 1
            r.v(UART1_PREFIX & "SCON_SM2_1") = 0   ' clear bit, because its meaning is mode dependent
            'r.l(BRG_PREFIX & "PCON_SMOD") = 0   Since these bits are not used in UART1
            r.v("BRG1_Interrupt_Select") = 0
            
            If r.v("UART1_RXDO1_1_Pin_P3.0_Used") = 1 Then
                r.v("UART1_RXDO1_1_Pin_P3.0_Used") = 0
                Call ReleaseAlternateOutputPin(r, "RXDO1_1")
            End If
            If r.v("UART1_RXDO1_0_Pin_P0.3_Used") = 1 Then
                r.v("UART1_RXDO1_0_Pin_P0.3_Used") = 0
                Call ReleaseAlternateOutputPin(r, "RXDO1_0")
            End If
            
        Case "OptMode2"
            Call SetUartMode(r, 2)
            r.l(UART1_PREFIX & "BCON_R") = 0
            r.l(UART1_PREFIX & "BCON_BRPRE") = &H0
            r.v(UART1_PREFIX & "SCON_SM2_1") = 0   ' clear bit, because its meaning is mode dependent
            'r.v(BRG_PREFIX & "FDCON_BGS") = 0     Since these bits are not used in UART1
                        
            If r.v("UART1_RXDO1_1_Pin_P3.0_Used") = 1 Then
                r.v("UART1_RXDO1_1_Pin_P3.0_Used") = 0
                Call ReleaseAlternateOutputPin(r, "RXDO1_1")
            End If
            If r.v("UART1_RXDO1_0_Pin_P0.3_Used") = 1 Then
                r.v("UART1_RXDO1_0_Pin_P0.3_Used") = 0
                Call ReleaseAlternateOutputPin(r, "RXDO1_0")
            End If

        Case "OptMode3"
            Call SetUartMode(r, 3)
            Call ResetBRG(r)
            If (r.v(UART1_PREFIX & "BCON_R") = 0) And (GetUartMode(r) <> 2) Then r.v(UART1_PREFIX & "BCON_R") = 1
            r.v(UART1_PREFIX & "SCON_SM2_1") = 0   ' clear bit, because its meaning is mode dependent
            'r.l(BRG_PREFIX & "PCON_SMOD") = 0 Since these bits are not used in UART1
            r.v("BRG1_Interrupt_Select") = 0
            
            If r.v("UART1_RXDO1_1_Pin_P3.0_Used") = 1 Then
                r.v("UART1_RXDO1_1_Pin_P3.0_Used") = 0
                Call ReleaseAlternateOutputPin(r, "RXDO1_1")
            End If
            If r.v("UART1_RXDO1_0_Pin_P0.3_Used") = 1 Then
                r.v("UART1_RXDO1_0_Pin_P0.3_Used") = 0
                Call ReleaseAlternateOutputPin(r, "RXDO1_0")
            End If


        '------------------------------------------------------------------------------------
        ' Frame "Baudrate Source"
        '------------------------------------------------------------------------------------
        Case "OptBRG"
            'r.v(BRG_PREFIX & "FDCON_BGS") = 0
            'Call ResetBRG(r)
            r.v(UART1_PREFIX & "BCON_R") = 1
        
'        Case "OptTimer1"
'            r.v(BRG_PREFIX & "FDCON_BGS") = 1
'            If r.v(UART1_PREFIX & "FDCON_FDM") <> 1 Then
'                Call ResetBRG(r)
'            End If
        
'        '------------------------------------------------------------------------------------
'        ' Frame "Options"
'        '------------------------------------------------------------------------------------
'        Case "chkDoubleBaudrate"
'            r.v(BRG_PREFIX & "PCON_SMOD") = v(1)
'

'         '------------------------------------------------------------------------------------
'         ' Frame "IC"
'         '------------------------------------------------------------------------------------
'        Case "chkRIEN"
'            'r.v(UART1_PREFIX & "SCON1_RIEN") = v(1)
'             If (v(1) = 1) Then
'               If (r.v("INTR_MSGEN") = 1) Then
'                   SharedInt = MsgBox(MSG_SELECT_XINTR8_INTERRUPTS, vbYesNo + vbQuestion, "DAvE")
'                   If (SharedInt = 6) Then
'                       r.v("INTR_MSGEN") = 1
'                   ElseIf (SharedInt = 7) Then
'                       r.v("INTR_MSGEN") = 0
'                       SharedInt = MsgBox(MSGBOX_SHAREDINT_ENABLE, vbInformation, "DAvE")
'                   End If
'               End If
'               r.v("UART1_Interrupt_Select") = v(1)
'               r.v("UART1_USE_Isr") = v(1)
'               r.v(UART1_PREFIX & "SCON1_RIEN") = v(1)
'             Else
'               r.v(UART1_PREFIX & "SCON1_RIEN") = v(1)
'               If (r.v(UART1_PREFIX & "SCON1_TIEN") = 0) Then
'                  r.v("UART1_Interrupt_Select") = v(1)
'                  r.v("UART1_USE_Isr") = v(1)
'               End If
'             End If
'        Case "chkTIEN"
'            'r.v(UART1_PREFIX & "SCON1_TIEN") = v(1)
'             If (v(1) = 1) Then
'               If (r.v("INTR_MSGEN") = 1) Then
'                   SharedInt = MsgBox(MSG_SELECT_XINTR8_INTERRUPTS, vbYesNo + vbQuestion, "DAvE")
'                   If (SharedInt = 6) Then
'                       r.v("INTR_MSGEN") = 1
'                   ElseIf (SharedInt = 7) Then
'                       r.v("INTR_MSGEN") = 0
'                       SharedInt = MsgBox(MSGBOX_SHAREDINT_ENABLE, vbInformation, "DAvE")
'                   End If
'               End If
'               r.v("UART1_Interrupt_Select") = v(1)
'               r.v("UART1_USE_Isr") = v(1)
'               r.v(UART1_PREFIX & "SCON1_TIEN") = v(1)
'             Else
'               r.v(UART1_PREFIX & "SCON1_TIEN") = v(1)
'               If (r.v(UART1_PREFIX & "SCON1_RIEN") = 0) Then
'                  r.v("UART1_Interrupt_Select") = v(1)
'                  r.v("UART1_USE_Isr") = v(1)
'               End If
'             End If
        '------------------------------------------------------------------------------------
        ' Frame "RXDO output pin selection"
        '------------------------------------------------------------------------------------
                '------------------------------------------------------------------------------------
        Case "OptRXDONoPinSel"
            If r.v("UART1_RXDO1_0_Pin_P0.3_Used") = 1 Then
                Call ReleaseAlternateOutputPin(r, "RXDO1_0")
                r.v("UART1_RXDO1_0_Pin_P0.3_Used") = 0
            End If
            If r.v("UART1_RXDO1_1_Pin_P3.0_Used") = 1 Then
                Call ReleaseAlternateOutputPin(r, "RXDO1_1")
                r.v("UART1_RXDO1_1_Pin_P3.0_Used") = 0
            End If
            Call CheckResetUart(r)
        
        Case "OptRXDOSelP0.3"
            r.v("UART1_RXDO1_0_Pin_P0.3_Used") = 1
            If r.v("UART1_RXDO1_1_Pin_P3.0_Used") = 1 Then
                r.v("UART1_RXDO1_1_Pin_P3.0_Used") = 0
                Call ReleaseAlternateOutputPin(r, "RXDO1_1")
            End If
            If (r.v(UART1_PREFIX & "BCON_R") = 0) And (GetUartMode(r) <> 0) And (GetUartMode(r) <> 2) Then r.v(UART1_PREFIX & "BCON_R") = 1
            Call RequestAlternateOutputPin(r, "RXDO1_0", ALT_FUN3)
        
        Case "OptRXDOSelP3.0"
            r.v("UART1_RXDO1_1_Pin_P3.0_Used") = 1
            If r.v("UART1_RXDO1_0_Pin_P0.3_Used") = 1 Then
                r.v("UART1_RXDO1_0_Pin_P0.3_Used") = 0
                Call ReleaseAlternateOutputPin(r, "RXDO1_0")
            End If
            If (r.v(UART1_PREFIX & "BCON_R") = 0) And (GetUartMode(r) <> 0) And (GetUartMode(r) <> 2) Then r.v(UART1_PREFIX & "BCON_R") = 1
            Call RequestAlternateOutputPin(r, "RXDO1_1", ALT_FUN3)
            

        '------------------------------------------------------------------------------------
        ' Frame "Multiprocessor"
        '------------------------------------------------------------------------------------
        Case "chkMultiprocCom"
            r.v(UART1_PREFIX & "SCON_SM2_1") = v(1)

        '------------------------------------------------------------------------------------
        ' Frame "Interrupts"
        '------------------------------------------------------------------------------------
        Case "chkEnableInt"
              
            If (v(1) = 1) Then
               If (r.v("INTR_MSGEN") = 1) Then
                    SharedInt = MsgBox(MSG_SELECT_XINTR8_INTERRUPTS, vbYesNo + vbQuestion, "DAvE")
                    If (SharedInt = 6) Then
                        r.v("INTR_MSGEN") = 1
                    ElseIf (SharedInt = 7) Then
                        r.v("INTR_MSGEN") = 0
                        SharedInt = MsgBox(MSGBOX_SHAREDINT_ENABLE, vbInformation, "DAvE")
                    End If
                End If
                r.v("UART1_Interrupt_Select") = v(1)
                r.v("UART1_USE_Isr") = v(1)
                'r.v(CORE_PREFIX & "IEN1_EX2") = v(1)
            Else
                r.v("UART1_Interrupt_Select") = v(1)
                r.v("UART1_USE_Isr") = v(1)
                'r.v(CORE_PREFIX & "IEN1_EX2") = v(1)
            End If
        Case "chkValidStopBit"
            r.v(UART1_PREFIX & "SCON_SM2_1") = v(1)



    End Select

    If (Controlname <> "") Then
        Call AdjustFunctions(ps) ' deselect function which are not applicable anymore
    End If

    '-------------------------------------------------------------------------
    ' page: UART (show)
    '-------------------------------------------------------------------------
    
    '------------------------------------------------------------------------------------
    ' Frame "Transmitter"
    '------------------------------------------------------------------------------------
    With c("OptNoPinSel")
         bDisabled = (r.v(SCU_PREFIX & "PMCON2_UART1_DIS"))
         .Enabled = Not (bDisabled)
         .Value = Not (r.v("UART1_TxPin_P3.1_Used") Or r.v("UART1_TxPin_P0.4_Used"))
    End With
    
    With e("OptNoPinSel")
         If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleClockDisabled(r, vIndex)
         End If
    End With
    With c("OptSelP0.4")
        bDisabled = Not IsAlternatePinFree(r, "TXD1_0") Or (r.v(SCU_PREFIX & "PMCON2_UART1_DIS") = 1)
        .Enabled = Not bDisabled
        .Value = -CInt(r.v("UART1_TxPin_P0.4_Used") = 1)
    End With

    With e("OptSelP0.4")
        If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (IsModuleClockDisabled(r, vToolIndex)) Then
               .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleClockDisabled(r, vToolIndex)
            Else
            .DisabledTooltipText = .DisabledTooltipText & GetDisabledAlternatePinTooltip(r, "TXD1_0")
            End If
        End If
    End With

    With c("OptSelP3.1")
        bDisabled = Not IsAlternatePinFree(r, "TXD1_1") Or (r.v(SCU_PREFIX & "PMCON2_UART1_DIS") = 1)
        .Enabled = Not bDisabled
        .Value = -CInt(r.v("UART1_TxPin_P3.1_Used") = 1)
    End With

    With e("OptSelP3.1")
        If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (IsModuleClockDisabled(r, vToolIndex)) Then
               .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleClockDisabled(r, vToolIndex)
            Else
               .DisabledTooltipText = .DisabledTooltipText & GetDisabledAlternatePinTooltip(r, "TXD1_1")
            End If
        End If
    End With


    '------------------------------------------------------------------------------------
    ' Frame "Receiver"
    '------------------------------------------------------------------------------------

    With c("chkEnableReceiver")
        bDisabled = (r.v("UART1_RxPin_P0.5_Used") = 0 And r.v("UART1_RxPin_P3.2_Used") = 0)
        .Enabled = Not bDisabled
        .Value = -CInt(r.v(UART1_PREFIX & "SCON_REN_1") = 1)
    End With
 

    With e("chkEnableReceiver")
        If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (IsModuleClockDisabled(r, vToolIndex)) Then
               .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleClockDisabled(r, vToolIndex)
            Else
               If (r.v("UART1_RxPin_P0.5_Used") = 0 And r.v("UART1_RxPin_P3.2_Used") = 0) Then
                  .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip("No pins are selected for reception")
               End If
            End If
        End If
    End With

    With c("optSelNone")
         bDisabled = (r.v(SCU_PREFIX & "PMCON2_UART1_DIS"))
         .Enabled = Not (bDisabled)
        .Value = (r.v("UART1_RxPin_P0.5_Used") = 0 And r.v("UART1_RxPin_P3.2_Used") = 0)
    End With
    
    With e("optSelNone")
         If (bDisabled) Then
            .DisabledToolTipText = TOOLTIP_DISABLED_IF
            .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleClockDisabled(r, vIndex)
         End If
    End With
    With c("optSelP0.5")
        bDisabled = Not IsAlternatePinFree(r, "RXD1_0") Or (r.v(SCU_PREFIX & "PMCON2_UART1_DIS") = 1)
        .Enabled = Not bDisabled
        .Value = -CInt(r.v("UART1_RxPin_P0.5_Used") = 1)
    End With

    With e("optSelP0.5")
        If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (IsModuleClockDisabled(r, vToolIndex)) Then
               .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleClockDisabled(r, vToolIndex)
            Else
            .DisabledTooltipText = .DisabledTooltipText & GetDisabledAlternatePinTooltip(r, "RXD1_0")
            End If
        End If
    End With

    With c("optSelP3.2")
        bDisabled = Not IsAlternatePinFree(r, "RXD1_1") Or (r.v(SCU_PREFIX & "PMCON2_UART1_DIS") = 1)
        .Enabled = Not bDisabled
        .Value = -CInt(r.v("UART1_RxPin_P3.2_Used") = 1)
    End With

    With e("optSelP3.2")
        If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (IsModuleClockDisabled(r, vToolIndex)) Then
               .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleClockDisabled(r, vToolIndex)
            Else
            .DisabledTooltipText = .DisabledTooltipText & GetDisabledAlternatePinTooltip(r, "RXD1_1")
            End If
        End If
    End With
    

    '------------------------------------------------------------------------------------
    ' Frame "Mode Control"
    '------------------------------------------------------------------------------------
    With c("OptMode0")
         bDisabled = CheckDisabledUart(r) Or (r.v(SCU_PREFIX & "PMCON2_UART1_DIS") = 1)
         .Enabled = Not bDisabled
        .Value = (GetUartMode(r) = 0)
    End With

    With e("OptMode0")
        If (bDisabled) Then
           .DisabledTooltipText = TOOLTIP_DISABLED_IF
           If (IsModuleClockDisabled(r, vToolIndex)) Then
              .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleClockDisabled(r, vToolIndex)
           Else
              .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip("the UART1 is not used as transmitter or receiver")
           End If
        End If
    End With
    
    '------------------------------------------------------------------------------------
    With c("OptMode1")
         bDisabled = CheckDisabledUart(r) Or (r.v(SCU_PREFIX & "PMCON2_UART1_DIS") = 1)
         .Enabled = Not bDisabled
        .Value = (GetUartMode(r) = 1)
    End With

    With e("OptMode1")
        If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (IsModuleClockDisabled(r, vToolIndex)) Then
              .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleClockDisabled(r, vToolIndex)
            Else
              .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip("the UART1 is not used as transmitter or receiver")
            End If
        End If
    End With

    '------------------------------------------------------------------------------------
    With c("OptMode2")
         bDisabled = CheckDisabledUart(r) Or (r.v(SCU_PREFIX & "PMCON2_UART1_DIS") = 1)
         .Enabled = Not bDisabled
         .Value = (GetUartMode(r) = 2)
    End With

    With e("OptMode2")
        If (bDisabled) Then
           .DisabledTooltipText = TOOLTIP_DISABLED_IF
           If (IsModuleClockDisabled(r, vToolIndex)) Then
              .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleClockDisabled(r, vToolIndex)
           Else
              .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip("the UART1 is not used as transmitter or receiver")
           End If
        End If
    End With

    '------------------------------------------------------------------------------------
    With c("OptMode3")
         bDisabled = CheckDisabledUart(r) Or (r.v(SCU_PREFIX & "PMCON2_UART1_DIS") = 1)
         .Enabled = Not bDisabled
        .Value = (GetUartMode(r) = 3)
    End With

    With e("OptMode3")
        If (bDisabled) Then
           .DisabledTooltipText = TOOLTIP_DISABLED_IF
           If (IsModuleClockDisabled(r, vToolIndex)) Then
              .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleClockDisabled(r, vToolIndex)
           Else
              .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip("the UART1 is not used as transmitter or receiver")
           End If
        End If
    End With
    
    '------------------------------------------------------------------------------------
    ' Frame "Baudrate Source"
    '------------------------------------------------------------------------------------
    With c("OptBRG")
        bDisabled = (GetUartMode(r) = 0) Or (GetUartMode(r) = 2) Or (r.v(SCU_PREFIX & "PMCON2_UART1_DIS") = 1)
        .Enabled = Not bDisabled
        '.Value = (r.v(BRG_PREFIX & "FDCON_BGS") = 0) since this bit is not used in UART1
        .Value = True
    End With
    
    With e("OptBRG")
        If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (IsModuleClockDisabled(r, vToolIndex)) Then
              .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleClockDisabled(r, vToolIndex)
            Else
              .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip("Mode 1 or 3 is not selected")
            End If
        End If
    End With
    
'    With c("OptTimer1")
'        bDisabled = (GetUartMode(r) = 0) Or (GetUartMode(r) = 2)
'        .Enabled = Not bDisabled
'        .Value = (r.v(BRG_PREFIX & "FDCON_BGS") = 1)
'    End With
'
'    With e("OptTimer1")
'        If (bDisabled) Then
'            .DisabledTooltipText = TOOLTIP_DISABLED_IF
'            .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip("Mode 1 or 3 is not selected")
'        End If
'    End With

    '------------------------------------------------------------------------------------
    ' Frame "Multiprocessor"
    '------------------------------------------------------------------------------------
    With c("chkMultiprocCom")
        bDisabled = (GetUartMode(r) < 2) Or (r.v(SCU_PREFIX & "PMCON2_UART1_DIS") = 1)
        .Enabled = Not bDisabled
        .Value = -CInt(IsMultiComMode(r))
    End With

    With e("chkMultiprocCom")
        If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (IsModuleClockDisabled(r, vToolIndex)) Then
              .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleClockDisabled(r, vToolIndex)
            Else
              .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("Mode 2 or 3 is not selected")
            End If
        End If
    End With

    '------------------------------------------------------------------------------------
    ' Frame "Interrupts"
    '------------------------------------------------------------------------------------
    With c("chkEnableInt")
        bDisabled = CheckDisabledUart(r) Or (r.v(SCU_PREFIX & "PMCON2_UART1_DIS") = 1)
        .Enabled = Not bDisabled
        '.Value = -CInt(r.v(CORE_PREFIX & "IEN1_EX2") = 1)
        .Value = -CInt(r.v("UART1_Interrupt_Select") = 1)
    End With

    With e("chkEnableInt")
        If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (IsModuleClockDisabled(r, vToolIndex)) Then
              .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleClockDisabled(r, vToolIndex)
            Else
              .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip("the UART1 is not used as transmitter or receiver")
            End If
        End If
    End With

    '------------------------------------------------------------------------------------
    With c("chkValidStopBit")
        bDisabled = (r.v(UART1_PREFIX & "SCON_REN_1") = 0) Or (GetUartMode(r) <> 1) Or (r.v(SCU_PREFIX & "PMCON2_UART1_DIS") = 1)
        .Enabled = Not bDisabled
        .Value = -CInt((r.v(UART1_PREFIX & "SCON_SM2_1") = 1) And (GetUartMode(r) = 1))
    End With

    With e("chkValidStopBit")
        If (bDisabled) Then
              .DisabledTooltipText = TOOLTIP_DISABLED_IF
           If (IsModuleClockDisabled(r, vToolIndex)) Then
              .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleClockDisabled(r, vToolIndex)
           Else
              If (GetUartMode(r) <> 1) Then
                 .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip("Mode 1 is not selected")
              End If
              If (r.v(UART1_PREFIX & "SCON_REN_1") = 0) Then
                 .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip("the receiver is not enabled")
              End If
           End If
        End If
    End With

'    '------------------------------------------------------------------------------------
'    ' Frame "Options"
'    '------------------------------------------------------------------------------------
'    With c("chkDoubleBaudrate")
'        bDisabled = CheckDisabledUart(r) Or ((GetUartMode(r) <> 2) And (r.v(BRG_PREFIX & "FDCON_BGS") = 0))
'        .Enabled = Not bDisabled
'        .Value = -CInt(r.v(BRG_PREFIX & "PCON_SMOD") = 1)
'    End With
'
'    With e("chkDoubleBaudrate")
'        If (bDisabled) Then
'            .DisabledTooltipText = TOOLTIP_DISABLED_IF
'            If (CheckDisabledUart(r)) Then
'                .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip("the UART is not used as transmitter or receiver")
'            End If
'            If GetUartMode(r) = 0 Then
'                .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip("Mode 2 is not selected")
'            End If
'
'            If (GetUartMode(r) = 1) Or (GetUartMode(r) = 3) Then
'                .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip("Timer1 is not selected as a baudrate generator")
'            End If
'        End If
'    End With

'    '------------------------------------------------------------------------------------
'    ' Frame "IC"
'    '------------------------------------------------------------------------------------
'     With c("chkRIEN")
'        bDisabled = CheckDisabledUart(r) Or (r.v(SCU_PREFIX & "PMCON2_UART1_DIS") = 1)
'        .Enabled = Not bDisabled And (r.v(UART1_PREFIX & "SCON_REN_1") = 1) And (r.v("UART1_USE_Isr") = 1)
'        .Value = -CInt(r.v(UART1_PREFIX & "SCON1_RIEN") = 1)
'     End With
'
'     With e("chkRIEN")
'        If (bDisabled) Then
'            .DisabledTooltipText = TOOLTIP_DISABLED_IF
'            If (IsModuleClockDisabled(r, vToolIndex)) Then
'              .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleClockDisabled(r, vToolIndex)
'            Else
'            .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip("the UART1 is not used as transmitter or receiver")
'            End If
'        ElseIf (r.v(UART1_PREFIX & "SCON_REN_1") = 0) Then
'                .DisabledTooltipText = TOOLTIP_DISABLED_IF
'                .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip("the receiver is not enabled")
'        ElseIf (r.v("UART1_USE_Isr") = 0) Then
'               .DisabledTooltipText = TOOLTIP_DISABLED_IF
'               .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip("the general interrupt EX2 is not enabled")
'        End If
'     End With
'
'     With c("chkTIEN")
'        bDisabled = CheckDisabledUart(r) Or (r.v(SCU_PREFIX & "PMCON2_UART1_DIS") = 1)
'        .Enabled = Not bDisabled And (r.v("UART1_USE_Isr") = 1) And (r.v("UART1_TxPin_P3.1_Used") Or r.v("UART1_TxPin_P0.4_Used"))
'        .Value = -CInt(r.v(UART1_PREFIX & "SCON1_TIEN") = 1)
'     End With
'
'     With e("chkTIEN")
'        If (bDisabled) Then
'            .DisabledTooltipText = TOOLTIP_DISABLED_IF
'            If (IsModuleClockDisabled(r, vToolIndex)) Then
'              .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleClockDisabled(r, vToolIndex)
'            Else
'            .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip("the UART1 is not used as transmitter or receiver")
'            End If
'        ElseIf (r.v("UART1_USE_Isr") = 0) Then
'               .DisabledTooltipText = TOOLTIP_DISABLED_IF
'               .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip("the general interrupt EX2 is not enabled")
'        ElseIf ((r.v("UART1_TxPin_P3.1_Used") = 0) Or (r.v("UART1_TxPin_P0.4_Used") = 0)) Then
'                .DisabledTooltipText = TOOLTIP_DISABLED_IF
'                .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip("the tranmitter pin is not selected")
'        End If
'     End With
'
'    '------------------------------------------------------------------------------------
'    ' Frame "IC"
'    '------------------------------------------------------------------------------------
'     With c("chkRIEN")
'        bDisabled = CheckDisabledUart(r) Or (r.v(SCU_PREFIX & "PMCON2_UART1_DIS") = 1)
'        .Enabled = Not bDisabled And (r.v(UART1_PREFIX & "SCON_REN_1") = 1)
'        .Value = -CInt(r.v(UART1_PREFIX & "SCON1_RIEN") = 1)
'     End With
'
'     With e("chkRIEN")
'        If (bDisabled) Then
'            .DisabledTooltipText = TOOLTIP_DISABLED_IF
'            If (IsModuleClockDisabled(r, vToolIndex)) Then
'              .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleClockDisabled(r, vToolIndex)
'            Else
'            .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip("the UART1 is not used as transmitter or receiver")
'            End If
'        ElseIf (r.v(UART1_PREFIX & "SCON_REN_1") = 0) Then
'                .DisabledTooltipText = TOOLTIP_DISABLED_IF
'                .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip("the receiver is not enabled")
'        End If
'     End With
'
'     With c("chkTIEN")
'        bDisabled = CheckDisabledUart(r) Or (r.v(SCU_PREFIX & "PMCON2_UART1_DIS") = 1)
'        .Enabled = Not bDisabled And (r.v("UART1_TxPin_P3.1_Used") Or r.v("UART1_TxPin_P0.4_Used"))
'        .Value = -CInt(r.v(UART1_PREFIX & "SCON1_TIEN") = 1)
'     End With
'
'     With e("chkTIEN")
'        If (bDisabled) Then
'            .DisabledTooltipText = TOOLTIP_DISABLED_IF
'            If (IsModuleClockDisabled(r, vToolIndex)) Then
'              .DisabledTooltipText = .DisabledTooltipText & GetTooltipModuleClockDisabled(r, vToolIndex)
'            Else
'            .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip("the UART1 is not used as transmitter or receiver")
'            End If
'        ElseIf ((r.v("UART1_TxPin_P3.1_Used") = 0) Or (r.v("UART1_TxPin_P0.4_Used") = 0)) Then
'                .DisabledTooltipText = TOOLTIP_DISABLED_IF
'                .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip("the tranmitter pin is not selected")
'        End If
'     End With


    '------------------------------------------------------------------------------------
    ' Frame "RXDO Pin Selection"
    '------------------------------------------------------------------------------------
    With c("OptRXDONoPinSel")
        bDisabled = CheckDisabledUart(r) Or (GetUartMode(r) <> 0) Or (r.v(SCU_PREFIX & "PMCON2_UART1_DIS") = 1)
        .Enabled = Not bDisabled
        .Value = Not (r.v("UART1_RXDO1_1_Pin_P3.0_Used") Or r.v("UART1_RXDO1_0_Pin_P0.3_Used"))
    End With
    
    With e("OptRXDONoPinSel")
        If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (IsModuleClockDisabled(r, vToolIndex)) Then
              .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleClockDisabled(r, vToolIndex)
            Else
            .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip("Mode 0 is not selected")
            End If
        End If
    End With
    
    With c("OptRXDOSelP0.3")
        bPinFree = IsAlternatePinFree(r, "RXDO1_0")
        bDisabled = CheckDisabledUart(r) Or (GetUartMode(r) <> 0 Or (Not bPinFree)) Or (r.v(SCU_PREFIX & "PMCON2_UART1_DIS") = 1)
        .Enabled = Not bDisabled
        .Value = r.v("UART1_RXDO1_0_Pin_P0.3_Used")
    End With
    
    With e("OptRXDOSelP0.3")
        If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (IsModuleClockDisabled(r, vToolIndex)) Then
              .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleClockDisabled(r, vToolIndex)
            Else
            If GetUartMode(r) <> 0 Then
                .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip("Mode 0 is not selected")
            ElseIf (Not bPinFree) Then
                .DisabledTooltipText = .DisabledTooltipText & GetDisabledAlternatePinTooltip(r, "RXDO1_0")
              End If
            End If
        End If
    End With
        
    With c("OptRXDOSelP3.0")
        bPinFree = IsAlternatePinFree(r, "RXDO1_1")
        bDisabled = CheckDisabledUart(r) Or (GetUartMode(r) <> 0 Or (Not bPinFree)) Or (r.v(SCU_PREFIX & "PMCON2_UART1_DIS") = 1)
        .Enabled = Not bDisabled
        .Value = r.v("UART1_RXDO1_1_Pin_P3.0_Used")
    End With
    
    With e("OptRXDOSelP3.0")
        If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (IsModuleClockDisabled(r, vToolIndex)) Then
              .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleClockDisabled(r, vToolIndex)
            Else
            If GetUartMode(r) <> 0 Then
                .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip("Mode 0 is not selected")
            ElseIf (Not bPinFree) Then
                .DisabledTooltipText = .DisabledTooltipText & GetDisabledAlternatePinTooltip(r, "RXDO1_1")
              End If
           End If
        End If
    End With
    
  End If         ' if Pagename

  OnShowPageUART1 = True
  Exit Function

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

'*****************************************************************************
'Description:
'        This subroutine is called when the TxD or RxD Pin is deselected.
'        The result might be that UART operation is no longer possible.
'        Then the variables and SFRs will be reset to DAvE's default state.
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the project data object
'-----------------------------------------------------------------------------
'Returns:
'*****************************************************************************
Sub CheckResetUart(r As ProjectData)
  On Error Resume Next

    If r.v("UART1_TxPin_P3.1_Used") = 0 And r.v("UART1_TxPin_P0.4_Used") = 0 And r.v(UART1_PREFIX & "SCON_REN_1") = 0 Then
        r.l(UART1_PREFIX & "SCON_SM2_1") = 0
        Call SetUartMode(r, DEFAULT_UART1_MODE)
        'r.l(BRG_PREFIX & "PCON_SMOD") = 0 Since not applicable for UART1
        'r.v(CORE_PREFIX & "IEN1_EX2") = 0
         r.v("UART1_Interrupt_Select") = 0
         r.v("BRG1_Interrupt_Select") = 0
        'r.l(BRG_PREFIX & "FDCON_BGS") = 0 Since not applicable for UART1
        r.v(UART1_PREFIX & "BCON_R") = 0
        r.v(UART1_PREFIX & "FDCON_FDM") = 0
        r.v(UART1_PREFIX & "FDCON_FDEN") = 0
        r.l(UART1_PREFIX & "BCON_BRPRE") = &H0
        r.v("UART1_USE_Isr") = 0
    End If
    
   ' Call ResetBRG(r)
    
End Sub

'*****************************************************************************
'Description:
'        This function checks whether UART has to be disabled or not based
'        on the transmitter and receiver settings.
'-----------------------------------------------------------------------------
'Parameters:
'        r               reference to the project data object
'-----------------------------------------------------------------------------
'Returns: True  - If the UART has to be disbaled
'         False - If not
'*****************************************************************************
Function CheckDisabledUart(r As ProjectData) As Boolean
  On Error Resume Next
    
    CheckDisabledUart = False
    
    If r.v("UART1_TxPin_P3.1_Used") = 0 And r.v("UART1_TxPin_P0.4_Used") = 0 And r.v(UART1_PREFIX & "SCON_REN_1") = 0 Then
        CheckDisabledUart = True
    End If
    
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 successful 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

Public Function OnChangingPageFunctions(ps As Peripherals, Pagename As String) As Boolean
  On Error Resume Next

  OnChangingPageFunctions = False

  Dim pos As Long

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

    If (Not ps.AddFrame("fraUART_USE_Init", 100, 100, 4150, 700, "Initialization Function")) Then Exit Function
    If (Not ps.AddCheck("chkUART_USE_Init", 200, 270, 1250, 380, "UART1_vInit")) Then Exit Function
    If (Not ps.AddText("txtUART_NAME_Init", 2150, 300, 1900, 315)) Then Exit Function

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

    ' Functions and Macros
    '------------------------------------------------------------------------------------------------
    If (Not ps.AddFrame("fraLibMisc", 100, 900, 4150, 4370, "Miscellaneous Functions")) Then Exit Function
    pos = 0
    'If (Not ps.AddCheck("chkUART_USE_Isr", 200, 270 + pos * 300, 2100, 380, "UART1_viIsr")) Then Exit Function
    If (Not ps.AddCheck("chkUART_USE_Isr", 200, 270 + pos * 300, 2100, 380, "SHINT_viXINTR8Isr")) Then Exit Function
    If (Not ps.AddText("txtUART_NAME_Isr", 2150, 300 + pos * 300, 1900, 315)) Then Exit Function
    pos = pos + 1

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

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

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

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

    '------------------------------------------------------------------------------------------------
    If (Not ps.AddFrame("fraLib8Bit", 4400, 900, 4150, 1075, "8-Bit Data Units")) Then Exit Function
    pos = 0

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

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

    '------------------------------------------------------------------------------------------------
    If (Not ps.AddFrame("fraLib9Bit", 4400, 2075, 4150, 1075, "9-Bit Data Units")) Then Exit Function
    pos = 0

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

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

    '------------------------------------------------------------------------------------------------
    If (Not ps.AddFrame("fraLibMulti", 4400, 3250, 4150, 2025, "Multiprocessor Communication")) Then Exit Function
    pos = 0
    If (Not ps.AddCheck("chkUART_USE_SendAddr", 200, 270 + pos * 300, 2100, 380, "UART1_vSendAddr")) Then Exit Function
    If (Not ps.AddText("txtUART_NAME_SendAddr", 2150, 300 + pos * 300, 1900, 315)) Then Exit Function
    pos = pos + 1

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

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

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

  End If

  OnChangingPageFunctions = True
End Function

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

  Set r = ps.ProjectData
  Set c = ps.ControlCollection
  Set e = ps.ExtenderCollection
  Set func = New FunctionClass
  
  If (Pagename = "Functions") Then
    '-------------------------------------------------------------------------
    ' page: Functions (action)
    '-------------------------------------------------------------------------
    Select Case Controlname
        Case "chkUART_USE_Init"
             r.v("UART1_USE_Init") = v(1)
    
        Case "txtUART_NAME_Init"
             If (IsInputFormatOK(v(1), FORMAT_FUNCTIONS, c("chkUART_USE_Init").Caption)) Then
                r.v("UART1_NAME_Init") = v(1)
             End If
    
        Case "txtUART_CFile"
             If (IsInputFormatOK(v(1), FORMAT_FILES, c("lblUART_CFile").Caption)) Then
                r.v("UART1_CFile") = v(1)
             End If
    End Select     ' case Controlname
    
    If (Not UpdateFunction(ps, Controlname, v, "Isr")) Then Exit Function
    If (Not UpdateFunction(ps, Controlname, v, "RxEnable")) Then Exit Function
    If (Not UpdateFunction(ps, Controlname, v, "RxDisable")) Then Exit Function
    If (Not UpdateFunction(ps, Controlname, v, "RxReady")) Then Exit Function
    If (Not UpdateFunction(ps, Controlname, v, "TxReady")) Then Exit Function
    If (Not UpdateFunction(ps, Controlname, v, "GetData8")) Then Exit Function
    If (Not UpdateFunction(ps, Controlname, v, "SendData8")) Then Exit Function
    If (Not UpdateFunction(ps, Controlname, v, "GetData9")) Then Exit Function
    If (Not UpdateFunction(ps, Controlname, v, "SendData9")) Then Exit Function
    If (Not UpdateFunction(ps, Controlname, v, "SendAddr")) Then Exit Function
    If (Not UpdateFunction(ps, Controlname, v, "OwnAddress")) Then Exit Function
    If (Not UpdateFunction(ps, Controlname, v, "WakeUp")) Then Exit Function
    If (Not UpdateFunction(ps, Controlname, v, "GotoSleep")) Then Exit Function
    
    '-------------------------------------------------------------------------
    ' page: Functions (show)
    '-------------------------------------------------------------------------
    Call RefreshFunctionDescriptions(func, r)

    '-------------------------------------------------------------------------
    ' control: chkUART_USE_Init (show)
    '-------------------------------------------------------------------------
    c("chkUART_USE_Init").Value = -CInt(r.v("UART1_USE_Init") = 1)
    e("chkUART_USE_Init").EnabledTooltipText = FormatFunctionToolTip(r, func, "UART1_NAME_Init")

    '-------------------------------------------------------------------------
    ' control: txtUART_NAME_Init (show)
    '-------------------------------------------------------------------------
    With c("txtUART_NAME_Init")
        bDisabled = r.v("UART1_USE_Init") = 0
        .Enabled = Not bDisabled
        .Text = FormatTextOutput(r.v("UART1_NAME_Init"), "S")
    End With

    With e("txtUART_NAME_Init")
        If (bDisabled) Then
           .DisabledToolTipText = FormatNormalToolTip(TOOLTIP_DISABLED_FUNC_NAME)
        End If
    End With
If (Not CheckFunction(ps, func, True, "Init")) Then Exit Function
    If (Not CheckFunction(ps, func, True, "Isr")) Then Exit Function
    If (Not CheckFunction(ps, func, True, "RxEnable")) Then Exit Function
    If (Not CheckFunction(ps, func, True, "RxDisable")) Then Exit Function
    If (Not CheckFunction(ps, func, True, "RxReady")) Then Exit Function
    If (Not CheckFunction(ps, func, True, "TxReady")) Then Exit Function
    If (Not CheckFunction(ps, func, True, "GetData8")) Then Exit Function
    If (Not CheckFunction(ps, func, True, "SendData8")) Then Exit Function
    If (Not CheckFunction(ps, func, True, "GetData9")) Then Exit Function
    If (Not CheckFunction(ps, func, True, "SendData9")) Then Exit Function
    If (Not CheckFunction(ps, func, True, "SendAddr")) Then Exit Function
    If (Not CheckFunction(ps, func, True, "OwnAddress")) Then Exit Function
    If (Not CheckFunction(ps, func, True, "WakeUp")) Then Exit Function
    If (Not CheckFunction(ps, func, True, "GotoSleep")) Then Exit Function
  
    '-------------------------------------------------------------------------
    ' control: lblUART_CFile (show)
    '-------------------------------------------------------------------------
    With c("lblUART_CFile")
        bDisabled = r.v("UART1_USE_Init") = 0
        .Enabled = Not bDisabled
    End With

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

    '-------------------------------------------------------------------------
    ' control: txtUART_CFile (show)
    '-------------------------------------------------------------------------
    With c("txtUART_CFile")
      bDisabled = (r.v("UART1_USE_Init") = 0)
      .Enabled = Not (bDisabled)
      .Text = FormatTextOutput(r.v("UART1_CFile"), "S")
    End With

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

  End If         ' if Pagename

  OnShowPageFunctions = True
  Exit Function

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

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

  Dim r As ProjectData
  Dim c As Collection

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

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

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

  UpdateFunction = True
ExitLabel:
End Function

'*****************************************************************************
'Description:           Any functions which do not suit the current settings
'                       will be deselected.
'-----------------------------------------------------------------------------
'Parameters:            none
'*****************************************************************************
Sub AdjustFunctions(ps As Peripherals)
  On Error Resume Next
  Dim func As FunctionClass

  Set func = New FunctionClass
  If (Not CheckFunction(ps, func, False, "Init")) Then Exit Sub
  If (Not CheckFunction(ps, func, False, "Isr")) Then Exit Sub
  If (Not CheckFunction(ps, func, False, "RxEnable")) Then Exit Sub
  If (Not CheckFunction(ps, func, False, "RxDisable")) Then Exit Sub
  If (Not CheckFunction(ps, func, False, "RxReady")) Then Exit Sub
  If (Not CheckFunction(ps, func, False, "TxReady")) Then Exit Sub
  If (Not CheckFunction(ps, func, False, "GetData8")) Then Exit Sub
  If (Not CheckFunction(ps, func, False, "SendData8")) Then Exit Sub
  If (Not CheckFunction(ps, func, False, "GetData9")) Then Exit Sub
  If (Not CheckFunction(ps, func, False, "SendData9")) Then Exit Sub
  If (Not CheckFunction(ps, func, False, "SendAddr")) Then Exit Sub
  If (Not CheckFunction(ps, func, False, "OwnAddress")) Then Exit Sub
  If (Not CheckFunction(ps, func, False, "WakeUp")) Then Exit Sub
  If (Not CheckFunction(ps, func, False, "GotoSleep")) Then Exit Sub
End Sub

'*****************************************************************************
'Description:
'-----------------------------------------------------------------------------
'Parameters:
'        ps              reference to the Peripherals object
'        func            reference to the function object
'        sName           function keyword
'        bShow           True  = update the function page
'                        False = adjust selections (deselect if not applicable)
'-----------------------------------------------------------------------------
'Returns:
'        True            on successful operation
'        False           else
'*****************************************************************************
Function CheckFunction(ps As Peripherals, func As FunctionClass, bShow As Boolean, sName As String) As Boolean
  On Error GoTo ExitLabel
  CheckFunction = False
    
  Dim r As ProjectData
  Dim c As Collection
  Dim e As Collection

  Dim vIndex As Variant
  Dim vToolIndex As Variant
  Dim bDisabled          As Boolean
  Dim bConditionInit     As Boolean
  Dim bConditionIsr      As Boolean
  Dim bConditionPins     As Boolean
  Dim bConditionRx       As Boolean
  Dim bConditionTx       As Boolean
  Dim bConditionMode13   As Boolean
  Dim bConditionBRGen    As Boolean
  Dim bConditionIntFlg   As Boolean
  Dim bCondition8Bit     As Boolean
  Dim bCondition9Bit     As Boolean
  Dim bConditionMulti    As Boolean
  Dim bNormalModeSel     As Boolean

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

  '-------------------------------------------------------------------------
  ' control: chkUART_USE_.. (show)
  '-------------------------------------------------------------------------
  bDisabled = False
  bConditionInit = False
  bConditionIsr = False
  bConditionPins = False
  bConditionRx = False
  bConditionTx = False
  bConditionMode13 = False
  bConditionIntFlg = False
  bCondition8Bit = False
  bCondition9Bit = False
  bConditionMulti = False

  ' Select the possible disabling reasons:
  Select Case sName
    Case "Init"
        bConditionPins = True
    
    Case "Isr"
        bConditionIsr = True

    Case "RxEnable", "RxDisable"
        bConditionInit = True
        bConditionRx = True

    Case "RxReady"
        bConditionInit = True
        bConditionRx = True
        bConditionIntFlg = True

    Case "TxReady"
        bConditionInit = True
        bConditionTx = True
        bConditionIntFlg = True
        
    Case "GetData8"
        bConditionInit = True
        bConditionRx = True
        bCondition8Bit = True

    Case "SendData8"
        bConditionInit = True
        bConditionTx = True
        bCondition8Bit = True

    Case "GetData9"
        bConditionInit = True
        bConditionRx = True
        bCondition9Bit = True

    Case "SendData9"
        bConditionInit = True
        bConditionTx = True
        bCondition9Bit = True

    Case "SendAddr"
        bConditionInit = True
        bConditionTx = True
        bConditionMulti = True

    Case "OwnAddress", "WakeUp", "GotoSleep"
        bConditionInit = True
        bConditionRx = True
        bConditionMulti = True
  End Select

  ' Check the selected disabling reasons:
  If (bConditionInit) Then bConditionInit = (r.v("UART1_USE_Init") = 0)
  If (bConditionPins) Then bConditionPins = (r.v("UART1_TxPin_P3.1_Used") = 0 And r.v("UART1_TxPin_P0.4_Used") = 0 And r.v(UART1_PREFIX & "SCON_REN_1") = 0)
  If (bConditionRx) Then bConditionRx = (r.v(UART1_PREFIX & "SCON_REN_1") = 0)
  If (bConditionTx) Then bConditionTx = (r.v("UART1_TxPin_P3.1_Used") = 0 And r.v("UART1_TxPin_P0.4_Used") = 0)
  If (bConditionMode13) Then bConditionMode13 = (GetUartMode(r) <> 1) And (GetUartMode(r) <> 3)
  If (bConditionIntFlg) Then bConditionIntFlg = (r.v("UART1_USE_Isr") = 1)
  If (bCondition8Bit) Then bCondition8Bit = DataSize9Bit(r)
  If (bCondition9Bit) Then bCondition9Bit = Not DataSize9Bit(r)
  If (bConditionMulti) Then bConditionMulti = Not IsMultiComMode(r)
  
  If r.v(UART1_PREFIX & "FDCON_FDM") = 1 Then bNormalModeSel = True
  
  ' reasons for deselection:
  bDisabled = bConditionPins Or bConditionRx Or bConditionTx Or bConditionMode13 Or bConditionIntFlg Or _
              bCondition8Bit Or bCondition9Bit Or bConditionMulti

  If sName = "Init" Then
    If bDisabled And bNormalModeSel Then bDisabled = False
  Else
      bConditionPins = (r.v("UART1_TxPin_P3.1_Used") = 0 And r.v("UART1_TxPin_P0.4_Used") = 0 And r.v(UART1_PREFIX & "SCON_REN_1") = 0)
      If bConditionInit And bNormalModeSel And bConditionPins Then
        bConditionInit = False
      End If
  End If
  

  If Not bShow Then

    '------------ Deselect Function if not applicable ----------------------
    If (bDisabled) Then
        r.v("UART1_USE_" & sName) = 0
    End If

  Else

    '------------ Update the displayed function page -----------------------

      With c("chkUART_USE_" & sName)

        ' reasons for disabling:
        bDisabled = bDisabled Or bConditionInit Or bConditionIsr Or (r.v(SCU_PREFIX & "PMCON2_UART1_DIS") = 1)
        .Enabled = Not bDisabled
        .Value = -CInt((r.v("UART1_USE_Init") = 1) And (r.v("UART1_USE_" & sName) = 1))

      End With


      With e("chkUART_USE_" & sName)
        If (bDisabled) Then
            ' tooltip if control is disabled
            If (IsModuleClockDisabled(r, vToolIndex)) Then
               .DisabledToolTipText = TOOLTIP_DISABLED_IF
               .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleClockDisabled(r, vToolIndex)
            Else
                If (bConditionIsr) Then
                        .DisabledToolTipText = TOOLTIP_DISABLED_ISR & vbCrLf & FormatFunctionToolTip(r, func, "UART1_NAME_" & sName)
                Else
                    .DisabledTooltipText = GetDisabledFunctionTooltipEntry(func, "UART1_NAME_" & sName)
                    If (bConditionInit) Then .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip(TOOLTIP_DESELECTED_INIT)
                    If (bConditionPins) Then .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip("the UART1 is not used as transmitter or receiver")
                    If (bConditionRx) Then .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip("the receiver is not enabled")
                    If (bConditionTx) Then .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip("the UART1 is not used as transmitter")
                    If (bConditionMode13) Then .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip("Mode 1 or 3 is not selected")
                    If (bConditionIntFlg) Then .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip("the UART1 interrupt is enabled. So the interrupt flags can not be used for this function.")
                    If (bCondition8Bit) Then .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip("the data unit size of the selected mode is not 8 bit")
                    If (bCondition9Bit) Then .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip("the data unit size of the selected mode is not 9 bit")
                    If (bConditionMulti) Then .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip("multiprocessor communication is not selected")
                End If
            End If
        Else
            ' tooltip if control is enabled
            .EnabledTooltipText = FormatFunctionToolTip(r, func, "UART1_NAME_" & sName)
            
        End If
      End With

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

      With e("txtUART_NAME_" & sName)
        If (bDisabled) Then
            '.DisabledToolTipText = FormatNormalToolTip(TOOLTIP_DISABLED_FUNC_NAME)
           If (sName = "Isr") Then
              If (IsModuleClockDisabled(r, vToolIndex)) Then
                  .DisabledToolTipText = TOOLTIP_DISABLED_IF
                  .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleClockDisabled(r, vToolIndex)
              Else
                  .DisabledTooltipText = FormatNormalToolTip(TOOLTIP_DISABLED_FUNC_SHAREDISR)
              End If
           Else
               .DisabledToolTipText = TOOLTIP_DISABLED_IF
               If (IsModuleClockDisabled(r, vToolIndex)) Then
                  .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleClockDisabled(r, vToolIndex)
               Else
                  .DisabledTooltipText = FormatNormalToolTip(TOOLTIP_DISABLED_FUNC_NAME)
               End If
           End If
        End If
      End With

  End If

  CheckFunction = True
ExitLabel:
End Function

'*****************************************************************************
'Description:
'        This function is called from the OnLoad function of the associated
'        module in order to add a page.
'-----------------------------------------------------------------------------
'Parameters:
'        ps               reference to the Peripherals object
'-----------------------------------------------------------------------------
'Returns:
'        True            on successful 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


Public Function OnChangingPageParameters(ps As Peripherals, Pagename As String) As Boolean
  On Error Resume Next

  Dim iPos As Integer
  Dim sName As String

  OnChangingPageParameters = False

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

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

  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 successful operation
'        False           else
'*****************************************************************************
Public Function OnShowPageParameters(ps As Peripherals, Controlname As String, Pagename As String, v() As Variant) As Boolean
  On Error GoTo OnShowError

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

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


  If (Pagename = "Parameters") Then
    '-------------------------------------------------------------------------
    ' page: Parameters (action)
    '-------------------------------------------------------------------------
    Select Case Controlname
        Case "txtUART_HFile"
            If (IsInputFormatOK(v(1), FORMAT_FILES, c("lblUART_HFile").Caption)) Then
                r.v("UART1_HFile") = v(1)
            Else
                Exit Function
            End If

        Case Else
            'no editable parameters implemented

    End Select

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

    With c("txtUART_HFile")
        bDisabled = (r.v("UART1_USE_Init") = 0)
        .Enabled = Not bDisabled
        .Text = FormatTextOutput(r.v("UART1_HFile"), "S")
    End With
    With e("txtUART_HFile")
        If (bDisabled) Then
            .DisabledTooltipText = FormatNormalToolTip(TOOLTIP_DISABLED_HFILE_NAME)
        End If
    End With

    'no editable parameters implemented

  End If         ' if Pagename

  OnShowPageParameters = True
  Exit Function

OnShowError:
    errorbox "Can not show page", Err.Description
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 successful operation
'        False           else
'*****************************************************************************
Private Function OnLoadPageBRG(ps As Peripherals) As Boolean
On Error Resume Next
    OnLoadPageBRG = False
    
    If (Not ps.AddPage("BRG")) Then Exit Function
    
    OnLoadPageBRG = True
End Function

Public Function OnChangingPageBRG(ps As Peripherals, Pagename As String) As Boolean
  On Error Resume Next
  
  OnChangingPageBRG = False
  
  If (Not ps.ExtenderCollection("BRG").Loaded) And (Pagename = "BRG") Then
    ps.ExtenderCollection("BRG").Loaded = True
    
    
    '-------------------------------
    ' frame: fraBRGCon
    '-------------------------------
    If (Not ps.AddFrame("fraBRGCon", 100, 100, 3500, 1000, "BRG Run Control")) Then Exit Function
        If (Not ps.AddCheck("chkBRGCon", 200, 260, 1950, 380, "Enable BRG (X.R)")) Then Exit Function
    
    '-------------------------------
    ' frame: fraFracDivide
    '-------------------------------
    If (Not ps.AddFrame("fraFracDivide", 3700, 100, 3400, 1000, "Fractional Divider Control")) Then Exit Function
        If (Not ps.AddCheck("chkFracDivide", 200, 260, 3150, 380, "Enable Fractional Divider (UART1_FDCON.FDEN)")) Then Exit Function
        
    '-------------------------------
    ' frame: fraBRG
    '-------------------------------
    If (Not ps.AddFrame("frmBRG", 100, 1300, 7000, 2800, "BRG Settings")) Then Exit Function
        If (Not ps.AddLabel("lblPreScaler", 0, 200, 300, 1575, 240, "Prescaler (X.BRPRE)")) Then Exit Function
        If (Not ps.AddCombo("cboPreScaler", 2000, 250, 1815, 315)) Then Exit Function
        With ps.ControlCollection("cboPreScaler")
            .AddItem "fDIV = fPCLK"
            .AddItem "fDIV = fPCLK/2"
            .AddItem "fDIV = fPCLK/4"
            .AddItem "fDIV = fPCLK/8"
            .AddItem "fDIV = fPCLK/16"
            .AddItem "fDIV = fPCLK/32"
        End With
        
        If (Not ps.AddLabel("lblFracDivide", 0, 4000, 250, 1815, 1500, "STEP Value")) Then Exit Function
        If (Not ps.AddText("txtFracDivide", 5500, 250, 1000, 315)) Then Exit Function
        
        
        If (Not ps.AddLabel("lblReqBaud", 0, 200, 800, 1575, 385, "Required Baudrate [kBaud]")) Then Exit Function
        If (Not ps.AddText("txtReqBaud", 2000, 800, 1000, 315)) Then Exit Function
        
        If (Not ps.AddLabel("lblMinBaudLabel", 0, 200, 1550, 1300, 385, "Min. Baudrate [Baud]")) Then Exit Function
        If (Not ps.AddLabel("lblMinBaud", 1, 2000, 1550, 1000, 315)) Then Exit Function
        
        If (Not ps.AddLabel("lblMaxBaudLabel", 0, 200, 2150, 1300, 385, "Max. Baudrate [MBaud]")) Then Exit Function
        If (Not ps.AddLabel("lblMaxBaud", 1, 2000, 2150, 1000, 315)) Then Exit Function
        
        If (Not ps.AddLabel("lblActualBaudLabel", 0, 4000, 800, 1575, 385, "Actual Baudrate [kBaud]")) Then Exit Function
        If (Not ps.AddLabel("lblActualBaud", 1, 5500, 800, 1000, 315)) Then Exit Function
                
        If (Not ps.AddLabel("lblDeviationLabel", 0, 4000, 1550, 1500, 400, "Percentage of deviation [%]")) Then Exit Function
        If (Not ps.AddLabel("lblDeviation", 1, 5500, 1550, 1000, 315)) Then Exit Function
        
        If (Not ps.AddLabel("lblReloadValue", 0, 4000, 2150, 1200, 400, "Reload Value (BG) ")) Then Exit Function
        If (Not ps.AddText("txtReloadValue", 5500, 2150, 1000, 315)) Then Exit Function
        
        ' frame: frmNote
        '-------------------------------
        If (Not ps.AddFrame("frmNote", 100, 4200, 7000, 900, "Note")) Then Exit Function
        If (Not ps.AddLabel("lblREG", 0, 120, 300, 3575, 385, "X = UART1_BCON")) Then Exit Function
    '---------------------------------------------------------------------------------------
    ' Following controls are for Normal Divider mode
    '---------------------------------------------------------------------------------------
    
    '-------------------------------
    ' frame: fraNormalDivider
    '-------------------------------
    If (Not ps.AddFrame("fraNormalDivider", 100, 100, 3500, 1000, "Normal Divider Mode")) Then Exit Function
        If (Not ps.AddCheck("chkNormalDivider", 200, 260, 2800, 380, "Select Normal Divider Mode (UART1_FDCON.FDM)")) Then Exit Function

    '-------------------------------
    ' frame: fraStartTimer
    '-------------------------------
    If (Not ps.AddFrame("fraStartTimer", 3700, 100, 3400, 1000, "Timer Run Control")) Then Exit Function
        If (Not ps.AddCheck("chkStartTimer", 200, 260, 3150, 380, "Start timer (UART1_FDCON.FDEN)")) Then Exit Function


    '-------------------------------
    ' frame: fraTmrSettings
    '-------------------------------
    If (Not ps.AddFrame("frmTmrSettings", 100, 1300, 7000, 2800, "Timer Settings")) Then Exit Function
        'If (Not ps.AddLabel("lblTmrPreScaler", 0, 200, 300, 1575, 240, "Prescaler (UART1_BCON.BRPRE)")) Then Exit Function
        'If (Not ps.AddCombo("cboTmrPreScaler", 2000, 250, 1815, 315)) Then Exit Function
         If (Not ps.AddLabel("lblTmrPreScaler", 0, 200, 300, 2575, 240, "Prescaler (UART1_BCON.BRPRE)")) Then Exit Function
         If (Not ps.AddCombo("cboTmrPreScaler", 3200, 250, 1815, 315)) Then Exit Function
        With ps.ControlCollection("cboTmrPreScaler")
            .AddItem "fDIV = fPCLK"
            .AddItem "fDIV = fPCLK/2"
            .AddItem "fDIV = fPCLK/4"
            .AddItem "fDIV = fPCLK/8"
            .AddItem "fDIV = fPCLK/16"
            .AddItem "fDIV = fPCLK/32"
        End With


        If (Not ps.AddLabel("lblTmrReloadValue", 0, 200, 925, 1575, 385, "Reload Value (STEP)")) Then Exit Function
        'If (Not ps.AddText("txtTmrReloadValue", 2000, 900, 1000, 315)) Then Exit Function
        If (Not ps.AddText("txtTmrReloadValue", 3200, 900, 1000, 315)) Then Exit Function

        If (Not ps.AddLabel("lblTmrOverflow", 0, 200, 1550, 1500, 385, "Timer Overflow [" & Chr(181) & "s]")) Then Exit Function
        'If (Not ps.AddLabel("lblTmrOverflowtxt", 1, 2000, 1550, 1275, 315)) Then Exit Function
        If (Not ps.AddLabel("lblTmrOverflowtxt", 1, 3200, 1550, 1275, 315)) Then Exit Function
    '-------------------------------
    ' frame: frmTmrInterrupt
    '-------------------------------
    If (Not ps.AddFrame("frmTmrInterrupt", 100, 4200, 7000, 900, "Interrupt Control")) Then Exit Function
        If (Not ps.AddCheck("chkEnableNDOV", 125, 300, 3300, 400, "Enable timer overflow interrupt (IEN1.EX2)")) Then Exit Function


  End If
  
  OnChangingPageBRG = 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 successful operation
'        False           else
'*****************************************************************************
Public Function OnShowPageBRG(ps As Peripherals, Controlname As String, Pagename As String, v() As Variant) As Boolean
  On Error GoTo OnShowError

  OnShowPageBRG = False
  
  Dim vIndex As Variant
  Dim vToolIndex As Variant
  Dim bDisabled As Boolean
  Dim c As Collection
  Dim e As Collection
  Dim r As ProjectData
  Dim Baudrate    As BaudrateType
  Dim MaxBaudRate As BaudrateType
  
  Set c = ps.ControlCollection
  Set e = ps.ExtenderCollection
  Set r = ps.ProjectData
  
  If Pagename = "BRG" Then
  '-------------------------------------------------------------------------
  'Page BRG (Control)
  '-------------------------------------------------------------------------
    Select Case Controlname
        
        Case "chkBRGCon"
            If v(1) = 0 Then
                r.l(UART1_PREFIX & "BCON_BRPRE") = &H0
                r.l(UART1_PREFIX & "FDSTEP_STEP") = &H0
                r.v(UART1_PREFIX & "FDCON_FDEN") = 0
                r.v("Uart1_Baudrate") = GetUartMaxBaudrate(r)
                Call UpdateUartBaudrate(r)
            End If
            r.v(UART1_PREFIX & "BCON_R") = v(1)
        
        Case "chkNormalDivider"
            r.v(UART1_PREFIX & "FDCON_FDM") = v(1)
            If v(1) = 0 Then
                Call ResetBRG(r)
                r.v("BRG1_Interrupt_Select") = 0
            End If
        
        Case "chkStartTimer"
            r.v(UART1_PREFIX & "FDCON_FDEN") = v(1)
            
'        Case "chkEnableNDOV"
'        If v(1) = 1 Then
'            If r.v(CORE_PREFIX & "IEN0_ET2") = 1 Then
'                If Ask(MSG_SELECT_BRG_INTERRUPT_1) Then
'                    r.v("BRG_Interrupt_Select") = v(1)
'                End If
'            Else
'                If Ask(MSG_SELECT_BRG_INTERRUPT_2) Then
'                    r.v("BRG_Interrupt_Select") = v(1)
'                End If
'            End If
'        Else
'          r.v("BRG_Interrupt_Select") = 0
'        End If
'
        Case "chkEnableNDOV"
            If v(1) = 1 Then
              If (r.v("INTR_MSGEN") = 1) Then
                   SharedInt = MsgBox(MSG_SELECT_XINTR8_INTERRUPTS, vbYesNo + vbQuestion, "DAvE")
                   If (SharedInt = 6) Then
                       r.v("INTR_MSGEN") = 1
                   ElseIf (SharedInt = 7) Then
                       r.v("INTR_MSGEN") = 0
                       SharedInt = MsgBox(MSGBOX_SHAREDINT_ENABLE, vbInformation, "DAvE")
                   End If
              End If
              r.v("BRG1_Interrupt_Select") = v(1)
            Else
              r.v("BRG1_Interrupt_Select") = 0
            End If
  
         
        Case "chkFracDivide"
            r.v(UART1_PREFIX & "FDCON_FDEN") = v(1)
            If Not v(1) Then
                r.l(UART1_PREFIX & "FDSTEP_STEP") = &H0
            End If
             Call UpdateUartBaudrate(r)
        
        Case "cboPreScaler"
            Select Case v(1)
                Case "fDIV = fPCLK"
                    r.l(UART1_PREFIX & "BCON_BRPRE") = &H0
                    
                    
                Case "fDIV = fPCLK/2"
                    r.l(UART1_PREFIX & "BCON_BRPRE") = &H1
                    
                Case "fDIV = fPCLK/4"
                    r.l(UART1_PREFIX & "BCON_BRPRE") = &H2
                    
                Case "fDIV = fPCLK/8"
                    r.l(UART1_PREFIX & "BCON_BRPRE") = &H3
                    
                Case "fDIV = fPCLK/16"
                    r.l(UART1_PREFIX & "BCON_BRPRE") = &H4
                    
                Case "fDIV = fPCLK/32"
                    r.l(UART1_PREFIX & "BCON_BRPRE") = &H5
                    
            End Select
            r.v("Uart1_Baudrate") = Format(GetUartMaxBaudrate(r), "0.0000")
            Call UpdateUartBaudrate(r)
        
        Case "cboTmrPreScaler"
            Select Case v(1)
                Case "fDIV = fPCLK"
                    r.l(UART1_PREFIX & "BCON_BRPRE") = &H0
                    
                Case "fDIV = fPCLK/2"
                    r.l(UART1_PREFIX & "BCON_BRPRE") = &H1
                    
                Case "fDIV = fPCLK/4"
                    r.l(UART1_PREFIX & "BCON_BRPRE") = &H2
                    
                Case "fDIV = fPCLK/8"
                    r.l(UART1_PREFIX & "BCON_BRPRE") = &H3
                    
                Case "fDIV = fPCLK/16"
                    r.l(UART1_PREFIX & "BCON_BRPRE") = &H4
                    
                Case "fDIV = fPCLK/32"
                    r.l(UART1_PREFIX & "BCON_BRPRE") = &H5
                    
            End Select
        
        Case "txtFracDivide"
            If (IsInputFormatOK(v(1), "H2", c("lblFracDivide").Caption, 0, 255)) Then
               r.sfr(UART1_PREFIX & "FDSTEP") = v(1)
               'r.d("Uart_Baudrate") = Format(GetActualUartBaudrate(r), "0.0000")
             Else
                 Exit Function
             End If
        
        Case "txtReqBaud"
            Baudrate = ConvertBaudrate(r.v("Uart1_Baudrate"))
            MaxBaudRate = ConvertBaudrate(GetUartMaxBaudrate(r))
            
            If (IsInputFormatOK(v(1), "F", c("lblReqBaud").Caption)) Then
                If (IsInputValueOK(Format(v(1) * Baudrate.dDivider, "0.0000"), _
                   Format(GetUartMinBaudrate(r), "0.0000"), _
                   Format(Format(GetUartMaxBaudrate(r) / MaxBaudRate.dDivider, "0.0000") _
                    * MaxBaudRate.dDivider, "0.0000"))) Then
                    r.v("Uart1_Baudrate") = v(1) * Baudrate.dDivider ' convert to baud
                    Call UpdateUartBaudrate(r)
                Else
                    Exit Function
                End If
            Else
                Exit Function
            End If
            
        Case "txtReloadValue"
            If (IsInputFormatOK(v(1), "H2", c("lblReloadValue").Caption, 0, 255)) Then
               r.sfr(UART1_PREFIX & "BG") = v(1)
               r.d("Uart1_Baudrate") = Format(GetActualUartBaudrate(r), "0.0000")
             Else
                 Exit Function
             End If
             
       Case "txtTmrReloadValue"
            If (IsInputFormatOK(v(1), "H2", "STEP", 0, 255)) Then
               r.l(UART1_PREFIX & "FDSTEP_STEP") = v(1)
             Else
                 Exit Function
             End If
        
        
    End Select
    
  '-------------------------------------------------------------------------
  'Page BRG (Show)
  '-------------------------------------------------------------------------
  
'  If r.v(BRG_PREFIX & "FDCON_BGS") = 1 Or Not (GetUartMode(r) = 1 Or GetUartMode(r) = 3) Then
   If Not (GetUartMode(r) = 1 Or GetUartMode(r) = 3) Then
    '-------------------------------------------------------------------
    ' Frame : "Normal Divider Mode"
    '-------------------------------------------------------------------
    With c("chkNormalDivider")
         bDisabled = (r.v(SCU_PREFIX & "PMCON2_UART1_DIS")) Or CheckDisabledUart(r)
        .Enabled = Not bDisabled
        .Value = r.l(UART1_PREFIX & "FDCON_FDM")
    End With
    
    With e("chkNormalDivider")
        If (bDisabled) Then
            .DisabledToolTipText = TOOLTIP_DISABLED_IF
           If (r.v(SCU_PREFIX & "PMCON2_UART1_DIS") = 0) Then
            .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip("UART1 is not used as Transmitter or Receiver")
            ElseIf CheckDisabledUart(r) Then
            .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleClockDisabled(r, vToolIndex)
        End If
      End If
    End With
    With c("chkStartTimer")
        bDisabled = (r.v(UART1_PREFIX & "FDCON_FDM") = 0) Or (r.v(SCU_PREFIX & "PMCON2_UART1_DIS") = 1)
        .Enabled = Not bDisabled
        .Value = r.l(UART1_PREFIX & "FDCON_FDEN")
    End With
    
    With e("chkStartTimer")
        If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (IsModuleClockDisabled(r, vToolIndex)) Then
               .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleClockDisabled(r, vToolIndex)
            Else
            .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip("Normal divider mode is not selected")
            End If
        End If
    End With
    
    With c("lblTmrPreScaler")
        bDisabled = (r.v(UART1_PREFIX & "FDCON_FDM") = 0)
        .Enabled = Not bDisabled
    End With
    
    With c("cboTmrPreScaler")
        bDisabled = (r.v(UART1_PREFIX & "FDCON_FDM") = 0) Or (r.v(SCU_PREFIX & "PMCON2_UART1_DIS") = 1)
        .Enabled = Not bDisabled
        .ListIndex = r.l(UART1_PREFIX & "BCON_BRPRE")
    End With
    
    With e("cboTmrPreScaler")
        If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (IsModuleClockDisabled(r, vToolIndex)) Then
               .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleClockDisabled(r, vToolIndex)
            Else
            .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip("Normal divider mode is not selected")
            End If
        End If
    End With
    
    With c("txtTmrReloadValue")
        bDisabled = (r.v(UART1_PREFIX & "FDCON_FDM") = 0) Or (r.v(SCU_PREFIX & "PMCON2_UART1_DIS") = 1)
        .Enabled = Not bDisabled
        
        If (bDisabled) Then
            .Text = CALCULATION_NOT_POSSIBLE
        Else
            .Text = FormatTextOutput(r.l(UART1_PREFIX & "FDSTEP_STEP"), "H2")
        End If
    End With
    
    With e("txtTmrReloadValue")
        If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (IsModuleClockDisabled(r, vToolIndex)) Then
               .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleClockDisabled(r, vToolIndex)
            Else
            .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip("Normal divider mode is not selected")
            End If
        End If
    End With
    
    With c("lblTmrOverflowtxt")
        bDisabled = (r.v(UART1_PREFIX & "FDCON_FDM") = 0) Or (r.v(SCU_PREFIX & "PMCON2_UART1_DIS") = 1)
        .Enabled = Not bDisabled
        
        If (bDisabled) Then
            .Caption = CALCULATION_NOT_POSSIBLE
        Else
            .Caption = GetBRGTmrOverflow(r)
        End If
    End With
     With e("lblTmrOverflowtxt")
        If (bDisabled) Then
            .DisabledToolTipText = TOOLTIP_DISABLED_IF
            .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleClockDisabled(r, vToolIndex)
        End If
    End With
    With c("lblTmrReloadValue")
        bDisabled = (r.v(UART1_PREFIX & "FDCON_FDM") = 0)
        .Enabled = Not bDisabled
    End With
        
    With c("lblTmrOverflow")
        bDisabled = (r.v(UART1_PREFIX & "FDCON_FDM") = 0)
        .Enabled = Not bDisabled
    End With
    
    With c("chkEnableNDOV")
        bDisabled = (r.v(UART1_PREFIX & "FDCON_FDM") = 0) Or (r.v(SCU_PREFIX & "PMCON2_UART1_DIS") = 1)
        .Enabled = Not bDisabled
        .Value = r.v("BRG1_Interrupt_Select")
    End With
    
    With e("chkEnableNDOV")
        If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (IsModuleClockDisabled(r, vToolIndex)) Then
               .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleClockDisabled(r, vToolIndex)
            Else
            .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip("Normal divider mode is not selected")
            End If
        End If
    End With
    
    End If
    
'    bDisabled = Not ((r.v(BRG_PREFIX & "FDCON_BGS") = 1) Or Not (GetUartMode(r) = 1 Or GetUartMode(r) = 3))
      bDisabled = Not (Not (GetUartMode(r) = 1 Or GetUartMode(r) = 3))
    
    With c("fraNormalDivider")
        .Visible = Not bDisabled
    End With
    
    With c("fraStartTimer")
        .Visible = Not bDisabled
    End With
    
    With c("frmTmrSettings")
        .Visible = Not bDisabled
    End With
    
    With c("frmTmrInterrupt")
        .Visible = Not bDisabled
    End With
    
'  If r.v(BRG_PREFIX & "FDCON_BGS") = 0 And Not (GetUartMode(r) = 0 Or GetUartMode(r) = 2) Then
   If Not (GetUartMode(r) = 0 Or GetUartMode(r) = 2) Then
    '-------------------------------------------------------------------
    ' Frame : "BRG run control"
    '-------------------------------------------------------------------
    With c("chkBRGCon")
        bDisabled = (CheckDisabledUart(r) Or (GetUartMode(r) = 0) Or (GetUartMode(r) = 2)) Or (r.v(SCU_PREFIX & "PMCON2_UART1_DIS") = 1)
        .Enabled = Not bDisabled
        .Value = r.l(UART1_PREFIX & "BCON_R")
    End With
    
    With e("chkBRGCon")
        If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (IsModuleClockDisabled(r, vToolIndex)) Then
               .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleClockDisabled(r, vToolIndex)
            Else
               If GetUartMode(r) = 2 Then
                  .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip("Mode 2 is selected")
               ElseIf CheckDisabledUart(r) Then
                  .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip("the UART1 is not used as transmitter or receiver")
               Else
                  .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip("Mode 0 is selected")
               End If
           End If
        End If
    End With
    
    
    
    '-------------------------------------------------------------------
    ' Frame : "Fractional Divider"
    '-------------------------------------------------------------------
    With c("chkFracDivide")
        bDisabled = (r.v(UART1_PREFIX & "BCON_R") = 0) Or (r.v(SCU_PREFIX & "PMCON2_UART1_DIS") = 1)
        .Enabled = Not bDisabled
        .Value = r.l(UART1_PREFIX & "FDCON_FDEN")
    End With
    
    With e("chkFracDivide")
        If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (IsModuleClockDisabled(r, vToolIndex)) Then
               .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleClockDisabled(r, vToolIndex)
            Else
            .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip("Baudrate generator is not enabled")
            End If
        End If
    End With
    
    With c("txtFracDivide")
        bDisabled = (r.v(UART1_PREFIX & "BCON_R") = 0) Or (r.v(UART1_PREFIX & "FDCON_FDEN") = 0) Or (r.v(SCU_PREFIX & "PMCON2_UART1_DIS") = 1)
        .Enabled = False
        If (bDisabled) Then
            .Text = CALCULATION_NOT_POSSIBLE
        Else
            .Text = FormatTextOutput(r.l(UART1_PREFIX & "FDSTEP_STEP"), "H2")
        End If
    End With
    
    With e("txtFracDivide")
        If (bDisabled) Then
           .DisabledTooltipText = FormatDisabledToolTip("This value will be set by DAvE if the fractional divider is enabled.")
        End If
    End With
    With c("lblFracDivide")
        bDisabled = (r.v(UART1_PREFIX & "BCON_R") = 0) Or (r.v(UART1_PREFIX & "FDCON_FDEN") = 0)
        .Enabled = Not bDisabled
    End With
    
    '-------------------------------------------------------------------
    ' Frame : "BRG settings"
    '-------------------------------------------------------------------
    With c("lblPreScaler")
        bDisabled = (r.v(UART1_PREFIX & "BCON_R") = 0)
        .Enabled = Not bDisabled
    End With
    
    With c("cboPreScaler")
        bDisabled = (r.v(UART1_PREFIX & "BCON_R") = 0) Or (r.v(SCU_PREFIX & "PMCON2_UART1_DIS") = 1)
        .Enabled = Not bDisabled
        .ListIndex = r.l(UART1_PREFIX & "BCON_BRPRE")
    End With
    
    With e("cboPreScaler")
        If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (IsModuleClockDisabled(r, vToolIndex)) Then
               .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleClockDisabled(r, vToolIndex)
            Else
               .DisabledToolTipText = .DisabledToolTipText & FormatDisabledToolTip("Baudrate generator is not enabled")
            End If
        End If
    End With
    
    
    '-------------------------------------------------------------------
    ' txtReqBaud (show)
    '-------------------------------------------------------------------
    With c("txtReqBaud")
        bDisabled = (r.v(UART1_PREFIX & "BCON_R") = 0) Or (r.v(SCU_PREFIX & "PMCON2_UART1_DIS") = 1)
        .Enabled = Not bDisabled
        
        If (bDisabled) Then
            .Text = CALCULATION_NOT_POSSIBLE
            c("lblReqBaud").Caption = "Required baud rate [baud]"
        Else
            Baudrate = ConvertBaudrate(r.d("Uart1_Baudrate"))
            .Text = Format(Baudrate.dValue, "0.0000")
            c("lblReqBaud").Caption = "Required baud rate [" & Baudrate.sUnit & "]"
            
        End If
        
    End With
        
    With e("txtReqBaud")
        If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (IsModuleClockDisabled(r, vToolIndex)) Then
               .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleClockDisabled(r, vToolIndex)
            Else
               .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip("Baudrate generator is not enabled")
            End If
        End If
    End With
    
    '-------------------------------------------------------------------
    ' lblReqBaud (show)
    '-------------------------------------------------------------------
    With c("lblReqBaud")
        bDisabled = (r.v(UART1_PREFIX & "BCON_R") = 0)
        .Enabled = Not bDisabled
    End With
    
    '-------------------------------------------------------------------
    ' lblActualBaudLabel (show)
    '-------------------------------------------------------------------
    With c("lblActualBaudLabel")
        bDisabled = (r.v(UART1_PREFIX & "BCON_R") = 0)
        .Enabled = Not bDisabled
    End With
    
    With c("lblActualBaud")
        bDisabled = (r.v(UART1_PREFIX & "BCON_R") = 0)
        .Enabled = Not bDisabled
        
        If (bDisabled) Then
            .Caption = CALCULATION_NOT_POSSIBLE
            c("lblActualBaudLabel").Caption = "Actual baud rate [baud]"
        Else
            Baudrate = ConvertBaudrate(GetActualUartBaudrate(r))
            .Caption = Format(Baudrate.dValue, "0.0000")
            c("lblActualBaudLabel").Caption = "Actual baud rate [" & Baudrate.sUnit & "]"
        End If
    End With
    
    With c("lblMinBaud")
        bDisabled = (r.v(UART1_PREFIX & "BCON_R") = 0)
        .Enabled = Not bDisabled
        
        If (bDisabled) Then
            .Caption = CALCULATION_NOT_POSSIBLE
            c("lblMinBaudLabel").Caption = "Min. baud rate [baud]"
        Else
            Baudrate = ConvertBaudrate(GetUartMinBaudrate(r))
            .Caption = Format(Baudrate.dValue, "0.0000")
            c("lblMinBaudLabel").Caption = "Min. baud rate [" & Baudrate.sUnit & "]"
        End If
      
    End With
    
    With c("lblMinBaudLabel")
        bDisabled = (r.v(UART1_PREFIX & "BCON_R") = 0)
        .Enabled = Not bDisabled
    End With
    
    
    With c("lblMaxBaud")
        bDisabled = (r.v(UART1_PREFIX & "BCON_R") = 0)
        .Enabled = Not bDisabled
        
        If (bDisabled) Then
            .Caption = CALCULATION_NOT_POSSIBLE
            c("lblMaxBaudLabel").Caption = "Max. baud rate [baud]"
        Else
            Baudrate = ConvertBaudrate(GetUartMaxBaudrate(r))
            .Caption = Format(Baudrate.dValue, "0.0000")
            c("lblMaxBaudLabel").Caption = "Max. baud rate [" & Baudrate.sUnit & "]"
        End If
        
    End With
    
    With c("lblMaxBaudLabel")
        bDisabled = (r.v(UART1_PREFIX & "BCON_R") = 0)
        .Enabled = Not bDisabled
    End With
            
    With c("txtReloadValue")
        bDisabled = (r.v(UART1_PREFIX & "BCON_R") = 0) Or (r.v(SCU_PREFIX & "PMCON2_UART1_DIS") = 1)
        .Enabled = Not bDisabled
        
        If (bDisabled) Then
            .Text = CALCULATION_NOT_POSSIBLE
        Else
             UpdateUartBaudrate (r) 'ashish
            .Text = FormatTextOutput(r.l(UART1_PREFIX & "BG_BR_VALUE"), "H2")
        End If
    End With
    
    With e("txtReloadValue")
        If (bDisabled) Then
            .DisabledTooltipText = TOOLTIP_DISABLED_IF
            If (IsModuleClockDisabled(r, vToolIndex)) Then
               .DisabledToolTipText = .DisabledToolTipText & GetTooltipModuleClockDisabled(r, vToolIndex)
            Else
               .DisabledTooltipText = .DisabledTooltipText & FormatDisabledToolTip("Baudrate generator is not enabled")
            End If
        End If
    End With
    
    With c("lblReloadValue")
        bDisabled = (r.v(UART1_PREFIX & "BCON_R") = 0)
        .Enabled = Not bDisabled
    End With
       
    With c("lblDeviation")
        bDisabled = (r.v(UART1_PREFIX & "BCON_R") = 0)
        .Enabled = Not bDisabled
        
        If (bDisabled) Then
          .Caption = CALCULATION_NOT_POSSIBLE
        Else
            .Caption = Format((Format(GetActualUartBaudrate(r), "0.0000") - r.d("Uart1_Baudrate")) / _
                             r.d("Uart1_Baudrate") * 100, "0.0000")
        End If
      
    End With
    
    With c("lblDeviationLabel")
        bDisabled = (r.v(UART1_PREFIX & "BCON_R") = 0)
        .Enabled = Not bDisabled
    End With
    
  End If
    
  End If
    
  OnShowPageBRG = True
  Exit Function
     
OnShowError:
  errorbox "ERROR: Show BRG", Err.Description
End Function

'*****************************************************************************
'Description:
'             This function resets the BRG module.
'
'
'-----------------------------------------------------------------------------
'Parameters:
'           r    Project Data
'
'-----------------------------------------------------------------------------
'Returns:
'           Nothing
'
'*****************************************************************************
  
Private Sub ResetBRG(r As ProjectData)
On Error Resume Next
    
   r.v(UART1_PREFIX & "BCON_R") = 0
   r.sfr(UART1_PREFIX & "BG") = 0
   r.v(UART1_PREFIX & "FDCON_FDM") = 0
   r.v(UART1_PREFIX & "FDCON_FDEN") = 0
   r.sfr(UART1_PREFIX & "FDSTEP") = 0
   r.l(UART1_PREFIX & "BCON_BRPRE") = 0
   r.v("Uart1_Baudrate") = GetUartMaxBaudrate(r)
End Sub
