Attribute VB_Name = "Module1"
'#Uses "..\include\Const.inc"
'#Uses "..\include\Global.inc"
'#Uses "..\include\CC6Format.inc"
'#Uses "..\classes\CC6FunctionClass.cls"
'#Uses "..\classes\CC6ParameterClass.cls
'#Uses "Include.inc"
'#Uses "..\include\Port.inc"
'#Uses "8BitAdapter.inc"
'#Uses "GenCodeForNodes.inc"

Option Explicit

'*****************************************************************************
' Module:
'        CAPCOMx
'-----------------------------------------------------------------------------
' Description:
'        This file contains functions for generating code for the
'        module 'CAPCOMx'.
'
'-----------------------------------------------------------------------------
' History:
'
'        Rev. Author         Date        Description
'        ---------------------------------------------------------------------
'        0.1   sheshadri    20.11.04     initial version for XC866
'        0.2   sheshadri    02.02.05     SFR page macro Added
'        0.3   sheshadri    27.04.05     CC6_vInit initialization sequence chaged
'                                        in TCTR4L & 4H
'        0.4   sheshadri    28.07.05     Macros StartTmr, StopTmr, ResetTmr, EnShadowTra
'                                         put OR operator (|= 0x)
'        0.5   sheshadri    23.11.05     Pins added wrt to B-Step
'        0.6   sheshadri    13.01.06     Pins added wrt to XC886C
'
'*****************************************************************************

'*****************************************************************************
'Description:
'        This functions initiates the code generation for the CAPCOMx module.
'-----------------------------------------------------------------------------
'Parameters:
'        r                reference to the Registers object
'        vIndex           a parameter
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Function StartGenerateCode(r As ProjectData, vIndex As Variant) As Boolean
    On Error GoTo StartGenerateCodeError
    StartGenerateCode = False
    Dim sVarPre As String

    sVarPre = "CCU" & vIndex

    ' write files CAPCOMx.h
    If (r.v(sVarPre & "_USE_Init") = 1) Then
      If (Not CAPCOMxGenerateH(r, vIndex)) Then Exit Function
                   If (Not r.AddFile(r.s(sVarPre & "_HFILE"))) Then Exit Function
    End If

    ' write file CAPCOMx.c
    If (r.v(sVarPre & "_USE_Init") = 1) Then
      If (Not CAPCOMxGenerateC(r, vIndex)) Then Exit Function
                   If (Not r.AddFile(r.s(sVarPre & "_CFILE"))) Then Exit Function
    End If
        
    StartGenerateCode = True
    Exit Function
    
StartGenerateCodeError:
    Errorbox("Code generation for " & sVarPre & " failed", Error$)
    Exit Function
End Function


'*****************************************************************************
'Description:
'        Generates the code for the CAPCOMx.c file.
'-----------------------------------------------------------------------------
'Parameters:
'        r                reference to the Registers object
'        vIndex           a parameter
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Function CAPCOMxGenerateC(r As ProjectData, vIndex As Variant) As Boolean
    On Error GoTo CAPCOMxGenerateCError
    
    '------------------------------------------------
    Dim lP0MaskALTSEL0 As Long
    Dim lP3MaskALTSEL0 As Long
    Dim lP0MaskALTSEL1 As Long
    Dim lP3MaskALTSEL1 As Long
    Dim lP0MaskDIR  As Long
    Dim lP3MaskDIR As Long

    Dim bP3Selected As Boolean
    Dim bP0Selected As Boolean
    Dim bP3_1Selected As Boolean
    '------------------------------------------------
    Dim i As Integer
    Dim f As Variant
    Dim v As Variant
    Dim d As String
    Dim dc As DAvECollection
    Dim uc As UserCode
    Dim func As CC6FunctionClass
    Dim n As String
    Dim Overflow As UnitType
    Dim iTmr_12 As Integer
    Dim iTmr_13 As Integer
    Dim iTmr As Integer
    Dim iCh_low As Integer
    Dim iCh_high As Integer
    Dim iChannel As Integer
    Dim lRegPre As Long
    Dim sHelp As String
    Dim sAlternatePinName(1 To 32) As String

    Dim sVarPre As String
    Dim sRegPre As String
    Dim sPinName As String
    Dim sPin As String

    sVarPre = "CCU" & vIndex
    sRegPre = sVarPre & "_"
    
    iCh_low = 0
    iCh_high = 3
    iTmr_12 = 12
    iTmr_13 = 13
    
    CAPCOMxGenerateC = False
    Set dc = ObjectCollection("MODULENAMES")
    Set uc = New UserCode
    Set func = New CC6FunctionClass

    'refresh the decriptions of the functions and macros
    Call RefreshFunctionDescriptions(vIndex, func, r)

    'read usercode
    uc.ReadFile ((StripFilenameAndExtension(r.LoadedFile)) & "\" & r.v(sVarPre & "_CFILE"))

    'open CAPCOMx.c
    f = FreeFile
    Open CStr(StripFilenameAndExtension(r.LoadedFile)) & "\" & r.v(sVarPre & "_CFILE") For Output As f
    
    '------------------------------------------------------------------------------------------------
    ' module header
    '------------------------------------------------------------------------------------------------
    d = FormatModuleDescription(GetModuleHeaderC(sVarPre))
    Print #f, Rtf.GenerateModuleHeader(DefGetValue("ProductVersion"), StripPath(r.LoadedFile), dc(sVarPre).ModuleDescription, r.v(sVarPre & "_CFILE"), r.v("MAIN_CPU_TYPE"), r.v("MAIN_COMPILER"), d)
    
    Print #f, uc.GetUserCode("(" & sVarPre & "_General,1)", 0)   'USER CODE for application specific descriptions'
    Print #f, ""
    Print #f, Rtf.GenerateNote((r.v(sVarPre & "_Notes")))
    Print #f, ""
    Print #f, SECTION_PROJECT_INCLUDES
    Print #f, ""  'DAvE includes'
    Print #f, "#include """ & r.v("MAIN_HFile") & """"
    Print #f, ""
    Print #f, uc.GetUserCode("(" & sVarPre & "_General,2)", 0)
    Print #f, ""
    Print #f, ""
    Print #f, SECTION_MACROS
    Print #f, ""  'DAvE local macro definitions'
    Print #f, uc.GetUserCode("(" & sVarPre & "_General,3)", 0)
    Print #f, ""
    Print #f, ""
    Print #f, SECTION_DEFINES
    Print #f, ""  'DAvE local #define definitions'
    Print #f, uc.GetUserCode("(" & sVarPre & "_General,4)", 0)
    Print #f, ""
    Print #f, ""
    Print #f, SECTION_TYPEDEFS
    Print #f, ""  'DAvE type defintions'
    Print #f, uc.GetUserCode("(" & sVarPre & "_General,5)", 0)
    Print #f, ""
    Print #f, ""
    Print #f, SECTION_IMPORTED_GLOBAL_VARIABLES
    Print #f, ""  'DAvE external declarations of imported global variables'
    Print #f, uc.GetUserCode("(" & sVarPre & "_General,6)", 0)
    Print #f, ""
    Print #f, ""
    Print #f, SECTION_GLOBAL_VARIABLES
    Print #f, ""  'DAvE definitions of global variables'
    Print #f, uc.GetUserCode("(" & sVarPre & "_General,7)", 0)
    Print #f, ""
    Print #f, ""
    Print #f, SECTION_EXTERNAL_PROTOTYPES
    Print #f, ""  'DAvE external declarations of imported functions'
    Print #f, uc.GetUserCode("(" & sVarPre & "_General,8)", 0)
    Print #f, ""
    Print #f, ""
    Print #f, SECTION_LOCAL_PROTOTYPES
    Print #f, ""  'DAvE declarations of internal local functions'
    Print #f, uc.GetUserCode("(" & sVarPre & "_General,9)", 0)
    Print #f, ""
    Print #f, ""
    
    '------------------------------------------------------------------------------------------------
    ' CAPCOMx_vInit function
    '------------------------------------------------------------------------------------------------
    n = "Init"
    If (r.v(sVarPre & "_USE_" & n) = 1) Then
      Print #f, FormatFunctionHeader(r, func, sVarPre & "_NAME_" & n)
      Print #f, uc.GetUserCode("(" & n & ",1)", 0)     'USER CODE for application specific descriptions'
      Print #f, ""
      Print #f, FormatFunctionDeclaration(r, func, sVarPre & "_NAME_" & n)
      Print #f, "{"
      Print #f, uc.GetUserCode("(" & n & ",2)", 2)
      Print #f, ""
      
      '---------------------------------------------------------------------------------------------------
      Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "1, noSST);", "", "", "switch to page 1")
      Print #f, ""
      '------------------------------------------------------------------------------------------------
      ' Configuration of Timer Control Register :"
      '------------------------------------------------------------------------------------------------
      Print #f, FormatSectionHeader(2, 1, "Configuration of Timer Control Register")
     
      Print #f, ""
      v = 0
      v = v + r.sfr(sRegPre & "TCTR0L")
      Print #f, FormatCodeStatemente(2, sRegPre & "TCTR0L", "=", _
                FormatTextOutput(v, "H2"), _
               "load " & sVarPre & " timer control register 0 low")

      v = 0
      v = v + r.sfr(sRegPre & "TCTR0H")
      Print #f, FormatCodeStatemente(2, sRegPre & "TCTR0H", "=", _
                FormatTextOutput(v, "H2"), _
               "load " & sVarPre & " timer control register 0 high")

      Print #f, ""

      '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      iTmr = iTmr_12
      '------------------------------------------------------------------------------------------------
      ' Configuration of " & sVarPre & " Timer " & iTmr & ":
      '------------------------------------------------------------------------------------------------
      Print #f, FormatSectionHeader(2, 1, "Configuration of " & sVarPre & " Timer " & iTmr & ":")
      '-------------------------------------------------------------- TxyCON_TiM
      If (r.v(sRegPre & "TCTR0L_T" & iTmr & "PRE") = 1) Then
        d = "timer 12 Input clock selected  is " & _
        (2 ^ (r.v(sRegPre & "TCTR0L_T" & iTmr & "CLK")) * 256)
      Else
        d = "timer 12 Input clock selected  is " & _
        2 ^ (r.v(sRegPre & "TCTR0L_T" & iTmr & "CLK"))
      End If
      Print #f, FormatCommentsForInit(1, d)
      '-------------------------------------------------------------- TxyCON_TiR
      If (r.v(sRegPre & "TCTR0L_T" & iTmr & "PRE") = 1) Then
          d = "the additional prescaler for T12 is disabled."
      Else
          d = "the additional prescaler for T12 is enabled."
      End If
      Print #f, FormatCommentsForInit(1, d)
      If (r.v(sRegPre & "TCTR4L_T" & iTmr & "RS") = 0) Then
          d = "timer " & iTmr & " run bit is reset"
      Else
          d = "timer " & iTmr & " run bit is set"
      End If
      Print #f, FormatCommentsForInit(1, d)

      If (r.v(sRegPre & "TCTR2L_T" & iTmr & "SSC") = 1) Then
          d = "single shot mode is enabled"
      Else
          d = "single shot mode is disabled"
      End If
      Print #f, FormatCommentsForInit(1, d)

      If (r.v(sRegPre & "TCTR0L_CTM") = 0) Then
          d = "timer " & iTmr & " works in edge aligned mode"
      Else
          d = "timer " & iTmr & " works in center aligned mode"
      End If
      Print #f, FormatCommentsForInit(1, d)

      If (r.v(sRegPre & "IENL_ENT12PM") = 0) Then
          d = "interrupt on period match is disabled"
      Else
          d = "interrupt on period match is enabled"
      End If
      Print #f, FormatCommentsForInit(1, d)

      If (r.v(sRegPre & "IENL_ENT12OM") = 0) Then
          d = "interrupt on one match is disabled"
      Else
          d = "interrupt on one match is enabled"
      End If
      Print #f, FormatCommentsForInit(1, d)
      Print #f, ""
      '---------------------------------------------------------------------------------------------------

      v = 0
      v = v + r.sfr(sRegPre & "T12PRL")
      Print #f, FormatCodeStatemente(2, sRegPre & "T12PRL", "=", _
                FormatTextOutput(v, "H2"), _
               "load " & sVarPre & " T12 period register low")
      v = 0
      v = v + r.sfr(sRegPre & "T12PRH")
      Print #f, FormatCodeStatemente(2, sRegPre & "T12PRH", "=", _
                FormatTextOutput(v, "H2"), _
               "load " & sVarPre & " T12 period register lhigh")
      Print #f, ""

      '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      iTmr = iTmr_13
      '------------------------------------------------------------------------------------------------
      ' Configuration of " & sVarPre & " Timer " & iTmr & ":
      '------------------------------------------------------------------------------------------------
      Print #f, FormatSectionHeader(2, 1, "Configuration of " & sVarPre & " Timer " & iTmr & ":")

      '-------------------------------------------------------------- TxyCON_TiM
      If (r.v(sRegPre & "TCTR0H_T" & iTmr & "PRE") = 1) Then
         d = "Timer T13 Input clock selected is " & _
         (2 ^ (r.v(sRegPre & "TCTR0H_T" & iTmr & "CLK")) * 256)
      Else
         d = "Timer T13 Input clock selected is " & _
         2 ^ (r.v(sRegPre & "TCTR0H_T" & iTmr & "CLK"))
      End If
      Print #f, FormatCommentsForInit(1, d)
      '-------------------------------------------------------------- TxyCON_TiR
       If (r.v(sRegPre & "TCTR0H_T" & iTmr & "PRE") = 0) Then
           d = "The additional prescaler for T13 is disabled"
       Else
           d = "The additional prescaler for T13 is enabled"
       End If
       Print #f, FormatCommentsForInit(1, d)
       '-------------------------------------------------------------- TxyCON_TiR
      If (r.v(sRegPre & "TCTR4H_T" & iTmr & "RS") = 0) Then
          d = "timer " & iTmr & " run bit is reset"
      Else
          d = "timer " & iTmr & " run bit is set"
      End If
      Print #f, FormatCommentsForInit(1, d)
      
      If (r.v(sRegPre & "TCTR4H_T" & iTmr & "RS") = 0) Then
          If (r.v(sRegPre & "TCTR2L_T" & iTmr & "TEC") = 0) Then
              d = "trigger control is disabled"
          ElseIf (r.v(sRegPre & "TCTR2L_T" & iTmr & "TEC") = 1) Then
              d = "T13 is started on a T12 compare event on channel 0"
          ElseIf (r.v(sRegPre & "TCTR2L_T" & iTmr & "TEC") = 2) Then
              d = "T13 is started on a T12 compare event on channel 1"
          ElseIf (r.v(sRegPre & "TCTR2L_T" & iTmr & "TEC") = 3) Then
              d = "T13 is started on a T12 compare event on channel 2"
          ElseIf (r.v(sRegPre & "TCTR2L_T" & iTmr & "TEC") = 4) Then
              d = "T13 is started on any T12 compare event (ch. 0, 1, 2)"
          ElseIf (r.v(sRegPre & "TCTR2L_T" & iTmr & "TEC") = 5) Then
              d = "T13 is started upon a period match of T12"
          ElseIf (r.v(sRegPre & "TCTR2L_T" & iTmr & "TEC") = 6) Then
              d = "T13 is started upon a zero-match of T12"
          ElseIf (r.v(sRegPre & "TCTR2L_T" & iTmr & "TEC") = 7) Then
              d = "T13 is started on any hall state change"
          End If
          If (r.v(sRegPre & "TCTR2L_T" & iTmr & "TEC") > 0) Then
              If (r.v(sRegPre & "TCTR2L_T" & iTmr & "TED") = 1) Then
                  d = d & ", while T12 is counting up"
              ElseIf (r.v(sRegPre & "TCTR2L_T" & iTmr & "TED") = 2) Then
                  d = d & ", while T12 is counting down"
              ElseIf (r.v(sRegPre & "TCTR2L_T" & iTmr & "TED") = 3) Then
                  d = d & ", independent on the count direction of T12"
              End If
          End If
          Print #f, FormatCommentsForInit(1, d)
      End If
      
      If (r.v(sRegPre & "TCTR2L_T" & iTmr & "SSC") = 1) Then
          d = "single shot mode is enabled"
      Else
          d = "single shot mode is disabled"
      End If
      Print #f, FormatCommentsForInit(1, d)

      If (r.v(sRegPre & "IENH_ENT13PM") = 0) Then
          d = "interrupt on period match is disabled"
      Else
          d = "interrupt on period match is enabled"
      End If
      Print #f, FormatCommentsForInit(1, d)

      If (r.v(sRegPre & "IENH_ENT13CM") = 0) Then
          d = "interrupt on compare match is disabled"
      Else
          d = "interrupt on compare match is enabled"
      End If
      Print #f, FormatCommentsForInit(1, d)

      Print #f, ""
      v = 0
      v = v + r.sfr(sRegPre & "T13PRL")
      Print #f, FormatCodeStatemente(2, sRegPre & "T13PRL", "=", _
                FormatTextOutput(v, "H2"), _
               "load " & sVarPre & " T13 period register low")

      v = 0
      v = v + r.sfr(sRegPre & "T13PRH")
      Print #f, FormatCodeStatemente(2, sRegPre & "T13PRH", "=", _
                FormatTextOutput(v, "H2"), _
               "load " & sVarPre & " T13 period register high")

      Print #f, ""
      
      '------------------------------------------------------------------------------------------------
      Print #f, FormatSectionHeader(2, 1, "Configuration of Dead-Time Control Register for Timer T12")
      '------------------------------------------------------------------------------------------------
      Print #f, ""
      v = 0
      v = v + r.sfr(sRegPre & "T12DTCL")
      Print #f, FormatCodeStatemente(2, sRegPre & "T12DTCL", "=", _
                FormatTextOutput(v, "H2"), _
               "load " & sVarPre & " dead time control register low for timer T12")

      Print #f, ""
      v = 0
      v = v + r.sfr(sRegPre & "T12DTCH")
      Print #f, FormatCodeStatemente(2, sRegPre & "T12DTCH", "=", _
                FormatTextOutput(v, "H2"), _
               "load " & sVarPre & " dead time control register high for timer T12")
      
      Print #f, ""
      '---------------------------------------------------------------------------------------------------
      Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "0, noSST);", "", "", "switch to page 0")
      Print #f, ""
      
      '------------------------------------------------------------------------------------------------
      '~~~~~~~~~Configuration of  CC6xSR   Registers
      '------------------------------------------------------------------------------------------------
      For iChannel = 0 To 2
          If (iChannel < 2) Then
              sHelp = "L"
          Else
              sHelp = "H"
          End If
          '------------------------------------------------------------------------------------------------
          ' Configuration of " & sVarPre & " Channel " & iChannel & ":
          '------------------------------------------------------------------------------------------------
          Print #f, FormatSectionHeader(2, 1, "Configuration of " & sVarPre & " Channel " & iChannel & ":")

          If (r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & iChannel) = 0) Then
              d = "channel " & iChannel & " is disabled"
          ElseIf (r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & iChannel) = 1) Then
              d = "compare mode 1 is selected"
          ElseIf (r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & iChannel) = 2) Then
              d = "compare mode 2 is selected"
          ElseIf (r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & iChannel) = 3) Then
              d = "compare mode 3 is selected"
          ElseIf (r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & iChannel) = 4) Then
              d = "double register capture mode 1 is selected"
          ElseIf (r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & iChannel) = 5) Then
              d = "double register capture mode 2 is selected"
          ElseIf (r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & iChannel) = 6) Then
              d = "double register capture mode 3 is selected"
          ElseIf (r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & iChannel) = 7) Then
              d = "double register capture mode 4 is selected"
          ElseIf (r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & iChannel) = 8) Then
              d = "hall sensor mode is selected"
          ElseIf (r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & iChannel) = 9) Then
              d = "hysteresis like control mode with dead time generation is selected"
          ElseIf (r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & iChannel) = 10) Then
              d = "multi input capture mode 1 is selected"
          ElseIf (r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & iChannel) = 11) Then
              d = "multi input capture mode 2 is selected"
          ElseIf (r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & iChannel) = 12) Then
              d = "multi input capture mode 3 is selected"
          ElseIf (r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & iChannel) = 13) Then
              d = "multi input capture mode 4 is selected"
          ElseIf (r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & iChannel) = 14) Then
              d = "multi input capture mode 5 is selected"
          End If
          Print #f, FormatCommentsForInit(1, d)

          If (Not (r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & iChannel) = 0) And _
              (((GetPinFunction(r, "CC6" & iChannel & "_0(Output)") = 2) Or _
              (GetPinFunction(r, "CC6" & iChannel & "_1(Output)") = 2) Or _
              (GetPinFunction(r, "CC6" & iChannel & "_2(Output)") = 2))) And _
              Not (IsHallSensorModeEnable(r, vIndex))) Then

              If (r.v(sRegPre & "T12MODEN_CC6" & iChannel) = 0) Then
                  d = "T12 modulation for output CC6" & iChannel & " is disabled"
              Else
                  d = "T12 modulation for output CC6" & iChannel & " is enabled"
              End If
              Print #f, FormatCommentsForInit(1, d)
          End If
      
          If (((GetPinFunction(r, "CC6" & iChannel & "_0(Output)") = 2) Or _
              (GetPinFunction(r, "CC6" & iChannel & "_1(Output)") = 2) Or _
              (GetPinFunction(r, "CC6" & iChannel & "_2(Output)") = 2))) Then
              If (r.v(sRegPre & "T13MODEN_CC6" & iChannel) = 0) Then
                  d = "T13 modulation for output CC6" & iChannel & " is disabled"
              Else
                  d = "T13 modulation for output CC6" & iChannel & " is enabled"
              End If
              Print #f, FormatCommentsForInit(1, d)
          End If

          If (((GetPinFunction(r, "CC6" & iChannel & "_0(Output)") = 2) Or _
              (GetPinFunction(r, "CC6" & iChannel & "_1(Output)") = 2) Or _
              (GetPinFunction(r, "CC6" & iChannel & "_2(Output)") = 2)) And _
              r.v(sRegPre & "MODCTRL_MCMEN") = 1) Then
              
              If (r.v(sRegPre & "MCMPS_CC6" & iChannel) = 0) Then
                  d = "the output CC6" & iChannel & " is set to the passive state"
              Else
                  d = "the output CC6" & iChannel & " can deliver the PWM generated by T12 or T13"
              End If
              Print #f, FormatCommentsForInit(1, d)
          End If
      
          If (((GetPinFunction(r, "CC6" & iChannel & "_0(Output)") = 2) Or _
              (GetPinFunction(r, "CC6" & iChannel & "_1(Output)") = 2) Or _
              (GetPinFunction(r, "CC6" & iChannel & "_2(Output)") = 2))) Then
              If (r.v(sRegPre & "TRPEN_CC6" & iChannel) = 0) Then
                  d = "the trap functionality of the pin CC6" & iChannel & " is disabled"
              Else
                  d = "the trap functionality of the pin CC6" & iChannel & " is enabled"
              End If
              Print #f, FormatCommentsForInit(1, d)
          End If

          If (Not (r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & iChannel) = 0) And _
              (((GetPinFunction(r, "CC6" & iChannel & "_0(Output)") = 2) Or _
              (GetPinFunction(r, "CC6" & iChannel & "_1(Output)") = 2) Or _
              (GetPinFunction(r, "CC6" & iChannel & "_2(Output)") = 2))) And _
              Not (IsHallSensorModeEnable(r, vIndex))) Then

              If (r.v(sRegPre & "CMPSTATH_CC6" & iChannel & "PS") = 0) Then
                  d = "the compare output CC6" & iChannel & " drives passive level while CC6" & iChannel & "ST is '0'"
              Else
                  d = "the compare output CC6" & iChannel & " drives passive level while CC6" & iChannel & "ST is '1'"
              End If
              Print #f, FormatCommentsForInit(1, d)
          End If

          If (((GetPinFunction(r, "CC6" & iChannel & "_0(Output)") = 2) Or _
              (GetPinFunction(r, "CC6" & iChannel & "_1(Output)") = 2) Or _
              (GetPinFunction(r, "CC6" & iChannel & "_2(Output)") = 2))) Then
              If (r.v(sRegPre & "PSL_CC6" & iChannel) = 0) Then
                  d = "the passive level of the output CC6" & iChannel & " is '0'"
              Else
                  d = "the passive level of the output CC6" & iChannel & " is '1'"
              End If
              Print #f, FormatCommentsForInit(1, d)
          End If

          '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          'COUTx
          '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          If (Not (r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & iChannel) = 0) And _
              ((GetPinFunction(r, "COUT6" & iChannel & "_0") = 2) Or _
              (GetPinFunction(r, "COUT6" & iChannel & "_1") = 2)) And _
              Not (IsHallSensorModeEnable(r, vIndex))) Then

              If (r.v(sRegPre & "T12MODEN_COUT6" & iChannel) = 0) Then
                  d = "T12 modulation for output COUT6" & iChannel & " is disabled"
              Else
                  d = "T12 modulation for output COUT6" & iChannel & " is enabled"
              End If
              Print #f, FormatCommentsForInit(1, d)
          End If
          
          If ((GetPinFunction(r, "COUT6" & iChannel & "_0") = 2) Or _
              (GetPinFunction(r, "COUT6" & iChannel & "_1") = 2)) Then
              If (r.v(sRegPre & "T13MODEN_COUT6" & iChannel) = 0) Then
                  d = "T13 modulation for output COUT6" & iChannel & " is disabled"
              Else
                  d = "T13 modulation for output COUT6" & iChannel & " is enabled"
              End If
              Print #f, FormatCommentsForInit(1, d)
          End If

          If (((GetPinFunction(r, "COUT6" & iChannel & "_0") = 2) Or _
              (GetPinFunction(r, "COUT6" & iChannel & "_1") = 2)) And _
              r.v(sRegPre & "MODCTRL_MCMEN") = 1) Then
              
              If (r.v(sRegPre & "MCMPS_COUT6" & iChannel) = 0) Then
                  d = "the output COUT6" & iChannel & " is set to the passive state"
              Else
                  d = "the output COUT6" & iChannel & " can deliver the PWM generated by T12 or T13"
              End If
              Print #f, FormatCommentsForInit(1, d)
          End If
      
          If ((GetPinFunction(r, "COUT6" & iChannel & "_0") = 2) Or _
              (GetPinFunction(r, "COUT6" & iChannel & "_1") = 2)) Then
              If (r.v(sRegPre & "TRPEN_COUT6" & iChannel) = 0) Then
                  d = "the trap functionality of the pin COUT6" & iChannel & " is disabled"
              Else
                  d = "the trap functionality of the pin COUT6" & iChannel & " is enabled"
              End If
              Print #f, FormatCommentsForInit(1, d)
          End If

          If (Not (r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & iChannel) = 0) And _
              ((GetPinFunction(r, "COUT6" & iChannel & "_0") = 2) Or _
              (GetPinFunction(r, "COUT6" & iChannel & "_1") = 2)) And _
              Not (IsHallSensorModeEnable(r, vIndex))) Then

              If (r.v(sRegPre & "CMPSTATH_COUT6" & iChannel & "PS") = 0) Then
                  d = "the compare output COUT6" & iChannel & " drives passive level while CC6" & iChannel & "ST is '0'"
              Else
                  d = "the compare output COUT6" & iChannel & " drives passive level while CC6" & iChannel & "ST is '1'"
              End If
              Print #f, FormatCommentsForInit(1, d)
          End If

          If ((GetPinFunction(r, "COUT6" & iChannel & "_0") = 2) Or _
              (GetPinFunction(r, "COUT6" & iChannel & "_1") = 2)) Then
              If (r.v(sRegPre & "PSL_COUT6" & iChannel) = 0) Then
                  d = "the passive level of the output COUT6" & iChannel & " is '0'"
              Else
                  d = "the passive level of the output COUT6" & iChannel & " is '1'"
              End If
              Print #f, FormatCommentsForInit(1, d)
          End If
      
          If (Not (r.v(sRegPre & "T12MSEL" & sHelp & "_MSEL6" & iChannel) = 0)) Then
              If (r.v(sRegPre & "T12DTCH_DTE" & iChannel) = 0) Then
                  d = "dead time generation is disabled"
              Else
                  d = "dead time generation is enabled"
              End If
              Print #f, FormatCommentsForInit(1, d)
              Print #f, ""

              If (r.v(sRegPre & "IENL_ENCC6" & iChannel & "R") = 0) Then
                  d = "generation interrupt on flag ICC6" & iChannel & "R is disabled"
              Else
                  d = "generation interrupt on flag ICC6" & iChannel & "R is enabled"
              End If
              Print #f, FormatCommentsForInit(1, d)

              If (r.v(sRegPre & "IENL_ENCC6" & iChannel & "F") = 0) Then
                  d = "generation interrupt on flag ICC6" & iChannel & "F is disabled"
              Else
                  d = "generation interrupt on flag ICC6" & iChannel & "F is enabled"
              End If
              Print #f, FormatCommentsForInit(1, d)
              Print #f, ""
        
              v = 0
              v = v + r.sfr(sRegPre & "CC6" & iChannel & "SRL")
              Print #f, FormatCodeStatemente(2, sRegPre & "CC6" & iChannel & "SRL", "=", _
                        FormatTextOutput(v, "H2"), _
                       "load " & sVarPre & " capture/compare shadow register low for channel " & iChannel)
              v = 0
              v = v + r.sfr(sRegPre & "CC6" & iChannel & "SRH")
              Print #f, FormatCodeStatemente(2, sRegPre & "CC6" & iChannel & "SRH", "=", _
                        FormatTextOutput(v, "H2"), _
                       "load " & sVarPre & " capture/compare shadow register high for channel " & iChannel)
              Print #f, ""
          End If
          Print #f, ""
      Next iChannel
      
      iChannel = 3
      '------------------------------------------------------------------------------------------------
      ' Configuration of " & sVarPre & " Channel " & iChannel & ":
      '------------------------------------------------------------------------------------------------
      Print #f, FormatSectionHeader(2, 1, "Configuration of " & sVarPre & " Channel " & iChannel & ":")

      If ((GetPinFunction(r, "COUT63_0") = 2) Or (GetPinFunction(r, "COUT63_1") = 2)) Then
          If (r.v(sRegPre & "MODCTRH_ECT13O") = 0) Then
              d = "alternate output function COUT63 for the PWM signal generated by T13 is disabled"
          Else
              d = "alternate output function COUT63 for the PWM signal generated by T13 is enabled"
          End If
          Print #f, FormatCommentsForInit(1, d)
          
          If (r.v(sRegPre & "TRPCTRH_TRPEN13") = 0) Then
              d = "the trap functionality of the pin COUT6" & iChannel & " is disabled"
          Else
              d = "the trap functionality of the pin COUT6" & iChannel & " is enabled"
          End If
          Print #f, FormatCommentsForInit(1, d)

          If (r.v(sRegPre & "CMPSTATH_COUT6" & iChannel & "PS") = 0) Then
              d = "the compare output COUT6" & iChannel & " drives passive level while CC6" & iChannel & "ST is '0'"
          Else
              d = "the compare output COUT6" & iChannel & " drives passive level while CC6" & iChannel & "ST is '1'"
          End If
          Print #f, FormatCommentsForInit(1, d)

          If (r.v(sRegPre & "PSLR_PSL6" & iChannel) = 0) Then
              d = "the passive level of the output COUT6" & iChannel & " is '0'"
          Else
              d = "the passive level of the output COUT6" & iChannel & " is '1'"
          End If
          Print #f, FormatCommentsForInit(1, d)
      End If

      If (r.v(sRegPre & "CMPSTATH_T13IM") = 0) Then
          d = "T13 output is not inverted"
      Else
          d = "T13 output is inverted for further modulation"
      End If
      Print #f, FormatCommentsForInit(1, d)
      
      Print #f, ""
      Print #f, ""
      
      v = 0
      v = v + r.sfr(sRegPre & "CC6" & iChannel & "SRL")
      Print #f, FormatCodeStatemente(2, sRegPre & "CC6" & iChannel & "SRL", "=", _
                FormatTextOutput(v, "H2"), _
               "load " & sVarPre & " capture/compare shadow register low for channel " & iChannel)

      v = 0
      v = v + r.sfr(sRegPre & "CC6" & iChannel & "SRH")
      Print #f, FormatCodeStatemente(2, sRegPre & "CC6" & iChannel & "SRH", "=", _
                FormatTextOutput(v, "H2"), _
               "load " & sVarPre & " capture/compare shadow register high for channel " & iChannel)
      Print #f, ""
      Print #f, ""
      
      '------------------------------------------------------------------------------------------------
      ' Configuration of MCMOUTS:
      '------------------------------------------------------------------------------------------------
      Print #f, FormatSectionHeader(2, 1, "Configuration of Multi-Channel Mode Output Register")
      Print #f, ""
      v = 0
      v = v + r.sfr(sRegPre & "MCMOUTSL")
      Print #f, FormatCodeStatemente(2, sRegPre & "MCMOUTSL", "=", _
                FormatTextOutput(v, "H2"), _
               "load " & sVarPre & " multi channel mode output control register low")
      v = 0
      v = v + r.sfr(sRegPre & "MCMOUTSH")
      Print #f, FormatCodeStatemente(2, sRegPre & "MCMOUTSH", "=", _
                FormatTextOutput(v, "H2"), _
               "load " & sVarPre & " multi channel mode output control register high")
      Print #f, ""
      
'      Print #f, ""
' '-------------------------------------------------------------------------------------
'      Print #f, FormatSectionHeader(2, 1, "Timer Control Register")
' '-------------------------------------------------------------------------------------
'      Print #f, FormatCommentsForInit(1, " enable shadow transfer to T12 and T13")
'      Print #f, ""
'      v = 0
'      v = v + 2 ^ 6
'      Print #f, FormatCodeStatemente(2, sRegPre & "TCTR4L", "=", _
'                FormatTextOutput(v, "H2"), _
'               "load " & sVarPre & " timer control register 4 low")
'      Print #f, ""
'      v = 0
'      v = v + 2 ^ 6
'      Print #f, FormatCodeStatemente(2, sRegPre & "TCTR4H", "=", _
'                FormatTextOutput(v, "H2"), _
'               "load " & sVarPre & " timer control register 4 high")
'      Print #f, ""
      '------------------------------------------------------------------------------------------------
      Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "2, noSST);", "", "", "switch to page 2")
      Print #f, ""
      '------------------------------------------------------------------------------------------------
      '------------------------------------------------------------------------------------------------
      ' Configuration of " & sVarPre & " trap control:
      '------------------------------------------------------------------------------------------------
      Print #f, FormatSectionHeader(2, 1, "Configuration of Timer Control Register")

      Print #f, ""
      v = 0
      v = v + r.sfr(sRegPre & "TCTR2L")
      Print #f, FormatCodeStatemente(2, sRegPre & "TCTR2L", "=", _
                FormatTextOutput(v, "H2"), _
               "load " & sVarPre & " timer control register 2 low")
      v = 0
      v = v + r.sfr(sRegPre & "TCTR2H")
      Print #f, FormatCodeStatemente(2, sRegPre & "TCTR2H", "=", _
                FormatTextOutput(v, "H2"), _
               "load " & sVarPre & " timer control register 2 high")
      Print #f, ""

      '------------------------------------------------------------------------------------------------
      ' Configuration of " & sVarPre & " trap control:
      '------------------------------------------------------------------------------------------------
      Print #f, FormatSectionHeader(2, 1, "Configuration of " & sVarPre & " trap control:")

      If (r.v(sRegPre & "TRPCTRH_TRPPEN") = 0) Then
          d = "a trap can only be generated by SW by setting the bit TRPF"
      Else
          d = "a trap can be generated by SW or by rising edge on #CTRAP"
      End If
      Print #f, FormatCommentsForInit(1, d)
      
      If (r.v(sRegPre & "TRPCTRL_TRPM0") = 0 And r.v(sRegPre & "TRPCTRL_TRPM1") = 0) Then
          d = "the trap state is left when a zero-match of T12 (while counting up) is detected (synchronization to T12)"
      ElseIf (r.v(sRegPre & "TRPCTRL_TRPM0") = 1 And r.v(sRegPre & "TRPCTRL_TRPM1") = 0) Then
          d = "the trap state is left when a zero-match of T13 is detected (synchronization to T13)"
      ElseIf (r.v(sRegPre & "TRPCTRL_TRPM0") = 1 And r.v(sRegPre & "TRPCTRL_TRPM1") = 1) Then
          d = "the trap state is left immediately without any synchronization to T12 or T13"
      End If
      Print #f, FormatCommentsForInit(1, d)
      
      If (r.v(sRegPre & "TRPCTRL_TRPM2") = 0) Then
          d = "bit TRPF is automatically cleared by HW (according to TRPPEN, TRPM0 and TRPM1)"
      Else
          d = "the trap state can be left as soon as bit TRPF is reset by SW (according to TRPPEN, TRPM0 and TRPM1)"
      End If
      Print #f, FormatCommentsForInit(1, d)
      
      If (r.v(sRegPre & "IENH_ENTRPF") = 0) Then
          d = "trap interrupt is disabled"
      Else
          d = "trap interrupt is enabled"
      End If
      Print #f, FormatCommentsForInit(1, d)
      
      Print #f, ""
      v = 0
      v = v + r.sfr(sRegPre & "TRPCTRL")
      Print #f, FormatCodeStatemente(2, sRegPre & "TRPCTRL", "=", _
                FormatTextOutput(v, "H2"), _
               "load " & sVarPre & " trap control register low")
      v = 0
      v = v + r.sfr(sRegPre & "TRPCTRH")
      Print #f, FormatCodeStatemente(2, sRegPre & "TRPCTRH", "=", _
                FormatTextOutput(v, "H2"), _
               "load " & sVarPre & " trap control register high")
      Print #f, ""

      '------------------------------------------------------------------------------------------------
      ' Configuration of multi channel mode:
      '------------------------------------------------------------------------------------------------
      Print #f, FormatSectionHeader(2, 1, "Configuration of Multi Channel Mode:")

      If (r.v(sRegPre & "MODCTRL_MCMEN") = 0) Then
          d = "multi channel mode is disabled"
      Else
          d = "multi channel mode is enabled"
      End If
      Print #f, FormatCommentsForInit(1, d)

      If (r.v(sRegPre & "MODCTRL_MCMEN") = 1) Then
          Print #f, ""
          d = "switching selection:"
          Print #f, FormatCommentsForInit(1, d)

          If (r.v(sRegPre & "MCMCTR_SWSEL") = 0) Then
              d = "no trigger request will be generated"
          ElseIf (r.v(sRegPre & "MCMCTR_SWSEL") = 1) Then
              d = "transfer on correct hall event"
          ElseIf (r.v(sRegPre & "MCMCTR_SWSEL") = 2) Then
              d = "transfer on T13 period match (while counting up)"
          ElseIf (r.v(sRegPre & "MCMCTR_SWSEL") = 3) Then
              d = "transfer on T12 one match (while counting down)"
          ElseIf (r.v(sRegPre & "MCMCTR_SWSEL") = 4) Then
              d = "transfer on T12 channel 1 compare match"
          ElseIf (r.v(sRegPre & "MCMCTR_SWSEL") = 5) Then
              d = "transfer on T12 period match"
          End If
          Print #f, FormatCommentsForInit(1, d)

          Print #f, ""
          d = "switching synchronization:"
          Print #f, FormatCommentsForInit(1, d)

          If (r.v(sRegPre & "MCMCTR_SWSYN") = 0) Then
              d = "direct transfer"
          ElseIf (r.v(sRegPre & "MCMCTR_SWSYN") = 1) Then
              d = "synchronization on T13 zero-match"
          Else
              d = "synchronization on T12 zero-match (while counting up)"
                  End If
          Print #f, FormatCommentsForInit(1, d)
          Print #f, ""
          
          If (r.v(sRegPre & "MCMCTR_SWSEL") = 1 Or r.v(sRegPre & "MCMCTR_SWSEL") = 5) Then
              If (r.v(sRegPre & "IENH_ENCHE") = 0) Then
                  d = "interrupt on correct hall event is disabled"
              Else
                  d = "interrupt on correct hall event is enabled"
              End If
              Print #f, FormatCommentsForInit(1, d)
    
              If (r.v(sRegPre & "IENH_ENWHE") = 0) Then
                  d = "interrupt on wrong hall event is disabled"
              Else
                  d = "interrupt on wrong hall event is enabled"
              End If
              Print #f, FormatCommentsForInit(1, d)
         End If
         
         If (r.v(sRegPre & "MCMCTR_SWSEL") = 1) Then
             If (r.v(sRegPre & "IENH_ENIDLE") = 0) Then
                  d = "the automatic entering of the idle state is disabled"
              Else
                  d = "the automatic entering of the idle state is enabled"
              End If
              Print #f, FormatCommentsForInit(1, d)
          End If
      End If
      Print #f, ""
      v = 0
      v = v + r.sfr(sRegPre & "MODCTRL")
      Print #f, FormatCodeStatemente(2, sRegPre & "MODCTRL", "=", _
                FormatTextOutput(v, "H2"), _
               "load " & sVarPre & " modulation control register low")
      v = 0
      v = v + r.sfr(sRegPre & "MODCTRH")
      Print #f, FormatCodeStatemente(2, sRegPre & "MODCTRH", "=", _
                FormatTextOutput(v, "H2"), _
               "load " & sVarPre & " modulation control register high")
      Print #f, ""

      '------------------------------------------------------------------------------------------------
      ' Configuration of Multi_Channel Mode Control Register
      '------------------------------------------------------------------------------------------------
      Print #f, FormatSectionHeader(2, 1, "Configuration of Multi_Channel Mode Control Register")
      Print #f, ""
      v = 0
      v = v + r.sfr(sRegPre & "MCMCTR")
      Print #f, FormatCodeStatemente(2, sRegPre & "MCMCTR", "=", _
                FormatTextOutput(v, "H2"), _
               "load " & sVarPre & " multi channel mode control register ")
      Print #f, ""
      '------------------------------------------------------------------------------------------------
      ' Configuration of T12 Capture/Compare Mode Select Register
      '------------------------------------------------------------------------------------------------
      Print #f, FormatSectionHeader(2, 1, "Configuration of T12 Capture/Compare Mode Select Register")
      Print #f, ""
      v = 0
      v = v + r.sfr(sRegPre & "T12MSELL")
      Print #f, FormatCodeStatemente(2, sRegPre & "T12MSELL", "=", _
                FormatTextOutput(v, "H2"), _
               "load " & sVarPre & " T12 campture/compare mode select register low")

      Print #f, ""
      v = 0
      v = v + r.sfr(sRegPre & "T12MSELH")
      Print #f, FormatCodeStatemente(2, sRegPre & "T12MSELH", "=", _
                FormatTextOutput(v, "H2"), _
               "load " & sVarPre & " T12 campture/compare mode select register high")

      '------------------------------------------------------------------------------------------------
      ' Configuration of Passive State Level Register
      '------------------------------------------------------------------------------------------------
      Print #f, FormatSectionHeader(2, 1, "Configuration of Passive State Level Register")
      Print #f, ""
      v = 0
      v = v + r.sfr(sRegPre & "PSLR")
      Print #f, FormatCodeStatemente(2, sRegPre & "PSLR", "=", _
                FormatTextOutput(v, "H2"), _
               "load " & sVarPre & " passive state level register low")
      Print #f, ""

      '------------------------------------------------------------------------------------------------
      ' Configuration of " & sVarPre & " interrupt control:
      '------------------------------------------------------------------------------------------------
      Print #f, FormatSectionHeader(2, 1, "Configuration of " & sVarPre & " interrupt control:")

      i = r.v(sRegPre & "INPL_INPCC60")
      d = "for channel 0 interrupts is node I" & i & " selected"
      Print #f, FormatCommentsForInit(1, d)

      i = r.v(sRegPre & "INPL_INPCC61")
      d = "for channel 1 interrupts is node I" & i & " selected"
      Print #f, FormatCommentsForInit(1, d)

      i = r.v(sRegPre & "INPL_INPCC62")
      d = "for channel 2 interrupts is node I" & i & " selected"
      Print #f, FormatCommentsForInit(1, d)

      i = r.v(sRegPre & "INPL_INPCHE")
      d = "for correct hall event interrupt is node I" & i & " selected"
      Print #f, FormatCommentsForInit(1, d)

      i = r.v(sRegPre & "INPH_INPERR")
      d = "for error interrupts is node I" & i & " selected"
      Print #f, FormatCommentsForInit(1, d)

      i = r.v(sRegPre & "INPH_INPT12")
      d = "for T12 interrupts is node I" & i & " selected"
      Print #f, FormatCommentsForInit(1, d)

      i = r.v(sRegPre & "INPH_INPT13")
      d = "for T13 interrupts is node I" & i & " selected"
      Print #f, FormatCommentsForInit(1, d)

      Print #f, ""

      '-------------------------------------------------
      v = 0
      v = v + r.sfr(sRegPre & "INPL")
      Print #f, FormatCodeStatemente(2, sRegPre & "INPL", "=", _
                FormatTextOutput(v, "H2"), _
               "load " & sVarPre & " capture/compare interrupt node pointer register low")

      v = 0
      v = v + r.sfr(sRegPre & "INPH")
      Print #f, FormatCodeStatemente(2, sRegPre & "INPH", "=", _
                FormatTextOutput(v, "H2"), _
               "load " & sVarPre & " capture/compare interrupt node pointer register high")

      Print #f, ""
      
      '-------------------------------------------------
      v = 0
      v = v + r.sfr(sRegPre & "IENL")
      Print #f, FormatCodeStatemente(2, sRegPre & "IENL", "=", _
                FormatTextOutput(v, "H2"), _
               "load " & sVarPre & " capture/compare interrupt enable register low")
      
      v = 0
      v = v + r.sfr(sRegPre & "IENH")
      Print #f, FormatCodeStatemente(2, sRegPre & "IENH", "=", _
                FormatTextOutput(v, "H2"), _
               "load " & sVarPre & " capture/compare interrupt enable register high")
      
      Print #f, ""
      
      '------------------------------------------------------------------------------------------------
      Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, noSST);", "", "", "switch to page 3")
      Print #f, ""
      '------------------------------------------------------------------------------------------------
      '------------------------------------------------------------------------------------------------
      ' Configuration of Compare State Register
      '------------------------------------------------------------------------------------------------
      Print #f, FormatSectionHeader(2, 1, "Configuration of Compare State Register")
      Print #f, ""
      v = 0
      v = v + r.sfr(sRegPre & "CMPSTATH")
      Print #f, FormatCodeStatemente(2, sRegPre & "CMPSTATH", "=", _
                FormatTextOutput(v, "H2"), _
               "load " & sVarPre & " compare status register high")
      
      Print #f, ""

      '------------------------------------------------------------------------------------------------
      ' Configuration of " & sVarPre & " module input signals:
      '------------------------------------------------------------------------------------------------
      Print #f, FormatSectionHeader(2, 1, "Configuration of " & sVarPre & " module input signals:")
        If ((r.v("CCU6_USE_CC60_PIN")) = 0) Then
                        d = "signal CC60 is not used"
                ElseIf ((r.v("CCU6_USE_CC60_PIN")) = 1) Then
                        d = "signal CC60_0 is used as input"
                ElseIf ((r.v("CCU6_USE_CC60_PIN")) = 2) Then
                        d = "signal CC60_0 is used as output"
                ElseIf ((r.v("CCU6_USE_CC60_PIN")) = 3) Then
                        d = "signal CC60_3 is used as input"
                ElseIf ((r.v("CCU6_USE_CC60_PIN")) = 4) Then
                        d = "signal CC60_1 is used as output"
         End If
         Print #f, FormatCommentsForInit(1, d)
  
         If ((r.v("CCU6_USE_CC61_PIN")) = 0) Then
                        d = "signal CC61 is not used"
                ElseIf ((r.v("CCU6_USE_CC61_PIN")) = 1) Then
                        d = "signal CC61_0 is used as input"
                ElseIf ((r.v("CCU6_USE_CC61_PIN")) = 2) Then
                        d = "signal CC61_1 is used as input"
                ElseIf ((r.v("CCU6_USE_CC61_PIN")) = 3) Then
                        d = "signal CC61_0 is used as output"
                ElseIf ((r.v("CCU6_USE_CC61_PIN")) = 4) Then
                        d = "signal CC61_1 is used as output"
                ElseIf ((r.v("CCU6_USE_CC61_PIN")) = 5) Then
                        d = "signal CC61_2 is used as input"
                ElseIf ((r.v("CCU6_USE_CC61_PIN")) = 6) Then
                        d = "signal CC61_2 is used as output"
                ElseIf ((r.v("CCU6_USE_CC61_PIN")) = 7) Then
                        d = "signal CC61_3 is used as input"
          End If
          Print #f, FormatCommentsForInit(1, d)

         If ((r.v("CCU6_USE_CC62_PIN")) = 0) Then
                        d = "signal CC62 is not used"
                ElseIf ((r.v("CCU6_USE_CC62_PIN")) = 1) Then
                        d = "signal CC62_0 is used as input"
                ElseIf ((r.v("CCU6_USE_CC62_PIN")) = 2) Then
                        d = "signal CC62_1 is used as input"
                ElseIf ((r.v("CCU6_USE_CC62_PIN")) = 3) Then
                        d = "signal CC62_0 is used as output"
                ElseIf ((r.v("CCU6_USE_CC62_PIN")) = 4) Then
                        d = "signal CC62_1 is used as output"
                ElseIf ((r.v("CCU6_USE_CC62_PIN")) = 7) Then
                        d = "signal CC62_3 is used as input"
         End If
         Print #f, FormatCommentsForInit(1, d)

        If ((r.v("CCU6_USE_#CTRAP_PIN")) = 0) Then
                    d = "signal #CTRAP is not used"
            ElseIf ((r.v("CCU6_USE_#CTRAP_PIN")) = 1) Then
                    d = "signal CTRAP#_0 is used"
            ElseIf ((r.v("CCU6_USE_#CTRAP_PIN")) = 2) Then
                    d = "signal CTRAP#_1 is used"
            ElseIf ((r.v("CCU6_USE_#CTRAP_PIN")) = 3) Then
                    d = "signal CTRAP#_2 is used"
         End If
         Print #f, FormatCommentsForInit(1, d)
      
      Print #f, ""
      v = 0
      v = v + r.sfr(sRegPre & "PISEL0L")
      Print #f, FormatCodeStatemente(2, sRegPre & "PISEL0L", "=", _
                FormatTextOutput(v, "H2"), _
               "load " & sVarPre & " Port Input Select Register 0 Low")
      Print #f, ""

         If ((r.v("CCU6_USE_CCPOS0_PIN")) = 0) Then
                 d = "signal CCPOS0 is not used"
            ElseIf ((r.v("CCU6_USE_CCPOS0_PIN")) = 1) Then
                 d = "signal CCPOS0_0 is used"
            ElseIf ((r.v("CCU6_USE_CCPOS0_PIN")) = 2) Then
                 d = "signal CCPOS0_1 is used"
            ElseIf ((r.v("CCU6_USE_CCPOS0_PIN")) = 3) Then
                 d = "signal CCPOS0_2 is used"
         End If
         Print #f, FormatCommentsForInit(1, d)
         
         If ((r.v("CCU6_USE_CCPOS1_PIN")) = 0) Then
                 d = "signal CCPOS1 is not used"
            ElseIf ((r.v("CCU6_USE_CCPOS1_PIN")) = 1) Then
                 d = "signal CCPOS1_0 is used"
            ElseIf ((r.v("CCU6_USE_CCPOS1_PIN")) = 2) Then
                 d = "signal CCPOS1_1 is used"
            ElseIf ((r.v("CCU6_USE_CCPOS1_PIN")) = 3) Then
                 d = "signal CCPOS1_2 is used"
          End If
          Print #f, FormatCommentsForInit(1, d)
        
         If ((r.v("CCU6_USE_CCPOS2_PIN")) = 0) Then
                 d = "signal CCPOS2 is not used"
            ElseIf ((r.v("CCU6_USE_CCPOS2_PIN")) = 1) Then
                 d = "signal CCPOS2_0 is used"
            ElseIf ((r.v("CCU6_USE_CCPOS0_PIN")) = 2) Then
                 d = "signal CCPOS2_1 is used"
            ElseIf ((r.v("CCU6_USE_CCPOS2_PIN")) = 3) Then
                 d = "signal CCPOS2_2 is used"
          End If
          Print #f, FormatCommentsForInit(1, d)
         
        If ((r.v("CCU6_USE_T12HR_PIN")) = 0) Then
                    d = "signal T12HR is not used"
            ElseIf ((r.v("CCU6_USE_T12HR_PIN")) = 1) Then
                    d = "signal T12HR_0 is used"
            ElseIf ((r.v("CCU6_USE_T12HR_PIN")) = 2) Then
                    d = "signal T12HR_1 is used"
            ElseIf ((r.v("CCU6_USE_T12HR_PIN")) = 3) Then
                    d = "signal T12HR_2 is used"
        End If
        Print #f, FormatCommentsForInit(1, d)
        Print #f, ""
        v = 0
        v = v + r.sfr(sRegPre & "PISEL0H")
        Print #f, FormatCodeStatemente(2, sRegPre & "PISEL0H", "=", _
                  FormatTextOutput(v, "H2"), _
                 "load " & sVarPre & " Port Input Select Register 0 High")
        Print #f, ""
      
        If ((r.v("CCU6_USE_T13HR_PIN")) = 0) Then
                    d = "signal T13HR is not used"
            ElseIf ((r.v("CCU6_USE_T13HR_PIN")) = 1) Then
                    d = "signal T13HR_0 is used"
            ElseIf ((r.v("CCU6_USE_T13HR_PIN")) = 2) Then
                    d = "signal T13HR_1 is used"
            ElseIf ((r.v("CCU6_USE_T13HR_PIN")) = 3) Then
                    d = "signal T13HR_2 is used"
        End If
            Print #f, FormatCommentsForInit(1, d)
      Print #f, ""
      v = 0
      v = v + r.sfr(sRegPre & "PISEL2")
      Print #f, FormatCodeStatemente(2, sRegPre & "PISEL2", "=", _
                FormatTextOutput(v, "H2"), _
               "load " & sVarPre & " Port Input Select Register 2")
      Print #f, ""

      '----------------------------------------------------------------------------
      'Alternate pin Functions.............
      '----------------------------------------------------------------------------
    lP0MaskALTSEL0 = 0
    lP3MaskALTSEL0 = 0
    lP0MaskALTSEL1 = 0
    lP3MaskALTSEL1 = 0
    lP0MaskDIR = 0
    lP3MaskDIR = 0

    bP3Selected = False
    bP0Selected = False
    bP3_1Selected = False

' --- Port 0
    If (r.v(sVarPre & "_USE_CC61_PIN") = 4) Then
        sPinName = "CC61_1"
        sPin = "P0.0"
        Print #f, FormatComments(2, 1, "", "", "Pin " & sPin & " is used as " & sPinName & " Output "); ""
        lP0MaskALTSEL0 = lP0MaskALTSEL0 + 2 ^ 0
        lP0MaskALTSEL1 = lP0MaskALTSEL1 + 2 ^ 0
        lP0MaskDIR = lP0MaskDIR + 2 ^ 0
        bP0Selected = True
    End If
       
    If (r.v(sVarPre & "_USE_COUT61_PIN") = 2) Then
        sPinName = "COUT61_1"
        sPin = "P0.1"
        Print #f, FormatComments(2, 1, "", "", "Pin " & sPin & " is used as " & sPinName & " Output "); ""
        lP0MaskALTSEL0 = lP0MaskALTSEL0 + 2 ^ 1
        lP0MaskALTSEL1 = lP0MaskALTSEL1 + 2 ^ 1
        lP0MaskDIR = lP0MaskDIR + 2 ^ 1
        bP0Selected = True
    End If
    
    If (r.v(sVarPre & "_USE_COUT63_PIN") = 2) Then
        sPinName = "COUT63_1"
        sPin = "P0.3"
        Print #f, FormatComments(2, 1, "", "", "Pin " & sPin & " is used as " & sPinName & " Output "); ""
        lP0MaskALTSEL0 = lP0MaskALTSEL0 + 2 ^ 3
        lP0MaskALTSEL1 = lP0MaskALTSEL1 + 2 ^ 3
        lP0MaskDIR = lP0MaskDIR + 2 ^ 3
        bP0Selected = True
    End If

    If (r.v(sVarPre & "_USE_CC62_PIN") = 4) Then
        sPinName = "CC62_1"
        sPin = "P0.4"
        Print #f, FormatComments(2, 1, "", "", "Pin " & sPin & " is used as " & sPinName & " Output "); ""
        lP0MaskALTSEL0 = lP0MaskALTSEL0 + 2 ^ 4
        lP0MaskALTSEL1 = lP0MaskALTSEL1 + 2 ^ 4
        lP0MaskDIR = lP0MaskDIR + 2 ^ 4
        bP0Selected = True
    End If

    If (r.v(sVarPre & "_USE_COUT62_PIN") = 2) Then
        sPinName = "COUT62_1"
        sPin = "P0.5"
        Print #f, FormatComments(2, 1, "", "", "Pin " & sPin & " is used as " & sPinName & " Output "); ""
        lP0MaskALTSEL0 = lP0MaskALTSEL0 + 2 ^ 5
        lP0MaskALTSEL1 = lP0MaskALTSEL1 + 2 ^ 5
        lP0MaskDIR = lP0MaskDIR + 2 ^ 5
        bP0Selected = True
    End If
    
    If bP0Selected Then
        Print #f, ""
        Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & PORT_PAGE_NAME & "2, noSST);", "", "", "switch to page 2")
        Print #f, "  P0_ALTSEL0      &= ~(ubyte) " & FormatTextOutput(lP0MaskALTSEL0, "H2") & ";    //  set AltSel0 "
        Print #f, "  P0_ALTSEL1      |= " & FormatTextOutput(lP0MaskALTSEL1, "H2") & ";    //  set AltSel1"
        Print #f, ""
        Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & PORT_PAGE_NAME & "0, noSST);", "", "", "switch to page 0")
        Print #f, "  P0_DIR          |= " & FormatTextOutput(lP0MaskDIR, "H2") & ";    //  set Direction as Output"
    End If
    Print #f, ""

' --- Port 3
    If (r.v(sVarPre & "_USE_CC60_PIN") = 2) Then
        sPinName = "CC60_0"
        sPin = "P3.0"
        Print #f, FormatComments(2, 1, "", "", "Pin " & sPin & " is used as " & sPinName & " Output "); ""
        lP3MaskALTSEL0 = lP3MaskALTSEL0 + 2 ^ 0
        lP3MaskALTSEL1 = lP3MaskALTSEL1 + 2 ^ 0
        lP3MaskDIR = lP3MaskDIR + 2 ^ 0
        bP3Selected = True
    End If
       
    If (r.v(sVarPre & "_USE_COUT60_PIN") = 1) Then
        sPinName = "COUT60_0"
        sPin = "P3.1"
        Print #f, FormatComments(2, 1, "", "", "Pin " & sPin & " is used as " & sPinName & " Output "); ""
        lP3MaskALTSEL0 = lP3MaskALTSEL0 + 2 ^ 1
        lP3MaskALTSEL1 = lP3MaskALTSEL1 + 2 ^ 1
        lP3MaskDIR = lP3MaskDIR + 2 ^ 1
        bP3Selected = True
    End If
       
    If (r.v(sVarPre & "_USE_CC61_PIN") = 3) Then
        sPinName = "CC61_0"
        sPin = "P3.2"
        Print #f, FormatComments(2, 1, "", "", "Pin " & sPin & " is used as " & sPinName & " Output "); ""
        lP3MaskALTSEL0 = lP3MaskALTSEL0 + 2 ^ 2
        lP3MaskALTSEL1 = lP3MaskALTSEL1 + 2 ^ 2
        lP3MaskDIR = lP3MaskDIR + 2 ^ 2
        bP3Selected = True
    End If
     
    If (r.v(sVarPre & "_USE_CC61_PIN") = 6) Then
        sPinName = "CC61_2"
        sPin = "P3.1"
        Print #f, FormatComments(2, 1, "", "", "Pin " & sPin & " is used as " & sPinName & " Output "); ""
'        lP3MaskALTSEL0 = lP3MaskALTSEL0 + 2 ^ 1
'        lP3MaskALTSEL1 = lP3MaskALTSEL1 + 2 ^ 1
        lP3MaskDIR = lP3MaskDIR + 2 ^ 1
        bP3_1Selected = True
    End If
     
     
    If (r.v(sVarPre & "_USE_COUT61_PIN") = 1) Then
        sPinName = "COUT61_0"
        sPin = "P3.3"
        Print #f, FormatComments(2, 1, "", "", "Pin " & sPin & " is used as " & sPinName & " Output "); ""
        lP3MaskALTSEL0 = lP3MaskALTSEL0 + 2 ^ 3
        lP3MaskALTSEL1 = lP3MaskALTSEL1 + 2 ^ 3
        lP3MaskDIR = lP3MaskDIR + 2 ^ 3
        bP3Selected = True
    End If

    If (r.v(sVarPre & "_USE_CC62_PIN") = 3) Then
        sPinName = "CC62_0"
        sPin = "P3.4"
        Print #f, FormatComments(2, 1, "", "", "Pin " & sPin & " is used as " & sPinName & " Output "); ""
        lP3MaskALTSEL0 = lP3MaskALTSEL0 + 2 ^ 4
        lP3MaskALTSEL1 = lP3MaskALTSEL1 + 2 ^ 4
        lP3MaskDIR = lP3MaskDIR + 2 ^ 4
        bP3Selected = True
    End If

    If (r.v(sVarPre & "_USE_COUT62_PIN") = 1) Then
        sPinName = "COUT62_0"
        sPin = "P3.5"
        Print #f, FormatComments(2, 1, "", "", "Pin " & sPin & " is used as " & sPinName & " Output "); ""
        lP3MaskALTSEL0 = lP3MaskALTSEL0 + 2 ^ 5
        lP3MaskALTSEL1 = lP3MaskALTSEL1 + 2 ^ 5
        lP3MaskDIR = lP3MaskDIR + 2 ^ 5
        bP3Selected = True
    End If

    If (r.v(sVarPre & "_USE_COUT63_PIN") = 1) Then
        sPinName = "COUT63_0"
        sPin = "P3.7"
        Print #f, FormatComments(2, 1, "", "", "Pin " & sPin & " is used as " & sPinName & " Output "); ""
        lP3MaskALTSEL0 = lP3MaskALTSEL0 + 2 ^ 7
        lP3MaskALTSEL1 = lP3MaskALTSEL1 + 2 ^ 7
        lP3MaskDIR = lP3MaskDIR + 2 ^ 7
        bP3Selected = True
     End If
    
     If ((bP3Selected = True) Or (bP3_1Selected = True)) Then
        Print #f, ""
        Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & PORT_PAGE_NAME & "2, noSST);", "", "", "switch to page 2")
        Print #f, ""
        If ((bP3Selected = True) And (bP3_1Selected = True)) Then

''P3_ALTSEL0      = (P3_ALTSEL0 | 0x01) & ~0x02;    //  set AltSel0
''P3_ALTSEL1      = (P3_ALTSEL0 ~(ubyte)0x01) | 0x02;    //  set AltSel1
'
''            Print #f, "  P3_ALTSEL0      = (P3_ALTSEL0 | " & FormatTextOutput(lP3MaskALTSEL0, "H2"); ")" & " & ~0x02;    //  set AltSel0 "
''            Print #f, "  P3_ALTSEL1      = (P3_ALTSEL0 ~(ubyte)" & FormatTextOutput(lP3MaskALTSEL1, "H2"); ")" & " | 0x02;    //  set AltSel1"
            
            Print #f, "  P3_ALTSEL0      |= " & FormatTextOutput(lP3MaskALTSEL0, "H2") & ";    //  set AltSel0 "
            Print #f, "  P3_ALTSEL1      &= ~(ubyte)" & FormatTextOutput(lP3MaskALTSEL1, "H2") & ";    //  set AltSel1"
            
            Print #f, ""
            lP3MaskALTSEL0 = 2 ^ 1
            lP3MaskALTSEL1 = 2 ^ 1
            
            Print #f, "  P3_ALTSEL0      &= ~(ubyte)" & FormatTextOutput(lP3MaskALTSEL0, "H2") & ";    //  set AltSel0 "
            Print #f, "  P3_ALTSEL1      |= " & FormatTextOutput(lP3MaskALTSEL1, "H2") & ";    //  set AltSel1"
        
        ElseIf ((bP3Selected = True) And (bP3_1Selected = False)) Then
            
            Print #f, "  P3_ALTSEL0      |= " & FormatTextOutput(lP3MaskALTSEL0, "H2") & ";    //  set AltSel0 "
            Print #f, "  P3_ALTSEL1      &= ~(ubyte)" & FormatTextOutput(lP3MaskALTSEL1, "H2") & ";    //  set AltSel1"
        
        ElseIf ((bP3Selected = False) And (bP3_1Selected = True)) Then
       
            lP3MaskALTSEL0 = lP3MaskALTSEL0 + 2 ^ 1
            lP3MaskALTSEL1 = lP3MaskALTSEL1 + 2 ^ 1
            
            Print #f, "  P3_ALTSEL0      &= ~(ubyte)" & FormatTextOutput(lP3MaskALTSEL0, "H2") & ";    //  set AltSel0 "
            Print #f, "  P3_ALTSEL1      |= " & FormatTextOutput(lP3MaskALTSEL1, "H2") & ";    //  set AltSel1"
        End If
        Print #f, ""
        Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & PORT_PAGE_NAME & "0, noSST);", "", "", "switch to page 0")
        Print #f, "  P3_DIR          |= " & FormatTextOutput(lP3MaskDIR, "H2") & ";    //  set Direction as Output"
     End If
     Print #f, ""


' --- Port 4
'-------------

    lP0MaskALTSEL0 = 0
    lP3MaskALTSEL0 = 0
    lP0MaskALTSEL1 = 0
    lP3MaskALTSEL1 = 0
    lP0MaskDIR = 0
    lP3MaskDIR = 0

    bP3Selected = False
    bP0Selected = False
    bP3_1Selected = False

    If (r.v(sVarPre & "_USE_CC60_PIN") = 4) Then
        sPinName = "CC60_1"
        sPin = "P4.0"
        Print #f, FormatComments(2, 1, "", "", "Pin " & sPin & " is used as " & sPinName & " Output "); ""
        lP3MaskALTSEL0 = lP3MaskALTSEL0 + 2 ^ 0
        lP3MaskALTSEL1 = lP3MaskALTSEL1 + 2 ^ 0
        lP3MaskDIR = lP3MaskDIR + 2 ^ 0
        bP3Selected = True
    End If
       
    If (r.v(sVarPre & "_USE_COUT60_PIN") = 2) Then
        sPinName = "COUT60_1"
        sPin = "P4.1"
        Print #f, FormatComments(2, 1, "", "", "Pin " & sPin & " is used as " & sPinName & " Output "); ""
        lP3MaskALTSEL0 = lP3MaskALTSEL0 + 2 ^ 1
        lP3MaskALTSEL1 = lP3MaskALTSEL1 + 2 ^ 1
        lP3MaskDIR = lP3MaskDIR + 2 ^ 1
        bP3Selected = True
    End If
       
    If (r.v(sVarPre & "_USE_COUT63_PIN") = 3) Then
        sPinName = "COUT63_2"
        sPin = "P4.3"
        Print #f, FormatComments(2, 1, "", "", "Pin " & sPin & " is used as " & sPinName & " Output "); ""
'        lP3MaskALTSEL0 = lP3MaskALTSEL0 + 2 ^ 1
'        lP3MaskALTSEL1 = lP3MaskALTSEL1 + 2 ^ 1
        lP3MaskDIR = lP3MaskDIR + 2 ^ 3
        bP3_1Selected = True
    End If
       
     If ((bP3Selected = True) Or (bP3_1Selected = True)) Then
        Print #f, ""
        Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & PORT_PAGE_NAME & "2, noSST);", "", "", "switch to page 2")
        Print #f, ""
        If ((bP3Selected = True) And (bP3_1Selected = True)) Then

            Print #f, "  P4_ALTSEL0      |= " & FormatTextOutput(lP3MaskALTSEL0, "H2") & ";    //  set AltSel0 "
            Print #f, "  P4_ALTSEL1      &= ~(ubyte)" & FormatTextOutput(lP3MaskALTSEL1, "H2") & ";    //  set AltSel1"
            
            Print #f, ""
            lP3MaskALTSEL0 = 2 ^ 3
            lP3MaskALTSEL1 = 2 ^ 3
            
            Print #f, "  P4_ALTSEL0      &= ~(ubyte)" & FormatTextOutput(lP3MaskALTSEL0, "H2") & ";    //  set AltSel0 "
            Print #f, "  P4_ALTSEL1      |= " & FormatTextOutput(lP3MaskALTSEL1, "H2") & ";    //  set AltSel1"
        
        ElseIf ((bP3Selected = True) And (bP3_1Selected = False)) Then
            
            Print #f, "  P4_ALTSEL0      |= " & FormatTextOutput(lP3MaskALTSEL0, "H2") & ";    //  set AltSel0 "
            Print #f, "  P4_ALTSEL1      &= ~(ubyte)" & FormatTextOutput(lP3MaskALTSEL1, "H2") & ";    //  set AltSel1"
        
        ElseIf ((bP3Selected = False) And (bP3_1Selected = True)) Then
       
            lP3MaskALTSEL0 = 2 ^ 3
            lP3MaskALTSEL1 = 2 ^ 3
            
            Print #f, "  P4_ALTSEL0      &= ~(ubyte)" & FormatTextOutput(lP3MaskALTSEL0, "H2") & ";    //  set AltSel0 "
            Print #f, "  P4_ALTSEL1      |= " & FormatTextOutput(lP3MaskALTSEL1, "H2") & ";    //  set AltSel1"
        End If
        Print #f, ""
        Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & PORT_PAGE_NAME & "0, noSST);", "", "", "switch to page 0")
        Print #f, "  P4_DIR          |= " & FormatTextOutput(lP3MaskDIR, "H2") & ";    //  set Direction as Output"
     End If
     Print #f, ""

 '-------------------------------------------------------------------------------------
      '------------------------------------------------------------------------------------------------
      ' Configuration of the used " & sVarPre & " Channels Interrupts:
      '------------------------------------------------------------------------------------------------
      Print #f, FormatSectionHeader(2, 1, "Configuration of the used " & sVarPre & " Channels Interrupts:")
      
      For i = 0 To 3
          If (r.v(CORE_PREFIX & "IEN1_ECCIP" & i) = 0) Then
              d = "capture/compare interrupt node " & i & " is disabled"
          Else
              d = "capture/compare interrupt node " & i & " is enabled"
          End If
          Print #f, FormatCommentsForInit(1, d)
      Next i

    If (r.v("CCU6_USE_NodeI0") = 1 Or r.v("CCU6_USE_NodeI1") = 1 Or r.v("CCU6_USE_NodeI2") = 1 Or r.v("CCU6_USE_NodeI3") = 1) Then
      Print #f, ""
      v = 0
      v = v + r.sfr(CORE_PREFIX & "IEN1")
      Print #f, FormatComments(2, 1, "", "", "CCU6 Node Interrupt enable bit is set in SHINT_vInit() function")
'      If ((r.v("MAIN_CPU_TYPE") <> "XC886CLM") Or (r.v("MAIN_CPU_TYPE") <> "XC886C")) Then
'              Print #f, FormatCodeStatemente(2, CORE_PREFIX & "IEN1", "|=", _
'                FormatTextOutput(v, "H2"), _
'               "load interrupt enable register 2")
'      Else
'            Print #f, FormatComments(2, 1, "", "", "CCU6 Node Interrupt enable bit is set in SHINT_vInit() function")
'      End If
'
      Print #f, ""
    End If
      
 '-------------------------------------------------------------------------------------
      Print #f, ""
      Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "0, noSST);", "", "", "switch to page 0")
 '-------------------------------------------------------------------------------------
      Print #f, ""
 '-------------------------------------------------------------------------------------
      Print #f, FormatSectionHeader(2, 1, "Timer Control Register")
 '-------------------------------------------------------------------------------------
      Print #f, FormatCommentsForInit(1, " enable shadow transfer to T12 and T13")
      Print #f, ""
      v = 0
      v = v + 2 ^ 6
      Print #f, FormatCodeStatemente(2, sRegPre & "TCTR4L", "=", _
                FormatTextOutput(v, "H2"), _
               "load " & sVarPre & " timer control register 4 low")
      Print #f, ""
      v = 0
      v = v + 2 ^ 6
      Print #f, FormatCodeStatemente(2, sRegPre & "TCTR4H", "=", _
                FormatTextOutput(v, "H2"), _
               "load " & sVarPre & " timer control register 4 high")
 
      If ((r.v(sRegPre & "TCTR4L_T12RS") = 1) Or (r.v(sRegPre & "TCTR4H_T13RS") = 1)) Then
        Print #f, ""
        Print #f, FormatComments(2, 1, "", "", "Start timer settings "); ""
          Print #f, ""
          If (r.v(sRegPre & "TCTR4L_T12RS") = 1) Then
              v = 0
              v = v + r.sfr(sRegPre & "TCTR4L")
              Print #f, FormatCodeStatemente(2, sRegPre & "TCTR4L", "=", _
                        FormatTextOutput(v, "H2"), _
                       "start timer 12")
          End If
          Print #f, ""
          If (r.v(sRegPre & "TCTR4H_T13RS") = 1) Then
              v = 0
              v = v + r.sfr(sRegPre & "TCTR4H")
              Print #f, FormatCodeStatemente(2, sRegPre & "TCTR4H", "=", _
                        FormatTextOutput(v, "H2"), _
                       "start timer 13")
          End If
      End If


      Print #f, ""
      Print #f, uc.GetUserCode("(" & n & ",3)", 2)
      Print #f, ""
      Print #f, "} " & END_OF_FUNCTION & r.v(sVarPre & "_NAME_" & n)
      Print #f, ""

    End If

    '------------------------------------------------------------------------------------------------
    '------------------------------------------------------------------------------------------------
    ' CCx_viNodeI0 function
    '------------------------------------------------------------------------------------------------
    '------------------------------------------------------------------------------------------------
'    n = "NodeI0"
'    If (r.v(CORE_PREFIX & "IEN1_ECCIP0") = 1) Then
'      Print #f, FormatFunctionHeader(r, func, sVarPre & "_NAME_" & n)
'      Print #f, uc.GetUserCode("(" & n & ",1)", 0)     'USER CODE for application specific descriptions'
'      Print #f, ""
'      Print #f, GenerateIsrDeclaration(r, r.v(sVarPre & "_NAME_" & n), _
'                  sVarPre & "_NodeI0_INT")
'      Print #f, "{"
'      Print #f, ""
'      Print #f, uc.GetUserCode("(" & n & ",2)", 2)
'      Print #f, ""
'' Clear the Interrupt bit
'      Call GenerateCodeForNodes(f, r, vIndex, 0, n, uc)
'      Print #f, ""
'      Print #f, "} //  End of function " & r.v(sVarPre & "_NAME_" & n)
'      Print #f, ""
'    End If
 If (Not IsCpuTypeOK(r)) Then
    n = "NodeI0"
    If (r.v(CORE_PREFIX & "IEN1_ECCIP0") = 1) Then
      If (r.v("ISR_CHOICE") = 1) Then
        Print #f, FormatFunctionHeader(r, func, sVarPre & "_NAME_" & n)
        Call GetDescriptionForISR(r, f)
        Print #f, uc.GetUserCode("(" & n & ",1)", 0)     'USER CODE for application specific descriptions'
        Print #f, ""
        Print #f, GenerateIsrDeclaration(r, r.v(sVarPre & "_NAME_" & n), _
                    sVarPre & "_NodeI0_INT")
        Print #f, "{"
        Print #f, ""
        Print #f, uc.GetUserCode("(" & n & ",2)", 2)
        Print #f, ""
        Print #f, FormatCodeStatemente(2, "_push_(SYSCON0);", "", "", "push the current RMAP")
        Print #f, FormatCodeStatemente(2, "RESET_RMAP();", "", "", "resets RMAP")
        Print #f, ""
       '**************************************************************** To Check for CCU6SR0 ****************************************************************
       If ((r.v(CORE_PREFIX & "IPH1_PCCIP0H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP0H") + r.v(CORE_PREFIX & "IP1_PCCIP0")) = 0) Then
          Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "3, SST0);", "", "", "switch to page 3")
       ElseIf ((r.v(CORE_PREFIX & "IPH1_PCCIP0H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP0H") + r.v(CORE_PREFIX & "IP1_PCCIP0")) = 1) Then
          Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "3, SST1);", "", "", "switch to page 3")
       ElseIf ((r.v(CORE_PREFIX & "IPH1_PCCIP0H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP0H") + r.v(CORE_PREFIX & "IP1_PCCIP0")) = 2) Then
          Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "3, SST2);", "", "", "switch to page 3")
       ElseIf ((r.v(CORE_PREFIX & "IPH1_PCCIP0H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP0H") + r.v(CORE_PREFIX & "IP1_PCCIP0")) = 3) Then
          Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "3, SST3);", "", "", "switch to page 3")
       End If
       Print #f, ""
       Print #f, " if (" & SCU_PREFIX & "IRCON3 & 0x01)  //  if CCU6SR0"
       Print #f, " {"
       Print #f, "      " & SCU_PREFIX & "IRCON3 &= ~(ubyte)0x01;"
       Print #f, ""
       If ((r.v(CORE_PREFIX & "IPH1_PCCIP0H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP0H") + r.v(CORE_PREFIX & "IP1_PCCIP0")) = 0) Then
          Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "3, RST0);", "", "", "restore the old CCU page")
       ElseIf ((r.v(CORE_PREFIX & "IPH1_PCCIP0H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP0H") + r.v(CORE_PREFIX & "IP1_PCCIP0")) = 1) Then
          Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "3, RST1);", "", "", "restore the old CCU page")
       ElseIf ((r.v(CORE_PREFIX & "IPH1_PCCIP0H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP0H") + r.v(CORE_PREFIX & "IP1_PCCIP0")) = 2) Then
          Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "3, RST2);", "", "", "restore the old CCU page")
       ElseIf ((r.v(CORE_PREFIX & "IPH1_PCCIP0H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP0H") + r.v(CORE_PREFIX & "IP1_PCCIP0")) = 3) Then
           Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "3, RST3);", "", "", "restore the old CCU page")
       End If
    '**************************************************************** To Check for CCU6SR0 ****************************************************************
        Print #f, ""
        Print #f, uc.GetUserCode("(" & n & ",3)", 2)
        Print #f, ""
        ' Clear the Interrupt bit
        Call GenerateCodeForNodes(f, r, vIndex, 0, n, uc)
        Print #f, ""
       '**************************************************************** To Check for CCU6SR0 ****************************************************************
        Print #f, " }" & "          " & "// End of CCU6SR0 condition check"
        Print #f, ""
       '**************************************************************** To Check for CCU6SR0 ****************************************************************
        Print #f, ""
        Print #f, FormatCodeStatemente(2, "_pop_(SYSCON0);", "", "", "restore the old RMAP")
        Print #f, ""
        Print #f, "} //  End of function " & r.v(sVarPre & "_NAME_" & n)
        Print #f, ""
     ElseIf (r.v("ISR_CHOICE") = 2) Then
        Print #f, FormatFunctionHeader(r, func, sVarPre & "_NAME_" & n)
        Call GetDescriptionForISR(r, f)
        Print #f, uc.GetUserCode("(" & n & ",1)", 0)     'USER CODE for application specific descriptions'
        Print #f, ""
        Print #f, GenerateIsrDeclaration(r, r.v(sVarPre & "_NAME_" & n), _
                    sVarPre & "_NodeI0_INT")
        Print #f, "{"
        Print #f, ""
        Print #f, uc.GetUserCode("(" & n & ",2)", 2)
        Print #f, ""
      '**************************************************************** To Check for CCU6SR0 ****************************************************************
        If ((r.v(CORE_PREFIX & "IPH1_PCCIP0H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP0H") + r.v(CORE_PREFIX & "IP1_PCCIP0")) = 0) Then
           Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "3, SST0);", "", "", "switch to page 3")
        ElseIf ((r.v(CORE_PREFIX & "IPH1_PCCIP0H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP0H") + r.v(CORE_PREFIX & "IP1_PCCIP0")) = 1) Then
           Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "3, SST1);", "", "", "switch to page 3")
        ElseIf ((r.v(CORE_PREFIX & "IPH1_PCCIP0H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP0H") + r.v(CORE_PREFIX & "IP1_PCCIP0")) = 2) Then
           Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "3, SST2);", "", "", "switch to page 3")
        ElseIf ((r.v(CORE_PREFIX & "IPH1_PCCIP0H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP0H") + r.v(CORE_PREFIX & "IP1_PCCIP0")) = 3) Then
           Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "3, SST3);", "", "", "switch to page 3")
        End If
        Print #f, ""
        Print #f, " if (" & SCU_PREFIX & "IRCON3 & 0x01)  //  if CCU6SR0"
        Print #f, " {"
        Print #f, "      " & SCU_PREFIX & "IRCON3 &= ~(ubyte)0x01;"
        Print #f, ""
        If ((r.v(CORE_PREFIX & "IPH1_PCCIP0H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP0H") + r.v(CORE_PREFIX & "IP1_PCCIP0")) = 0) Then
           Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "3, RST0);", "", "", "restore the old CCU page")
        ElseIf ((r.v(CORE_PREFIX & "IPH1_PCCIP0H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP0H") + r.v(CORE_PREFIX & "IP1_PCCIP0")) = 1) Then
           Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "3, RST1);", "", "", "restore the old CCU page")
        ElseIf ((r.v(CORE_PREFIX & "IPH1_PCCIP0H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP0H") + r.v(CORE_PREFIX & "IP1_PCCIP0")) = 2) Then
           Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "3, RST2);", "", "", "restore the old CCU page")
        ElseIf ((r.v(CORE_PREFIX & "IPH1_PCCIP0H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP0H") + r.v(CORE_PREFIX & "IP1_PCCIP0")) = 3) Then
            Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "3, RST3);", "", "", "restore the old CCU page")
        End If
     '**************************************************************** To Check for CCU6SR0 ****************************************************************
        Print #f, uc.GetUserCode("(" & n & ",3)", 2)
        Print #f, ""
        ' Clear the Interrupt bit
        Call GenerateCodeForNodes(f, r, vIndex, 0, n, uc)
        Print #f, ""
       '**************************************************************** To Check for CCU6SR0 ****************************************************************
        Print #f, " }" & "          " & "// End of CCU6SR0 condition check"
        Print #f, ""
       '**************************************************************** To Check for CCU6SR0 ****************************************************************
        Print #f, "} //  End of function " & r.v(sVarPre & "_NAME_" & n)
        Print #f, ""
    End If
   End If
 End If
    '------------------------------------------------------------------------------------------------
    '------------------------------------------------------------------------------------------------
    ' CCx_viNodeI1 function
    '------------------------------------------------------------------------------------------------
    '------------------------------------------------------------------------------------------------
'    n = "NodeI1"
'    If (r.v(CORE_PREFIX & "IEN1_ECCIP1") = 1) Then
'      Print #f, FormatFunctionHeader(r, func, sVarPre & "_NAME_" & n)
'      Print #f, uc.GetUserCode("(" & n & ",1)", 0)     'USER CODE for application specific descriptions'
'      Print #f, ""
'      Print #f, GenerateIsrDeclaration(r, r.v(sVarPre & "_NAME_" & n), _
'                  sVarPre & "_NodeI1_INT")
'      Print #f, "{"
'      Print #f, ""
'      Print #f, uc.GetUserCode("(" & n & ",2)", 2)
'      Print #f, ""
'' Clear the Interrupt bit
'      Call GenerateCodeForNodes(f, r, vIndex, 1, n, uc)
'      Print #f, ""
'      Print #f, "} //  End of function " & r.v(sVarPre & "_NAME_" & n)
'      Print #f, ""
'    End If
  If (Not IsCpuTypeOK(r)) Then
    n = "NodeI1"
    If (r.v(CORE_PREFIX & "IEN1_ECCIP1") = 1) Then
        If (r.v("ISR_CHOICE") = 1) Then
          Print #f, FormatFunctionHeader(r, func, sVarPre & "_NAME_" & n)
      Call GetDescriptionForISR(r, f)
      Print #f, uc.GetUserCode("(" & n & ",1)", 0)     'USER CODE for application specific descriptions'
      Print #f, ""
      Print #f, GenerateIsrDeclaration(r, r.v(sVarPre & "_NAME_" & n), _
                  sVarPre & "_NodeI1_INT")
      Print #f, "{"
      Print #f, ""
          Print #f, uc.GetUserCode("(" & n & ",2)", 2)
          Print #f, ""
          Print #f, FormatCodeStatemente(2, "_push_(SYSCON0);", "", "", "push the current RMAP")
          Print #f, FormatCodeStatemente(2, "RESET_RMAP();", "", "", "resets RMAP")
          Print #f, ""
          '**************************************************************** To Check for CCU6SR1 ****************************************************************
           If ((r.v(CORE_PREFIX & "IPH1_PCCIP1H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP1H") + r.v(CORE_PREFIX & "IP1_PCCIP1")) = 0) Then
              Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "3, SST0);", "", "", "switch to page 3")
           ElseIf ((r.v(CORE_PREFIX & "IPH1_PCCIP1H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP1H") + r.v(CORE_PREFIX & "IP1_PCCIP1")) = 1) Then
              Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "3, SST1);", "", "", "switch to page 3")
           ElseIf ((r.v(CORE_PREFIX & "IPH1_PCCIP1H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP1H") + r.v(CORE_PREFIX & "IP1_PCCIP1")) = 2) Then
              Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "3, SST2);", "", "", "switch to page 3")
           ElseIf ((r.v(CORE_PREFIX & "IPH1_PCCIP1H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP1H") + r.v(CORE_PREFIX & "IP1_PCCIP1")) = 3) Then
              Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "3, SST3);", "", "", "switch to page 3")
           End If
           Print #f, ""
           Print #f, " if (" & SCU_PREFIX & "IRCON3 & 0x10)  //  if CCU6SR1"
           Print #f, " {"
           Print #f, "      " & SCU_PREFIX & "IRCON3 &= ~(ubyte)0x10;"
           Print #f, ""
           If ((r.v(CORE_PREFIX & "IPH1_PCCIP1H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP1H") + r.v(CORE_PREFIX & "IP1_PCCIP1")) = 0) Then
              Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "3, RST0);", "", "", "restore the old CCU page")
           ElseIf ((r.v(CORE_PREFIX & "IPH1_PCCIP1H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP1H") + r.v(CORE_PREFIX & "IP1_PCCIP1")) = 1) Then
              Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "3, RST1);", "", "", "restore the old CCU page")
           ElseIf ((r.v(CORE_PREFIX & "IPH1_PCCIP1H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP1H") + r.v(CORE_PREFIX & "IP1_PCCIP1")) = 2) Then
              Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "3, RST2);", "", "", "restore the old CCU page")
           ElseIf ((r.v(CORE_PREFIX & "IPH1_PCCIP1H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP1H") + r.v(CORE_PREFIX & "IP1_PCCIP1")) = 3) Then
              Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "3, RST3);", "", "", "restore the old CCU page")
           End If
          '**************************************************************** To Check for CCU6SR1 ****************************************************************
          Print #f, ""
          Print #f, uc.GetUserCode("(" & n & ",3)", 2)
          Print #f, ""
          ' Clear the Interrupt bit
          Call GenerateCodeForNodes(f, r, vIndex, 1, n, uc)
          Print #f, ""
          '**************************************************************** To Check for CCU6SR1 ****************************************************************
            Print #f, " }" & "          " & "// End of CCU6SR1 condition check"
            Print #f, ""
          '**************************************************************** To Check for CCU6SR1 ****************************************************************
          Print #f, ""
          Print #f, FormatCodeStatemente(2, "_pop_(SYSCON0);", "", "", "restore the old RMAP")
          Print #f, ""
      Print #f, "} //  End of function " & r.v(sVarPre & "_NAME_" & n)
          Print #f, ""
       ElseIf (r.v("ISR_CHOICE") = 2) Then
          Print #f, FormatFunctionHeader(r, func, sVarPre & "_NAME_" & n)
          Call GetDescriptionForISR(r, f)
          Print #f, uc.GetUserCode("(" & n & ",1)", 0)     'USER CODE for application specific descriptions'
          Print #f, ""
          Print #f, GenerateIsrDeclaration(r, r.v(sVarPre & "_NAME_" & n), _
                      sVarPre & "_NodeI1_INT")
          Print #f, "{"
          Print #f, ""
          Print #f, uc.GetUserCode("(" & n & ",2)", 2)
          Print #f, ""
          '**************************************************************** To Check for CCU6SR1 ****************************************************************
           If ((r.v(CORE_PREFIX & "IPH1_PCCIP1H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP1H") + r.v(CORE_PREFIX & "IP1_PCCIP1")) = 0) Then
              Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "3, SST0);", "", "", "switch to page 3")
           ElseIf ((r.v(CORE_PREFIX & "IPH1_PCCIP1H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP1H") + r.v(CORE_PREFIX & "IP1_PCCIP1")) = 1) Then
              Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "3, SST1);", "", "", "switch to page 3")
           ElseIf ((r.v(CORE_PREFIX & "IPH1_PCCIP1H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP1H") + r.v(CORE_PREFIX & "IP1_PCCIP1")) = 2) Then
              Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "3, SST2);", "", "", "switch to page 3")
           ElseIf ((r.v(CORE_PREFIX & "IPH1_PCCIP1H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP1H") + r.v(CORE_PREFIX & "IP1_PCCIP1")) = 3) Then
              Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "3, SST3);", "", "", "switch to page 3")
           End If
           Print #f, ""
           Print #f, " if (" & SCU_PREFIX & "IRCON3 & 0x10)  //  if CCU6SR1"
           Print #f, " {"
           Print #f, "      " & SCU_PREFIX & "IRCON3 &= ~(ubyte)0x10;"
           Print #f, ""
           If ((r.v(CORE_PREFIX & "IPH1_PCCIP1H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP1H") + r.v(CORE_PREFIX & "IP1_PCCIP1")) = 0) Then
              Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "3, RST0);", "", "", "restore the old CCU page")
           ElseIf ((r.v(CORE_PREFIX & "IPH1_PCCIP1H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP1H") + r.v(CORE_PREFIX & "IP1_PCCIP1")) = 1) Then
              Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "3, RST1);", "", "", "restore the old CCU page")
           ElseIf ((r.v(CORE_PREFIX & "IPH1_PCCIP1H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP1H") + r.v(CORE_PREFIX & "IP1_PCCIP1")) = 2) Then
              Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "3, RST2);", "", "", "restore the old CCU page")
           ElseIf ((r.v(CORE_PREFIX & "IPH1_PCCIP1H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP1H") + r.v(CORE_PREFIX & "IP1_PCCIP1")) = 3) Then
              Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "3, RST3);", "", "", "restore the old CCU page")
           End If
          '**************************************************************** To Check for CCU6SR1 ****************************************************************
          Print #f, uc.GetUserCode("(" & n & ",3)", 2)
          Print #f, ""
          ' Clear the Interrupt bit
          Call GenerateCodeForNodes(f, r, vIndex, 1, n, uc)
          Print #f, ""
          '**************************************************************** To Check for CCU6SR1 ****************************************************************
           Print #f, " }" & "          " & "// End of CCU6SR1 condition check"
           Print #f, ""
          '**************************************************************** To Check for CCU6SR1 ****************************************************************
          Print #f, "} //  End of function " & r.v(sVarPre & "_NAME_" & n)
          Print #f, ""
       End If
    End If
End If
    '------------------------------------------------------------------------------------------------
    '------------------------------------------------------------------------------------------------
    ' CCx_viNodeI2 function
    '------------------------------------------------------------------------------------------------
    '------------------------------------------------------------------------------------------------
'    n = "NodeI2"
'    If (r.v(CORE_PREFIX & "IEN1_ECCIP2") = 1) Then
'      Print #f, FormatFunctionHeader(r, func, sVarPre & "_NAME_" & n)
'      Print #f, uc.GetUserCode("(" & n & ",1)", 0)     'USER CODE for application specific descriptions'
'      Print #f, ""
'      Print #f, GenerateIsrDeclaration(r, r.v(sVarPre & "_NAME_" & n), _
'                  sVarPre & "_NodeI2_INT")
'      Print #f, "{"
'      Print #f, ""
'      Print #f, uc.GetUserCode("(" & n & ",2)", 2)
'      Print #f, ""
'' Clear the Interrupt bit
'      Call GenerateCodeForNodes(f, r, vIndex, 2, n, uc)
'      Print #f, ""
'      Print #f, "} //  End of function " & r.v(sVarPre & "_NAME_" & n)
'      Print #f, ""
'    End If
  If (Not IsCpuTypeOK(r)) Then
    n = "NodeI2"
    If (r.v(CORE_PREFIX & "IEN1_ECCIP2") = 1) Then
       If (r.v("ISR_CHOICE") = 1) Then
      Print #f, FormatFunctionHeader(r, func, sVarPre & "_NAME_" & n)
      Call GetDescriptionForISR(r, f)
      Print #f, uc.GetUserCode("(" & n & ",1)", 0)     'USER CODE for application specific descriptions'
      Print #f, ""
      Print #f, GenerateIsrDeclaration(r, r.v(sVarPre & "_NAME_" & n), _
                  sVarPre & "_NodeI2_INT")
      Print #f, "{"
      Print #f, ""
            Print #f, uc.GetUserCode("(" & n & ",2)", 2)
            Print #f, ""
            Print #f, FormatCodeStatemente(2, "_push_(SYSCON0);", "", "", "push the current RMAP")
            Print #f, FormatCodeStatemente(2, "RESET_RMAP();", "", "", "resets RMAP")
            Print #f, ""
            '**************************************************************** To Check for CCU6SR2 ****************************************************************
             If ((r.v(CORE_PREFIX & "IPH1_PCCIP2H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP2H") + r.v(CORE_PREFIX & "IP1_PCCIP2")) = 0) Then
                 Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "3, SST0);", "", "", "switch to page 3")
             ElseIf ((r.v(CORE_PREFIX & "IPH1_PCCIP2H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP2H") + r.v(CORE_PREFIX & "IP1_PCCIP2")) = 1) Then
                 Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "3, SST1);", "", "", "switch to page 3")
             ElseIf ((r.v(CORE_PREFIX & "IPH1_PCCIP2H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP2H") + r.v(CORE_PREFIX & "IP1_PCCIP2")) = 2) Then
                 Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "3, SST2);", "", "", "switch to page 3")
             ElseIf ((r.v(CORE_PREFIX & "IPH1_PCCIP2H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP2H") + r.v(CORE_PREFIX & "IP1_PCCIP2")) = 3) Then
                 Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "3, SST3);", "", "", "switch to page 3")
             End If
             Print #f, ""
             Print #f, " if (" & SCU_PREFIX & "IRCON4 & 0x01)  //  if CCU6SR2"
             Print #f, " {"
             Print #f, "      " & SCU_PREFIX & "IRCON4 &= ~(ubyte)0x01;"
             Print #f, ""
             If ((r.v(CORE_PREFIX & "IPH1_PCCIP2H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP2H") + r.v(CORE_PREFIX & "IP1_PCCIP2")) = 0) Then
                 Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "3, RST0);", "", "", "restore the old CCU page")
             ElseIf ((r.v(CORE_PREFIX & "IPH1_PCCIP2H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP2H") + r.v(CORE_PREFIX & "IP1_PCCIP2")) = 1) Then
                 Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "3, RST1);", "", "", "restore the old CCU page")
             ElseIf ((r.v(CORE_PREFIX & "IPH1_PCCIP2H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP2H") + r.v(CORE_PREFIX & "IP1_PCCIP2")) = 2) Then
                 Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "3, RST2);", "", "", "restore the old CCU page")
             ElseIf ((r.v(CORE_PREFIX & "IPH1_PCCIP2H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP2H") + r.v(CORE_PREFIX & "IP1_PCCIP2")) = 3) Then
                 Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "3, RST3);", "", "", "restore the old CCU page")
             End If
            '**************************************************************** To Check for CCU6SR2 ****************************************************************
            Print #f, ""
      Print #f, uc.GetUserCode("(" & n & ",3)", 2)
      Print #f, ""
' Clear the Interrupt bit
      Call GenerateCodeForNodes(f, r, vIndex, 2, n, uc)
      Print #f, ""
           '**************************************************************** To Check for CCU6SR2 ****************************************************************
             Print #f, " }" & "          " & "// End of CCU6SR2 condition check"
             Print #f, ""
           '**************************************************************** To Check for CCU6SR2 ****************************************************************
            Print #f, ""
            Print #f, FormatCodeStatemente(2, "_pop_(SYSCON0);", "", "", "restore the old RMAP")
            Print #f, ""
      Print #f, "} //  End of function " & r.v(sVarPre & "_NAME_" & n)
      Print #f, ""
       ElseIf (r.v("ISR_CHOICE") = 2) Then
            Print #f, FormatFunctionHeader(r, func, sVarPre & "_NAME_" & n)
            Call GetDescriptionForISR(r, f)
            Print #f, uc.GetUserCode("(" & n & ",1)", 0)     'USER CODE for application specific descriptions'
            Print #f, ""
            Print #f, GenerateIsrDeclaration(r, r.v(sVarPre & "_NAME_" & n), _
                        sVarPre & "_NodeI2_INT")
            Print #f, "{"
            Print #f, ""
            Print #f, uc.GetUserCode("(" & n & ",2)", 2)
            Print #f, ""
            '**************************************************************** To Check for CCU6SR2 ****************************************************************
             If ((r.v(CORE_PREFIX & "IPH1_PCCIP2H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP2H") + r.v(CORE_PREFIX & "IP1_PCCIP2")) = 0) Then
                 Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "3, SST0);", "", "", "switch to page 3")
             ElseIf ((r.v(CORE_PREFIX & "IPH1_PCCIP2H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP2H") + r.v(CORE_PREFIX & "IP1_PCCIP2")) = 1) Then
                 Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "3, SST1);", "", "", "switch to page 3")
             ElseIf ((r.v(CORE_PREFIX & "IPH1_PCCIP2H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP2H") + r.v(CORE_PREFIX & "IP1_PCCIP2")) = 2) Then
                 Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "3, SST2);", "", "", "switch to page 3")
             ElseIf ((r.v(CORE_PREFIX & "IPH1_PCCIP2H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP2H") + r.v(CORE_PREFIX & "IP1_PCCIP2")) = 3) Then
                 Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "3, SST3);", "", "", "switch to page 3")
             End If
             Print #f, ""
             Print #f, " if (" & SCU_PREFIX & "IRCON4 & 0x01)  //  if CCU6SR2"
             Print #f, " {"
             Print #f, "      " & SCU_PREFIX & "IRCON4 &= ~(ubyte)0x01;"
             Print #f, ""
             If ((r.v(CORE_PREFIX & "IPH1_PCCIP2H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP2H") + r.v(CORE_PREFIX & "IP1_PCCIP2")) = 0) Then
                 Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "3, RST0);", "", "", "restore the old CCU page")
             ElseIf ((r.v(CORE_PREFIX & "IPH1_PCCIP2H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP2H") + r.v(CORE_PREFIX & "IP1_PCCIP2")) = 1) Then
                 Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "3, RST1);", "", "", "restore the old CCU page")
             ElseIf ((r.v(CORE_PREFIX & "IPH1_PCCIP2H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP2H") + r.v(CORE_PREFIX & "IP1_PCCIP2")) = 2) Then
                 Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "3, RST2);", "", "", "restore the old CCU page")
             ElseIf ((r.v(CORE_PREFIX & "IPH1_PCCIP2H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP2H") + r.v(CORE_PREFIX & "IP1_PCCIP2")) = 3) Then
                 Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "3, RST3);", "", "", "restore the old CCU page")
             End If
            '**************************************************************** To Check for CCU6SR2 ****************************************************************
            Print #f, uc.GetUserCode("(" & n & ",3)", 2)
            Print #f, ""
            'Clear the Interrupt bit
            Call GenerateCodeForNodes(f, r, vIndex, 2, n, uc)
            Print #f, ""
            '**************************************************************** To Check for CCU6SR2 ****************************************************************
             Print #f, " }" & "          " & "// End of CCU6SR2 condition check"
             Print #f, ""
            '**************************************************************** To Check for CCU6SR2 ****************************************************************
            Print #f, "} //  End of function " & r.v(sVarPre & "_NAME_" & n)
            Print #f, ""
       End If
    End If
 End If
    '------------------------------------------------------------------------------------------------
    '------------------------------------------------------------------------------------------------
    ' CCx_viNodeI3 function
    '------------------------------------------------------------------------------------------------
    '------------------------------------------------------------------------------------------------
'    n = "NodeI3"
'    If (r.v(CORE_PREFIX & "IEN1_ECCIP3") = 1) Then
'      Print #f, FormatFunctionHeader(r, func, sVarPre & "_NAME_" & n)
'      Print #f, uc.GetUserCode("(" & n & ",1)", 0)     'USER CODE for application specific descriptions'
'      Print #f, ""
'      Print #f, GenerateIsrDeclaration(r, r.v(sVarPre & "_NAME_" & n), _
'                  sVarPre & "_NodeI3_INT")
'      Print #f, "{"
'      Print #f, ""
'      Print #f, uc.GetUserCode("(" & n & ",2)", 2)
'      Print #f, ""
'' Clear the Interrupt bit
'      Call GenerateCodeForNodes(f, r, vIndex, 3, n, uc)
'      Print #f, ""
'      Print #f, "} //  End of function " & r.v(sVarPre & "_NAME_" & n)
'      Print #f, ""
'    End If
  If (Not IsCpuTypeOK(r)) Then
    n = "NodeI3"
    If (r.v(CORE_PREFIX & "IEN1_ECCIP3") = 1) Then
       If (r.v("ISR_CHOICE") = 1) Then
      Print #f, FormatFunctionHeader(r, func, sVarPre & "_NAME_" & n)
      Call GetDescriptionForISR(r, f)
      Print #f, uc.GetUserCode("(" & n & ",1)", 0)     'USER CODE for application specific descriptions'
      Print #f, ""
      Print #f, GenerateIsrDeclaration(r, r.v(sVarPre & "_NAME_" & n), _
                  sVarPre & "_NodeI3_INT")
      Print #f, "{"
      Print #f, ""
          Print #f, uc.GetUserCode("(" & n & ",2)", 2)
          Print #f, ""
          Print #f, FormatCodeStatemente(2, "_push_(SYSCON0);", "", "", "push the current RMAP")
          Print #f, FormatCodeStatemente(2, "RESET_RMAP();", "", "", "resets RMAP")
          Print #f, ""
          '**************************************************************** To Check for CCU6SR3 ****************************************************************
            If ((r.v(CORE_PREFIX & "IPH1_PCCIP3H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP3H") + r.v(CORE_PREFIX & "IP1_PCCIP3")) = 0) Then
               Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "3, SST0);", "", "", "switch to page 3")
            ElseIf ((r.v(CORE_PREFIX & "IPH1_PCCIP3H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP3H") + r.v(CORE_PREFIX & "IP1_PCCIP3")) = 1) Then
               Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "3, SST1);", "", "", "switch to page 3")
            ElseIf ((r.v(CORE_PREFIX & "IPH1_PCCIP3H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP3H") + r.v(CORE_PREFIX & "IP1_PCCIP3")) = 2) Then
               Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "3, SST2);", "", "", "switch to page 3")
            ElseIf ((r.v(CORE_PREFIX & "IPH1_PCCIP3H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP3H") + r.v(CORE_PREFIX & "IP1_PCCIP3")) = 3) Then
               Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "3, SST3);", "", "", "switch to page 3")
            End If
            Print #f, ""
            Print #f, " if (" & SCU_PREFIX & "IRCON4 & 0x10)  //  if CCU6SR3"
            Print #f, " {"
            Print #f, "      " & SCU_PREFIX & "IRCON4 &= ~(ubyte)0x10;"
            Print #f, ""
            If ((r.v(CORE_PREFIX & "IPH1_PCCIP3H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP3H") + r.v(CORE_PREFIX & "IP1_PCCIP3")) = 0) Then
               Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "3, RST0);", "", "", "restore the old CCU page")
            ElseIf ((r.v(CORE_PREFIX & "IPH1_PCCIP3H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP3H") + r.v(CORE_PREFIX & "IP1_PCCIP3")) = 1) Then
               Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "3, RST1);", "", "", "restore the old CCU page")
            ElseIf ((r.v(CORE_PREFIX & "IPH1_PCCIP3H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP3H") + r.v(CORE_PREFIX & "IP1_PCCIP3")) = 2) Then
               Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "3, RST2);", "", "", "restore the old CCU page")
            ElseIf ((r.v(CORE_PREFIX & "IPH1_PCCIP3H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP3H") + r.v(CORE_PREFIX & "IP1_PCCIP3")) = 3) Then
               Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "3, RST3);", "", "", "restore the old CCU page")
            End If
          '**************************************************************** To Check for CCU6SR3 ****************************************************************
          Print #f, ""
      Print #f, uc.GetUserCode("(" & n & ",3)", 2)
      Print #f, ""
' Clear the Interrupt bit
      Call GenerateCodeForNodes(f, r, vIndex, 3, n, uc)
      Print #f, ""
          '**************************************************************** To Check for CCU6SR3 ****************************************************************
            Print #f, " }" & "          " & "// End of CCU6SR3 condition check"
            Print #f, ""
          '**************************************************************** To Check for CCU6SR3 ****************************************************************
          Print #f, ""
          Print #f, FormatCodeStatemente(2, "_pop_(SYSCON0);", "", "", "restore the old RMAP")
          Print #f, ""
      Print #f, "} //  End of function " & r.v(sVarPre & "_NAME_" & n)
      Print #f, ""
       ElseIf (r.v("ISR_CHOICE") = 2) Then
          Print #f, FormatFunctionHeader(r, func, sVarPre & "_NAME_" & n)
          Call GetDescriptionForISR(r, f)
          Print #f, uc.GetUserCode("(" & n & ",1)", 0)     'USER CODE for application specific descriptions'
          Print #f, ""
          Print #f, GenerateIsrDeclaration(r, r.v(sVarPre & "_NAME_" & n), _
                      sVarPre & "_NodeI3_INT")
          Print #f, "{"
          Print #f, ""
          Print #f, uc.GetUserCode("(" & n & ",2)", 2)
          Print #f, ""
          '**************************************************************** To Check for CCU6SR3 ****************************************************************
            If ((r.v(CORE_PREFIX & "IPH1_PCCIP3H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP3H") + r.v(CORE_PREFIX & "IP1_PCCIP3")) = 0) Then
               Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "3, SST0);", "", "", "switch to page 3")
            ElseIf ((r.v(CORE_PREFIX & "IPH1_PCCIP3H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP3H") + r.v(CORE_PREFIX & "IP1_PCCIP3")) = 1) Then
               Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "3, SST1);", "", "", "switch to page 3")
            ElseIf ((r.v(CORE_PREFIX & "IPH1_PCCIP3H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP3H") + r.v(CORE_PREFIX & "IP1_PCCIP3")) = 2) Then
               Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "3, SST2);", "", "", "switch to page 3")
            ElseIf ((r.v(CORE_PREFIX & "IPH1_PCCIP3H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP3H") + r.v(CORE_PREFIX & "IP1_PCCIP3")) = 3) Then
               Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "3, SST3);", "", "", "switch to page 3")
            End If
              
            Print #f, ""
            Print #f, " if (" & SCU_PREFIX & "IRCON4 & 0x10)  //  if CCU6SR3"
            Print #f, " {"
            Print #f, "      " & SCU_PREFIX & "IRCON4 &= ~(ubyte)0x10;"
            Print #f, ""
            If ((r.v(CORE_PREFIX & "IPH1_PCCIP3H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP3H") + r.v(CORE_PREFIX & "IP1_PCCIP3")) = 0) Then
               Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "3, RST0);", "", "", "restore the old CCU page")
            ElseIf ((r.v(CORE_PREFIX & "IPH1_PCCIP3H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP3H") + r.v(CORE_PREFIX & "IP1_PCCIP3")) = 1) Then
               Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "3, RST1);", "", "", "restore the old CCU page")
            ElseIf ((r.v(CORE_PREFIX & "IPH1_PCCIP3H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP3H") + r.v(CORE_PREFIX & "IP1_PCCIP3")) = 2) Then
               Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "3, RST2);", "", "", "restore the old CCU page")
            ElseIf ((r.v(CORE_PREFIX & "IPH1_PCCIP3H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP3H") + r.v(CORE_PREFIX & "IP1_PCCIP3")) = 3) Then
               Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "3, RST3);", "", "", "restore the old CCU page")
            End If
        '**************************************************************** To Check for CCU6SR3 ****************************************************************
          Print #f, uc.GetUserCode("(" & n & ",3)", 2)
          Print #f, ""
          ' Clear the Interrupt bit
          Call GenerateCodeForNodes(f, r, vIndex, 3, n, uc)
          Print #f, ""
          '**************************************************************** To Check for CCU6SR3 ****************************************************************
           Print #f, " }" & "          " & "// End of CCU6SR3 condition check"
           Print #f, ""
          '**************************************************************** To Check for CCU6SR3 ****************************************************************
          Print #f, "} //  End of function " & r.v(sVarPre & "_NAME_" & n)
          Print #f, ""
       End If
    End If
  End If
    Print #f, ""
    Print #f, uc.GetUserCode("(" & sVarPre & "_General,10)", 0)
    Print #f, ""
    
    'close file
    Close f
    
    CAPCOMxGenerateC = True
    Exit Function
    
CAPCOMxGenerateCError:
    Close f
    Exit Function
End Function


'*****************************************************************************
'Description:
'        Generates the code for the CAPCOMx.h file.
'-----------------------------------------------------------------------------
'Parameters:
'        r                reference to the Registers object
'        vIndex           a parameter
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Function CAPCOMxGenerateH(r As ProjectData, vIndex As Variant) As Boolean
    On Error GoTo CAPCOMxGenerateHError
    
    Dim i As Integer
    Dim f As Variant
    Dim d As String
    Dim dc As DAvECollection
    Dim uc As UserCode
    Dim func As CC6FunctionClass
    Dim para As ParameterClass
    Dim n As String
    Dim sVarPre As String
    Dim l As Long
    Dim v As Variant
    Dim iTmr_12 As Integer
    Dim iTmr_13 As Integer
    Dim iTmr As Integer
    Dim iCh_low As Integer
    Dim iCh_high As Integer
    Dim iChannel As Integer
    Dim sRegPre As String
    
    sVarPre = "CCU" & vIndex
    sRegPre = sVarPre & "_"
    
    iCh_low = 0
    iCh_high = 3
    iTmr_12 = 12
    iTmr_13 = 13
   
    CAPCOMxGenerateH = False

    Set dc = ObjectCollection("MODULENAMES")
    Set uc = New UserCode
    Set func = New CC6FunctionClass
    Set para = New ParameterClass

    'refresh the decriptions of the functions and macros
    Call RefreshFunctionDescriptions(vIndex, func, r)
    
    'refresh the decriptions of the parameters
    Call RefreshParameterDescriptions(vIndex, para, r)

    'read usercode
    uc.ReadFile ((StripFilenameAndExtension(r.LoadedFile)) & "\" & r.v(sVarPre & "_HFILE"))
    
    'open CAPCOMx.h
    f = FreeFile
    Open CStr(StripFilenameAndExtension(r.LoadedFile)) & "\" & r.v(sVarPre & "_HFILE") For Output As f
    
    '------------------------------------------------------------------------------------------------
    ' module header
    '------------------------------------------------------------------------------------------------
    d = FormatModuleDescription(GetModuleHeaderH(sVarPre & ""))
    Print #f, Rtf.GenerateModuleHeader(DefGetValue("ProductVersion"), StripPath(r.LoadedFile), dc(sVarPre).ModuleDescription, r.v(sVarPre & "_HFILE"), r.v("MAIN_CPU_TYPE"), r.v("MAIN_COMPILER"), d)
            
    Print #f, uc.GetUserCode("(" & sVarPre & "_Header,1)", 0)
    Print #f, ""
    Print #f, Rtf.GenerateNote((r.v(sVarPre & "_Notes")))
    Print #f, ""
    Print #f, "#ifndef _" & StripExtension(r.v(sVarPre & "_HFILE")) & "_H_"
    Print #f, "#define _" & StripExtension(r.v(sVarPre & "_HFILE")) & "_H_"
    Print #f, ""
    Print #f, SECTION_PROJECT_INCLUDES
    Print #f, ""  'DAvE includes'
    Print #f, uc.GetUserCode("(" & sVarPre & "_Header,2)", 0)
    Print #f, ""
    Print #f, ""
    Print #f, SECTION_MACROS
    Print #f, ""  'DAvE global macro definitions; not used as functions'
    Print #f, uc.GetUserCode("(" & sVarPre & "_Header,3)", 0)
    Print #f, ""
    Print #f, ""
    Print #f, SECTION_DEFINES
    Print #f, ""  'DAvE global #define definitions'


    n = "TIMER_" & iTmr_12
    Print #f, FormatParameterStatement(r, para, sVarPre & "_PARA_" & n, "" & iTmr_12)

    n = "TIMER_" & iTmr_13
    Print #f, FormatParameterStatement(r, para, sVarPre & "_PARA_" & n, "" & iTmr_13)

    For i = iCh_low To iCh_high
        n = "CHANNEL_" & i
        Print #f, FormatParameterStatement(r, para, sVarPre & "_PARA_" & n, "" & i)
    Next i

    Print #f, ""
    Print #f, uc.GetUserCode("(" & sVarPre & "_Header,4)", 0)
    Print #f, ""
    Print #f, ""
    Print #f, SECTION_TYPEDEFS
    Print #f, ""  'DAvE type definitions'
    Print #f, uc.GetUserCode("(" & sVarPre & "_Header,5)", 0)
    Print #f, ""
    Print #f, ""
    Print #f, SECTION_IMPORTED_GLOBAL_VARIABLES
    Print #f, ""  'DAvE external declarations of imported global variables'
    Print #f, uc.GetUserCode("(" & sVarPre & "_Header,6)", 0)
    Print #f, ""
    Print #f, ""
    Print #f, SECTION_GLOBAL_VARIABLES
    Print #f, ""  'DAvE definition of global variables'
    Print #f, uc.GetUserCode("(" & sVarPre & "_Header,7)", 0)
    Print #f, ""
    Print #f, ""
    Print #f, SECTION_GLOBAL_PROTOTYPES
    Print #f, ""  'DAvE declarations of functions which should become global'

    ' for each function in this 'func' object
    For l = 1 To (func.FunctionCount - 1)
      ' get the function name which was insert in 'Include.inc' with
      'AddFunction()'
      d = func.FunctionName(l)
      ' get only the third part of the function name (e.g "Init")
      n = Right(d, Len(d) - InStr(d, "NAME") - Len("NAME"))
      ' only if the use variable of the function is selected and the function is a really function
      ' not a macro or a ISR
      If (r.v(sVarPre & "_USE_" & n) = 1 And func.FunctionSort(d) = 1) Then
            Print #f, FormatFunctionDeclaration(r, func, d) & ";"
      End If
    Next l
    Print #f, ""
    Print #f, ""
    Print #f, uc.GetUserCode("(" & sVarPre & "_Header,8)", 0)
    Print #f, ""
    Print #f, ""
                          'DAvE declarations of global macros'

    '------------------------------------------------------------------------------------------------
    '------------------------------------------------------------------------------------------------
    ' CCx_StartTmr macro
    '------------------------------------------------------------------------------------------------
    '------------------------------------------------------------------------------------------------
    n = "StartTmr"
    If (r.v(sVarPre & "_USE_" & n) = 1) Then
      Print #f, FormatFunctionHeader(r, func, sVarPre & "_NAME_" & n)
      Print #f, "#define " & FormatFunctionDeclaration(r, func, sVarPre & "_NAME_" & n) & " " _
                & r.v(sVarPre & "_NAME_" & n) & "_##TimerNr()"
      Print #f, "#define " & r.v(sVarPre & "_NAME_" & n) & "_" & _
                r.v(sVarPre & "_PARA_TIMER_" & iTmr_12) & "() " & _
                sRegPre & "TCTR4L |= 0x02"
                
      Print #f, "#define " & r.v(sVarPre & "_NAME_" & n) & "_" & _
                r.v(sVarPre & "_PARA_TIMER_" & iTmr_13) & "() " & _
                sRegPre & "TCTR4H |= 0x02"
      Print #f, ""
      Print #f, ""
    End If

    '------------------------------------------------------------------------------------------------
    '------------------------------------------------------------------------------------------------
    ' CCx_StopTmr macro
    '------------------------------------------------------------------------------------------------
    '------------------------------------------------------------------------------------------------
    n = "StopTmr"
    If (r.v(sVarPre & "_USE_" & n) = 1) Then
      Print #f, FormatFunctionHeader(r, func, sVarPre & "_NAME_" & n)
      Print #f, "#define " & FormatFunctionDeclaration(r, func, sVarPre & "_NAME_" & n) & " " _
                & r.v(sVarPre & "_NAME_" & n) & "_##TimerNr()"
      Print #f, "#define " & r.v(sVarPre & "_NAME_" & n) & "_" & _
                r.v(sVarPre & "_PARA_TIMER_" & iTmr_12) & "() " & _
                sRegPre & "TCTR4L |= 0x01"
      Print #f, "#define " & r.v(sVarPre & "_NAME_" & n) & "_" & _
                r.v(sVarPre & "_PARA_TIMER_" & iTmr_13) & "() " & _
                sRegPre & "TCTR4H |= 0x01"
      Print #f, ""
      Print #f, ""
    End If

    '------------------------------------------------------------------------------------------------
    '------------------------------------------------------------------------------------------------
    ' CCx_ResetTmr macro
    '------------------------------------------------------------------------------------------------
    '------------------------------------------------------------------------------------------------
    n = "ResetTmr"
    If (r.v(sVarPre & "_USE_" & n) = 1) Then
      Print #f, FormatFunctionHeader(r, func, sVarPre & "_NAME_" & n)
      Print #f, "#define " & FormatFunctionDeclaration(r, func, sVarPre & "_NAME_" & n) & " " & _
                r.v(sVarPre & "_NAME_" & n) & "_##TimerNr()"
      Print #f, "#define " & r.v(sVarPre & "_NAME_" & n) & "_" & _
                r.v(sVarPre & "_PARA_TIMER_" & iTmr_12) & "() " & _
                sRegPre & "TCTR4L |= 0x04"
      Print #f, "#define " & r.v(sVarPre & "_NAME_" & n) & "_" & _
                r.v(sVarPre & "_PARA_TIMER_" & iTmr_13) & "() " & _
                sRegPre & "TCTR4H |= 0x04"
      Print #f, ""
      Print #f, ""
    End If

    '------------------------------------------------------------------------------------------------
    '------------------------------------------------------------------------------------------------
    ' CCx_SetTmrPeriod macro
    '------------------------------------------------------------------------------------------------
    '------------------------------------------------------------------------------------------------
    n = "SetTmrPeriod"
    If (r.v(sVarPre & "_USE_" & n) = 1) Then
      Print #f, FormatFunctionHeader(r, func, sVarPre & "_NAME_" & n)
      Print #f, "#define " & FormatFunctionDeclaration(r, func, sVarPre & "_NAME_" & n) & " " & _
                r.v(sVarPre & "_NAME_" & n) & "_##TimerNr(uwValue)"
      If (r.v("MAIN_COMPILER") = "Keil") Then
        Print #f, "#define " & r.v(sVarPre & "_NAME_" & n) & "_" & _
                  r.v(sVarPre & "_PARA_TIMER_" & iTmr_12) & "(uwValue) " & _
                  sRegPre & "T12PRLH = uwValue"
        Print #f, "#define " & r.v(sVarPre & "_NAME_" & n) & "_" & _
                  r.v(sVarPre & "_PARA_TIMER_" & iTmr_13) & "(uwValue) " & _
                  sRegPre & "T13PRLH = uwValue"
      Else
        Print #f, "#define " & r.v(sVarPre & "_NAME_" & n) & "_" & _
                  r.v(sVarPre & "_PARA_TIMER_" & iTmr_12) & "(uwValue) " & _
                  sRegPre & "T12PRL = (ubyte)(0x00FF & uwValue);" & sRegPre & "T12PRH = (ubyte)(uwValue >> 8)"
        Print #f, "#define " & r.v(sVarPre & "_NAME_" & n) & "_" & _
                  r.v(sVarPre & "_PARA_TIMER_" & iTmr_13) & "(uwValue) " & _
                  sRegPre & "T13PRL = (ubyte)(0x00FF & uwValue); " & sRegPre & "T13PRH = (ubyte)(uwValue >> 8)"
      End If
      Print #f, ""
      Print #f, ""
    End If

    '------------------------------------------------------------------------------------------------
    '------------------------------------------------------------------------------------------------
    ' CCx_GetTmrCounter macro
    '------------------------------------------------------------------------------------------------
    '------------------------------------------------------------------------------------------------
    n = "GetTmrCounter"
    If (r.v(sVarPre & "_USE_" & n) = 1) Then
      Print #f, FormatFunctionHeader(r, func, sVarPre & "_NAME_" & n)
      Print #f, "#define " & FormatFunctionDeclaration(r, func, sVarPre & "_NAME_" & n) & " " & _
                r.v(sVarPre & "_NAME_" & n) & "_##TimerNr()"
      If (r.v("MAIN_COMPILER") = "Keil") Then
        Print #f, "#define " & r.v(sVarPre & "_NAME_" & n) & "_" & _
                  r.v(sVarPre & "_PARA_TIMER_" & iTmr_12) & "() " & _
                  sRegPre & "T12LH"
        Print #f, "#define " & r.v(sVarPre & "_NAME_" & n) & "_" & _
                  r.v(sVarPre & "_PARA_TIMER_" & iTmr_13) & "() " & _
                  sRegPre & "T13LH"
      Else
        Print #f, "#define " & r.v(sVarPre & "_NAME_" & n) & "_" & _
                  r.v(sVarPre & "_PARA_TIMER_" & iTmr_12) & "() " & _
                  "(uword)((" & sRegPre & "T12H << 8) + " & sRegPre & "T12L)"
        Print #f, "#define " & r.v(sVarPre & "_NAME_" & n) & "_" & _
                  r.v(sVarPre & "_PARA_TIMER_" & iTmr_13) & "() " & _
                  "(uword)((" & sRegPre & "T13H << 8) + " & sRegPre & "T13L)"
      End If
      Print #f, ""
      Print #f, ""
    End If

    '------------------------------------------------------------------------------------------------
    '------------------------------------------------------------------------------------------------
    ' CCx_SetTmrCounter macro
    '------------------------------------------------------------------------------------------------
    '------------------------------------------------------------------------------------------------
    n = "SetTmrCounter"
    If (r.v(sVarPre & "_USE_" & n) = 1) Then
      Print #f, FormatFunctionHeader(r, func, sVarPre & "_NAME_" & n)
      Print #f, "#define " & FormatFunctionDeclaration(r, func, sVarPre & "_NAME_" & n) & " " & _
                r.v(sVarPre & "_NAME_" & n) & "_##TimerNr(uwValue)"
      If (r.v("MAIN_COMPILER") = "Keil") Then
        Print #f, "#define " & r.v(sVarPre & "_NAME_" & n) & "_" & _
                  r.v(sVarPre & "_PARA_TIMER_" & iTmr_12) & "(uwValue) " & _
                  sRegPre & "T12LH = uwValue"
        Print #f, "#define " & r.v(sVarPre & "_NAME_" & n) & "_" & _
                  r.v(sVarPre & "_PARA_TIMER_" & iTmr_13) & "(uwValue) " & _
                  sRegPre & "T13LH = uwValue"
      Else
        Print #f, "#define " & r.v(sVarPre & "_NAME_" & n) & "_" & _
                  r.v(sVarPre & "_PARA_TIMER_" & iTmr_12) & "(uwValue) " & _
                  sRegPre & "T12L = (ubyte)(0x00FF & uwValue); " & sRegPre & "T12H = (ubyte)(uwValue >> 8)"
        Print #f, "#define " & r.v(sVarPre & "_NAME_" & n) & "_" & _
                  r.v(sVarPre & "_PARA_TIMER_" & iTmr_13) & "(uwValue) " & _
                  sRegPre & "T13L = (ubyte)(0x00FF & uwValue); " & sRegPre & "T13H = (ubyte)(uwValue >> 8)"
      End If
                
      Print #f, ""
      Print #f, ""
    End If

    '------------------------------------------------------------------------------------------------
    '------------------------------------------------------------------------------------------------
    ' CCx_SetDeadTimePeriod macro
    '------------------------------------------------------------------------------------------------
    '------------------------------------------------------------------------------------------------
    n = "SetDeadTimePeriod"
    If (r.v(sVarPre & "_USE_" & n) = 1) Then
      Print #f, FormatFunctionHeader(r, func, sVarPre & "_NAME_" & n)
      Print #f, "#define " & FormatFunctionDeclaration(r, func, sVarPre & "_NAME_" & n) & " " & _
                sRegPre & "T12DTCL = (ubValue)"
      Print #f, ""
      Print #f, ""
    End If

    '------------------------------------------------------------------------------------------------
    '------------------------------------------------------------------------------------------------
    ' CCx_EnableShadowTransfer macro
    '------------------------------------------------------------------------------------------------
    '------------------------------------------------------------------------------------------------
    n = "EnableShadowTransfer"
    If (r.v(sVarPre & "_USE_" & n) = 1) Then
      Print #f, FormatFunctionHeader(r, func, sVarPre & "_NAME_" & n)
      Print #f, "#define " & FormatFunctionDeclaration(r, func, sVarPre & "_NAME_" & n) & " " & _
                r.v(sVarPre & "_NAME_" & n) & "_##TimerNr()"
      Print #f, "#define " & r.v(sVarPre & "_NAME_" & n) & "_" & _
                r.v(sVarPre & "_PARA_TIMER_" & iTmr_12) & "() " & _
                sRegPre & "TCTR4L |= 0x40"
      Print #f, "#define " & r.v(sVarPre & "_NAME_" & n) & "_" & _
                r.v(sVarPre & "_PARA_TIMER_" & iTmr_13) & "() " & _
                sRegPre & "TCTR4H |= 0x40"
      Print #f, ""
      Print #f, ""
    End If

    '------------------------------------------------------------------------------------------------
    '------------------------------------------------------------------------------------------------
    ' CCx_LoadChannelShadowRegister macro
    '------------------------------------------------------------------------------------------------
    '------------------------------------------------------------------------------------------------
    n = "LoadChannelShadowRegister"
    If (r.v(sVarPre & "_USE_" & n) = 1) Then
      Print #f, FormatFunctionHeader(r, func, sVarPre & "_NAME_" & n)
      Print #f, "#define " & FormatFunctionDeclaration(r, func, sVarPre & "_NAME_" & n) & " " & _
                r.v(sVarPre & "_NAME_" & n) & "_##RegName(uwValue)"

      If (r.v("MAIN_COMPILER") = "Keil") Then
        For i = iCh_low To iCh_high
            Print #f, "#define " & r.v(sVarPre & "_NAME_" & n) & "_" & _
                      r.v(sVarPre & "_PARA_CHANNEL_" & i) & "(uwValue) " & _
                      sRegPre & "CC6" & i & "SRLH = uwValue"
        Next i
      Else
        For i = iCh_low To iCh_high
            Print #f, "#define " & r.v(sVarPre & "_NAME_" & n) & "_" & _
                      r.v(sVarPre & "_PARA_CHANNEL_" & i) & "(uwValue) " & _
                      sRegPre & "CC6" & i & "SRH = (uword)(uwValue >> 8); " & sRegPre & "CC6" & i & "SRL = (ubyte)(uwValue & 0x00FF)"
        Next i
      End If
      Print #f, ""
      Print #f, ""
    End If

    '------------------------------------------------------------------------------------------------
    '------------------------------------------------------------------------------------------------
    ' GetChannelShadowRegister macro
    '------------------------------------------------------------------------------------------------
    '------------------------------------------------------------------------------------------------
    n = "GetChannelShadowRegister"
    If (r.v(sVarPre & "_USE_" & n) = 1) Then
      Print #f, FormatFunctionHeader(r, func, sVarPre & "_NAME_" & n)
      Print #f, "#define " & FormatFunctionDeclaration(r, func, sVarPre & "_NAME_" & n) & " " & r.v(sVarPre & "_NAME_" & n) & "_##RegName()"

      If (r.v("MAIN_COMPILER") = "Keil") Then
        For i = iCh_low To iCh_high
            Print #f, "#define " & r.v(sVarPre & "_NAME_" & n) & "_" & _
                      r.v(sVarPre & "_PARA_CHANNEL_" & i) & "() " & _
                      sRegPre & "CC6" & i & "SRLH"
        Next i
      Else
        For i = iCh_low To iCh_high
            Print #f, "#define " & r.v(sVarPre & "_NAME_" & n) & "_" & _
                      r.v(sVarPre & "_PARA_CHANNEL_" & i) & "() " & _
                      "(uword)((" & sRegPre & "CC6" & i & "SRH << 8) + " & sRegPre & "CC6" & i & "SRL)"
        Next i
      End If
      Print #f, ""
      Print #f, ""
    End If

    '------------------------------------------------------------------------------------------------
    '------------------------------------------------------------------------------------------------
    ' GetChannelRegister macro
    '------------------------------------------------------------------------------------------------
    '------------------------------------------------------------------------------------------------
    n = "GetChannelRegister"
    If (r.v(sVarPre & "_USE_" & n) = 1) Then
      Print #f, FormatFunctionHeader(r, func, sVarPre & "_NAME_" & n)
      Print #f, "#define " & FormatFunctionDeclaration(r, func, sVarPre & "_NAME_" & n) & " " & r.v(sVarPre & "_NAME_" & n) & "_##RegName()"

      If (r.v("MAIN_COMPILER") = "Keil") Then
        For i = iCh_low To iCh_high
            Print #f, "#define " & r.v(sVarPre & "_NAME_" & n) & "_" & _
                      r.v(sVarPre & "_PARA_CHANNEL_" & i) & "() " & _
                      sRegPre & "CC6" & i & "RLH"
        Next i
      Else
        For i = iCh_low To iCh_high
            Print #f, "#define " & r.v(sVarPre & "_NAME_" & n) & "_" & _
                      r.v(sVarPre & "_PARA_CHANNEL_" & i) & "() " & _
                      "(uword)((" & sRegPre & "CC6" & i & "RH << 8) + " & sRegPre & "CC6" & i & "RL)"
        Next i
      End If
      Print #f, ""
      Print #f, ""
    End If

    '------------------------------------------------------------------------------------------------
    '------------------------------------------------------------------------------------------------
    ' SetStatusBit macro
    '------------------------------------------------------------------------------------------------
    '------------------------------------------------------------------------------------------------
    n = "SetStatusBit"
    If (r.v(sVarPre & "_USE_" & n) = 1) Then
      Print #f, FormatFunctionHeader(r, func, sVarPre & "_NAME_" & n)
      Print #f, "#define " & FormatFunctionDeclaration(r, func, sVarPre & "_NAME_" & n) & " " & r.v(sVarPre & "_NAME_" & n) & "_##ChName()"

      Print #f, "#define " & r.v(sVarPre & "_NAME_" & n) & "_" & _
                r.v(sVarPre & "_PARA_CHANNEL_0") & "() " & _
                sRegPre & "CMPMODIFL = 0x01"

      Print #f, "#define " & r.v(sVarPre & "_NAME_" & n) & "_" & _
                r.v(sVarPre & "_PARA_CHANNEL_1") & "() " & _
                sRegPre & "CMPMODIFL = 0x02"

      Print #f, "#define " & r.v(sVarPre & "_NAME_" & n) & "_" & _
                r.v(sVarPre & "_PARA_CHANNEL_2") & "() " & _
                sRegPre & "CMPMODIFL = 0x04"

      Print #f, "#define " & r.v(sVarPre & "_NAME_" & n) & "_" & _
                r.v(sVarPre & "_PARA_CHANNEL_3") & "() " & _
                sRegPre & "CMPMODIFL = 0x40"

      Print #f, ""
      Print #f, ""
    End If

    '------------------------------------------------------------------------------------------------
    '------------------------------------------------------------------------------------------------
    ' ResetStatusBit macro
    '------------------------------------------------------------------------------------------------
    '------------------------------------------------------------------------------------------------
    n = "ResetStatusBit"
    If (r.v(sVarPre & "_USE_" & n) = 1) Then
      Print #f, FormatFunctionHeader(r, func, sVarPre & "_NAME_" & n)
      Print #f, "#define " & FormatFunctionDeclaration(r, func, sVarPre & "_NAME_" & n) & " " & r.v(sVarPre & "_NAME_" & n) & "_##ChName()"

      Print #f, "#define " & r.v(sVarPre & "_NAME_" & n) & "_" & _
                r.v(sVarPre & "_PARA_CHANNEL_0") & "() " & _
                sRegPre & "CMPMODIFH = 0x01"

      Print #f, "#define " & r.v(sVarPre & "_NAME_" & n) & "_" & _
                r.v(sVarPre & "_PARA_CHANNEL_1") & "() " & _
                sRegPre & "CMPMODIFH = 0x02"

      Print #f, "#define " & r.v(sVarPre & "_NAME_" & n) & "_" & _
                r.v(sVarPre & "_PARA_CHANNEL_2") & "() " & _
                sRegPre & "CMPMODIFH = 0x04"

      Print #f, "#define " & r.v(sVarPre & "_NAME_" & n) & "_" & _
                r.v(sVarPre & "_PARA_CHANNEL_3") & "() " & _
                sRegPre & "CMPMODIFH = 0x40"

      Print #f, ""
      Print #f, ""
    End If

    '------------------------------------------------------------------------------------------------
    '------------------------------------------------------------------------------------------------
    ' CCx_GetTmrPeriod macro
    '------------------------------------------------------------------------------------------------
    '------------------------------------------------------------------------------------------------
    n = "GetTmrPeriod"
    If (r.v("CAN_USE_WriteCANAddress_I") = 1) Then
      Print #f, FormatFunctionHeader(r, func, "CAN_NAME_WriteCANAddress_I")
      Print #f, "#define " & FormatFunctionDeclaration(r, func, "CAN_NAME_WriteCANAddress_I") & " " & _
                r.v("CAN_NAME_WriteCANAddress_I") & "_##TimerNr()"
      If (r.v("MAIN_COMPILER") = "Keil") Then
        Print #f, "#define " & r.v("CAN_NAME_WriteCANAddress_I") & "_" & _
                  r.v(sVarPre & "_PARA_TIMER_" & iTmr_12) & "() " & _
                  sRegPre & "T12PRLH"
        Print #f, "#define " & r.v("CAN_NAME_WriteCANAddress_I") & "_" & _
                  r.v(sVarPre & "_PARA_TIMER_" & iTmr_13) & "() " & _
                  sRegPre & "T13PRLH"
      Else
        Print #f, "#define " & r.v("CAN_NAME_WriteCANAddress_I") & "_" & _
                  r.v(sVarPre & "_PARA_TIMER_" & iTmr_12) & "() " & _
                  "(uword)((" & sRegPre & "T12PRH << 8) + " & sRegPre & "T12PRL)"
        Print #f, "#define " & r.v("CAN_NAME_WriteCANAddress_I") & "_" & _
                  r.v(sVarPre & "_PARA_TIMER_" & iTmr_13) & "() " & _
                  "(uword)((" & sRegPre & "T13PRH << 8) + " & sRegPre & "T13PRL)"
      End If
      Print #f, ""
      Print #f, ""
    End If

    '------------------------------------------------------------------------------------------------
    ' Interrupt Vectors
    '------------------------------------------------------------------------------------------------
    Print #f, SECTION_INTERRUPT_VECTORS
    Print #f, ""  'DAvE interrupt vector definitions
    If (Not IsCpuTypeOK(r)) Then
        n = "NodeI0"
        If (r.v(sVarPre & "_USE_" & n) = 1) Then
            Print #f, "#define " & sVarPre & "_" & n & "_INT " & IntNumber(&H53)
        End If

        n = "NodeI1"
        If (r.v(sVarPre & "_USE_" & n) = 1) Then
            Print #f, "#define " & sVarPre & "_" & n & "_INT " & IntNumber(&H5B)
        End If
        n = "NodeI2"
        If (r.v(sVarPre & "_USE_" & n) = 1) Then
            Print #f, "#define " & sVarPre & "_" & n & "_INT " & IntNumber(&H63)
        End If
        n = "NodeI3"
        If (r.v(sVarPre & "_USE_" & n) = 1) Then
            Print #f, "#define " & sVarPre & "_" & n & "_INT " & IntNumber(&H6B)
        End If
    Else
        Print #f, FormatComments(0, 0, "", "", "Shared interrupt vector definitions are defined in SHARED_INT.H")
    End If
    
    Print #f, ""
    Print #f, ""
    Print #f, uc.GetUserCode("(" & sVarPre & "_Header,10)", 0)
    Print #f, ""
    Print #f, ""
    Print #f, "#endif  // ifndef _" & StripExtension(r.v(sVarPre & "_HFILE")) & "_H_"

    'close file
    Close f
    
    CAPCOMxGenerateH = True
    Exit Function
    
CAPCOMxGenerateHError:
    Close f
    Exit Function
End Function

'*****************************************************************************
'Description:
'        This function generates code for ISR NodeIx.
'-----------------------------------------------------------------------------
'Parameters:
'        f
'        r                reference to the Registers object
'        vIndex           a parameter
'        iNode            number of node
'        n                ISR-name
'        uc               user code variable
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
'Sub GenerateCodeForNodes(f As Variant, r As ProjectData, vIndex As Variant, iNode As Integer, n As String, uc As UserCode)
'    Dim sVarPre As String
'    Dim sRegPre As String
'    Dim s       As String
'
'    Dim sfrset As Integer
'
'    sfrset = 0
'
'    sVarPre = "CCU" & vIndex
'    sRegPre = sVarPre & "_"
'
'    If (r.v(sRegPre & "INPL_INPCC60") = iNode) Then
'        s = "if ISL_ICC60R"
'        If (r.v(sRegPre & "IENL_ENCC60R") = 1) Then
'
'            sfrset = 1
'              Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, SST2);", "", "", "switch to page 3")
'              Print #f, ""
'
'            Print #f, "  if(CCU6_ISL & 0x01)   //" & s
'            Print #f, "  {"
'            s = "    //capture, compare match rising edge detection an channel 0" & vbCrLf
'            Print #f, "" & s
'            s = "clear flag ISL_ICC60R"
'            Print #f, FormatCodeStatemente(4, "SFR_PAGE(" & CCU_PAGE_NAME & "0, noSST);", "", "", "switch to page 0")
'            Print #f, ""
'            Print #f, "    CCU6_ISRL = 0x01;             //" & s
'            Print #f, ""
'            Print #f, uc.GetUserCode("(" & n & ",10)", 4)
'            Print #f, ""
'            Print #f, "  }"
'            Print #f, ""
'        End If
'        s = "if ISL_ICC60F"
'        If (r.v(sRegPre & "IENL_ENCC60F") = 1) Then
'
'            If (sfrset = 1) Then
'              Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, noSST);", "", "", "switch to page 3")
'            Else
'              Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, SST2);", "", "", "switch to page 3")
'              sfrset = 1
'            End If
'              Print #f, ""
'
'            Print #f, "  if(CCU6_ISL & 0x02)   //" & s
'            Print #f, "  {"
'            s = "    //capture, compare match faling edge detection an channel 0" & vbCrLf
'            Print #f, "" & s
'            s = "clear flag IS_ICC60F"
'            Print #f, FormatCodeStatemente(4, "SFR_PAGE(" & CCU_PAGE_NAME & "0, noSST);", "", "", "switch to page 0")
'            Print #f, ""
'            Print #f, "    CCU6_ISRL = 0x02;  //" & s
'            Print #f, ""
'            Print #f, uc.GetUserCode("(" & n & ",11)", 4)
'            Print #f, ""
'            Print #f, "  }"
'            Print #f, ""
'        End If
'    End If
'
'    If (r.v(sRegPre & "INPL_INPCC61") = iNode) Then
'        s = "if ISL_ICC61R"
'        If (r.v(sRegPre & "IENL_ENCC61R") = 1) Then
'            If (sfrset = 1) Then
'              Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, noSST);", "", "", "switch to page 3")
'            Else
'              Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, SST2);", "", "", "switch to page 3")
'              sfrset = 1
'            End If
'              Print #f, ""
'            Print #f, "  if(CCU6_ISL & 0x04)   //" & s
'            Print #f, "  {"
'            s = "    //capture, compare match rising edge detection an channel 1" & vbCrLf
'            Print #f, "" & s
'            s = "clear flag ISL_ICC61R"
'            Print #f, FormatCodeStatemente(4, "SFR_PAGE(" & CCU_PAGE_NAME & "0, noSST);", "", "", "switch to page 0")
'            Print #f, ""
'            Print #f, "    CCU6_ISRL = 0x04;  //" & s
'            Print #f, ""
'            Print #f, uc.GetUserCode("(" & n & ",12)", 4)
'            Print #f, ""
'            Print #f, "  }"
'            Print #f, ""
'        End If
'        s = "if ISL_ICC61F"
'        If (r.v(sRegPre & "IENL_ENCC61F") = 1) Then
'            If (sfrset = 1) Then
'              Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, noSST);", "", "", "switch to page 3")
'            Else
'              Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, SST2);", "", "", "switch to page 3")
'              sfrset = 1
'            End If
'              Print #f, ""
'            Print #f, "  if(CCU6_ISL & 0x08)   //" & s
'            Print #f, "  {"
'            s = "    //capture, compare match faling edge detection an channel 1" & vbCrLf
'            Print #f, "" & s
'            s = "clear flag ISL_ICC61F"
'            Print #f, FormatCodeStatemente(4, "SFR_PAGE(" & CCU_PAGE_NAME & "0, noSST);", "", "", "switch to page 0")
'            Print #f, ""
'            Print #f, "    CCU6_ISRL = 0x08;  //" & s
'            Print #f, ""
'            Print #f, uc.GetUserCode("(" & n & ",13)", 4)
'            Print #f, ""
'            Print #f, "  }"
'            Print #f, ""
'        End If
'    End If
'
'    If (r.v(sRegPre & "INPL_INPCC62") = iNode) Then
'        s = "if ISL_ICC62R"
'        If (r.v(sRegPre & "IENL_ENCC62R") = 1) Then
'            If (sfrset = 1) Then
'              Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, noSST);", "", "", "switch to page 3")
'            Else
'              Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, SST2);", "", "", "switch to page 3")
'              sfrset = 1
'            End If
'              Print #f, ""
'            Print #f, "  if(CCU6_ISL & 0x10)   //" & s
'            Print #f, "  {"
'            s = "    //capture, compare match rising edge detection an channel 2" & vbCrLf
'            Print #f, "" & s
'            s = "clear flag ISL_ICC62R"
'            Print #f, FormatCodeStatemente(4, "SFR_PAGE(" & CCU_PAGE_NAME & "0, noSST);", "", "", "switch to page 0")
'            Print #f, ""
'            Print #f, "    CCU6_ISRL = 0x10;  //" & s
'            Print #f, ""
'            Print #f, uc.GetUserCode("(" & n & ",14)", 4)
'            Print #f, ""
'            Print #f, "  }"
'            Print #f, ""
'        End If
'        s = "if ISL_ICC62F"
'        If (r.v(sRegPre & "IENL_ENCC62F") = 1) Then
'            If (sfrset = 1) Then
'              Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, noSST);", "", "", "switch to page 3")
'            Else
'              Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, SST2);", "", "", "switch to page 3")
'              sfrset = 1
'            End If
'              Print #f, ""
'            Print #f, "  if(CCU6_ISL & 0x20)   //" & s
'            Print #f, "  {"
'            s = "    //capture, compare match faling edge detection an channel 2" & vbCrLf
'            Print #f, "" & s
'            s = "clear flag ISL_ICC62F"
'            Print #f, FormatCodeStatemente(4, "SFR_PAGE(" & CCU_PAGE_NAME & "0, noSST);", "", "", "switch to page 0")
'            Print #f, ""
'            Print #f, "    CCU6_ISRL = 0x20;  //" & s
'            Print #f, ""
'            Print #f, uc.GetUserCode("(" & n & ",15)", 4)
'            Print #f, ""
'            Print #f, "  }"
'            Print #f, ""
'        End If
'    End If
'
'    If (r.v(sRegPre & "INPH_INPT12") = iNode) Then
'        s = "if ISL_T12OM"
'        If (r.v(sRegPre & "IENL_ENT12OM") = 1) Then
'            If (sfrset = 1) Then
'              Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, noSST);", "", "", "switch to page 3")
'            Else
'              Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, SST2);", "", "", "switch to page 3")
'              sfrset = 1
'            End If
'              Print #f, ""
'            Print #f, "  if(CCU6_ISL & 0x40)   //" & s
'            Print #f, "  {"
'            s = "    //timer T12 one match detection" & vbCrLf
'            Print #f, "" & s
'            s = "clear flag ISL_T12OM"
'            Print #f, FormatCodeStatemente(4, "SFR_PAGE(" & CCU_PAGE_NAME & "0, noSST);", "", "", "switch to page 0")
'            Print #f, ""
'            Print #f, "    CCU6_ISRL = 0x40;  //" & s
'            Print #f, ""
'            Print #f, uc.GetUserCode("(" & n & ",16)", 4)
'            Print #f, ""
'            Print #f, "  }"
'            Print #f, ""
'        End If
'        s = "if ISL_T12PM"
'        If (r.v(sRegPre & "IENL_ENT12PM") = 1) Then
'            If (sfrset = 1) Then
'              Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, noSST);", "", "", "switch to page 3")
'            Else
'              Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, SST2);", "", "", "switch to page 3")
'              sfrset = 1
'            End If
'              Print #f, ""
'            Print #f, "  if(CCU6_ISL & 0x80)   //" & s
'            Print #f, "  {"
'            s = "    //timer T12 period match detection" & vbCrLf
'            Print #f, "" & s
'            s = "clear flag ISL_T12PM"
'            Print #f, FormatCodeStatemente(4, "SFR_PAGE(" & CCU_PAGE_NAME & "0, noSST);", "", "", "switch to page 0")
'            Print #f, ""
'            Print #f, "    CCU6_ISRL = 0x80;  //" & s
'            Print #f, ""
'            Print #f, uc.GetUserCode("(" & n & ",17)", 4)
'            Print #f, ""
'            Print #f, "  }"
'            Print #f, ""
'        End If
'    End If
'
'    If (r.v(sRegPre & "INPH_INPT13") = iNode) Then
'        s = "if ISH_T13CM"
'        If (r.v(sRegPre & "IENH_ENT13CM") = 1) Then
'            If (sfrset = 1) Then
'              Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, noSST);", "", "", "switch to page 3")
'            Else
'              Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, SST2);", "", "", "switch to page 3")
'              sfrset = 1
'            End If
'              Print #f, ""
'            Print #f, "  if(CCU6_ISH & 0x01)   //" & s
'            Print #f, "  {"
'            s = "    //timer T13 compare match detection" & vbCrLf
'            Print #f, "" & s
'            s = "clear flag ISH_T13CM"
'            Print #f, FormatCodeStatemente(4, "SFR_PAGE(" & CCU_PAGE_NAME & "0, noSST);", "", "", "switch to page 0")
'            Print #f, ""
'            Print #f, "    CCU6_ISRH = 0x01;  //" & s
'            Print #f, ""
'            Print #f, uc.GetUserCode("(" & n & ",18)", 4)
'            Print #f, ""
'            Print #f, "  }"
'            Print #f, ""
'        End If
'        s = "if ISH_T13PM"
'        If (r.v(sRegPre & "IENH_ENT13PM") = 1) Then
'            If (sfrset = 1) Then
'              Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, noSST);", "", "", "switch to page 3")
'            Else
'              Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, SST2);", "", "", "switch to page 3")
'              sfrset = 1
'            End If
'              Print #f, ""
'            Print #f, "  if(CCU6_ISH & 0x02)   //" & s
'            Print #f, "  {"
'            s = "    //timer T13 period match detection" & vbCrLf
'            Print #f, "" & s
'            s = "clear flag ISH_T13PM"
'            Print #f, FormatCodeStatemente(4, "SFR_PAGE(" & CCU_PAGE_NAME & "0, noSST);", "", "", "switch to page 0")
'            Print #f, ""
'            Print #f, "    CCU6_ISRH = 0x02;  //" & s
'            Print #f, ""
'            Print #f, uc.GetUserCode("(" & n & ",19)", 4)
'            Print #f, ""
'            Print #f, "  }"
'            Print #f, ""
'        End If
'    End If
'
'    If (r.v(sRegPre & "INPH_INPERR") = iNode) Then
'        s = "if ISH_TRPF"
'        If (r.v(sRegPre & "IENH_ENTRPF") = 1) Then
'            If (sfrset = 1) Then
'              Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, noSST);", "", "", "switch to page 3")
'            Else
'              Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, SST2);", "", "", "switch to page 3")
'              sfrset = 1
'            End If
'              Print #f, ""
'            Print #f, "  if(CCU6_ISH & 0x04)   //" & s
'            Print #f, "  {"
'            s = "    //trap detection" & vbCrLf
'            Print #f, "" & s
'            s = "clear flag ISH_TRPF"
'            Print #f, FormatCodeStatemente(4, "SFR_PAGE(" & CCU_PAGE_NAME & "0, noSST);", "", "", "switch to page 0")
'            Print #f, ""
'            Print #f, "    CCU6_ISRH = 0x04;  //" & s
'            Print #f, ""
'            Print #f, uc.GetUserCode("(" & n & ",20)", 4)
'            Print #f, ""
'            Print #f, "  }"
'            Print #f, ""
'        End If
'        s = "if ISH_WHE"
'        If (r.v(sRegPre & "IENH_ENWHE") = 1) Then
'            If (sfrset = 1) Then
'              Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, noSST);", "", "", "switch to page 3")
'            Else
'              Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, SST2);", "", "", "switch to page 3")
'              sfrset = 1
'            End If
'              Print #f, ""
'            Print #f, "  if(CCU6_ISH & 0x20)   //" & s
'            Print #f, "  {"
'            s = "    //wrong hall event detection" & vbCrLf
'            Print #f, "" & s
'            s = "clear flag ISH_WHE"
'            Print #f, FormatCodeStatemente(4, "SFR_PAGE(" & CCU_PAGE_NAME & "0, noSST);", "", "", "switch to page 0")
'            Print #f, ""
'            Print #f, "    CCU6_ISRH = 0x20;  //" & s
'            Print #f, ""
'            Print #f, uc.GetUserCode("(" & n & ",21)", 4)
'            Print #f, ""
'            Print #f, "  }"
'            Print #f, ""
'        End If
'        s = "if ISH_CCU_IDLE"
'        If (r.v(sRegPre & "IENH_ENIDLE") = 1) Then
'            If (sfrset = 1) Then
'              Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, noSST);", "", "", "switch to page 3")
'            Else
'              Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, SST2);", "", "", "switch to page 3")
'              sfrset = 1
'            End If
'              Print #f, ""
'            Print #f, "  if(CCU6_ISH & 0x40)   //" & s
'            Print #f, "  {"
'            s = "    //idle state detection" & vbCrLf
'            Print #f, "" & s
'            s = "clear flag ISH_CCU_IDLE"
'            Print #f, FormatCodeStatemente(4, "SFR_PAGE(" & CCU_PAGE_NAME & "0, noSST);", "", "", "switch to page 0")
'            Print #f, ""
'            Print #f, "    CCU6_ISRH = 0x40;  //" & s
'            Print #f, ""
'            Print #f, uc.GetUserCode("(" & n & ",22)", 4)
'            Print #f, ""
'            Print #f, "  }"
'            Print #f, ""
'        End If
'    End If
'    If (r.v(sRegPre & "INPL_INPCHE") = iNode) Then
'        s = "if ISH_CHE"
'        If (r.v(sRegPre & "IENH_ENCHE") = 1) Then
'            If (sfrset = 1) Then
'              Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, noSST);", "", "", "switch to page 3")
'            Else
'              Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, SST2);", "", "", "switch to page 3")
'              sfrset = 1
'            End If
'              Print #f, ""
'            Print #f, "  if(CCU6_ISH & 0x10)   //" & s
'            Print #f, "  {"
'            s = "    //correct hall event detection" & vbCrLf
'            Print #f, "" & s
'            s = "clear flag ISH_CHE"
'            Print #f, FormatCodeStatemente(4, "SFR_PAGE(" & CCU_PAGE_NAME & "0, noSST);", "", "", "switch to page 0")
'            Print #f, ""
'            Print #f, "    CCU6_ISRH = 0x10;  //" & s
'            Print #f, ""
'            Print #f, uc.GetUserCode("(" & n & ",23)", 4)
'            Print #f, ""
'            Print #f, "  }"
'            Print #f, ""
'        End If
'        s = "if ISH_SSTR"
'        If (r.v(sRegPre & "IENH_ENSTR") = 1) Then
'            If (sfrset = 1) Then
'              Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, noSST);", "", "", "switch to page 3")
'            Else
'              Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, SST2);", "", "", "switch to page 3")
'              sfrset = 1
'            End If
'              Print #f, ""
'            Print #f, "  if(CCU6_ISH & 0x80)   //" & s
'            Print #f, "  {"
'            s = "    // shadow transfer has taken place." & vbCrLf
'            Print #f, "" & s
'            s = "clear flag ISH_SSTR"
'            Print #f, FormatCodeStatemente(4, "SFR_PAGE(" & CCU_PAGE_NAME & "0, noSST);", "", "", "switch to page 0")
'            Print #f, ""
'            Print #f, "    CCU6_ISRH = 0x80;  //" & s
'            Print #f, ""
'            Print #f, uc.GetUserCode("(" & n & ",24)", 4)
'            Print #f, ""
'            Print #f, "  }"
'            Print #f, ""
'        End If
'    End If
'
'        If (sfrset = 1) Then
'             Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "0, RST2);", "", "", "restore the old CCU page")
'             Print #f, ""
'             sfrset = 0
'        End If
'
'End Sub
'



''Sub GenerateCodeForNodes(f As Variant, r As ProjectData, vIndex As Variant, iNode As Integer, n As String, uc As UserCode)
''
''    Dim sVarPre As String
''    Dim sRegPre As String
''    Dim s       As String
''    Dim sfrset As Integer
''    sfrset = 0
''    sVarPre = "CCU" & vIndex
''    sRegPre = sVarPre & "_"
''
''    If (r.v(sRegPre & "INPL_INPCC60") = iNode) Then
''        s = "if ISL_ICC60R"
''        If (r.v(sRegPre & "IENL_ENCC60R") = 1) Then
''            sfrset = 1
''              'Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, SST2);", "", "", "switch to page 3")
''               Call GenerateCodeForSST(f, r, iNode)
''              Print #f, ""
''            Print #f, "  if(CCU6_ISL & 0x01)   //" & s
''            Print #f, "  {"
''            s = "    //capture, compare match rising edge detection an channel 0" & vbCrLf
''            Print #f, "" & s
''            s = "clear flag ISL_ICC60R"
''            Print #f, FormatCodeStatemente(4, "SFR_PAGE(" & CCU_PAGE_NAME & "0, noSST);", "", "", "switch to page 0")
''            Print #f, ""
''            Print #f, "    CCU6_ISRL = 0x01;             //" & s
''            Print #f, ""
''            Print #f, uc.GetUserCode("(" & n & ",10)", 4)
''            Print #f, ""
''            Print #f, "  }"
''            Print #f, ""
''        End If
''        s = "if ISL_ICC60F"
''        If (r.v(sRegPre & "IENL_ENCC60F") = 1) Then
''            If (sfrset = 1) Then
''              Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, noSST);", "", "", "switch to page 3")
''            Else
''              'Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, SST2);", "", "", "switch to page 3")
''              Call GenerateCodeForSST(f, r, iNode)
''              sfrset = 1
''            End If
''              Print #f, ""
''            Print #f, "  if(CCU6_ISL & 0x02)   //" & s
''            Print #f, "  {"
''            s = "    //capture, compare match faling edge detection an channel 0" & vbCrLf
''            Print #f, "" & s
''            s = "clear flag IS_ICC60F"
''            Print #f, FormatCodeStatemente(4, "SFR_PAGE(" & CCU_PAGE_NAME & "0, noSST);", "", "", "switch to page 0")
''            Print #f, ""
''            Print #f, "    CCU6_ISRL = 0x02;  //" & s
''            Print #f, ""
''            Print #f, uc.GetUserCode("(" & n & ",11)", 4)
''            Print #f, ""
''            Print #f, "  }"
''            Print #f, ""
''        End If
''    End If
''
''    If (r.v(sRegPre & "INPL_INPCC61") = iNode) Then
''        s = "if ISL_ICC61R"
''        If (r.v(sRegPre & "IENL_ENCC61R") = 1) Then
''            If (sfrset = 1) Then
''              Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, noSST);", "", "", "switch to page 3")
''            Else
''              'Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, SST2);", "", "", "switch to page 3")
''              Call GenerateCodeForSST(f, r, iNode)
''              sfrset = 1
''            End If
''              Print #f, ""
''            Print #f, "  if(CCU6_ISL & 0x04)   //" & s
''            Print #f, "  {"
''            s = "    //capture, compare match rising edge detection an channel 1" & vbCrLf
''            Print #f, "" & s
''            s = "clear flag ISL_ICC61R"
''            Print #f, FormatCodeStatemente(4, "SFR_PAGE(" & CCU_PAGE_NAME & "0, noSST);", "", "", "switch to page 0")
''            Print #f, ""
''            Print #f, "    CCU6_ISRL = 0x04;  //" & s
''            Print #f, ""
''            Print #f, uc.GetUserCode("(" & n & ",12)", 4)
''            Print #f, ""
''            Print #f, "  }"
''            Print #f, ""
''        End If
''        s = "if ISL_ICC61F"
''        If (r.v(sRegPre & "IENL_ENCC61F") = 1) Then
''            If (sfrset = 1) Then
''              Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, noSST);", "", "", "switch to page 3")
''            Else
''              'Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, SST2);", "", "", "switch to page 3")
''              Call GenerateCodeForSST(f, r, iNode)
''              sfrset = 1
''            End If
''              Print #f, ""
''            Print #f, "  if(CCU6_ISL & 0x08)   //" & s
''            Print #f, "  {"
''            s = "    //capture, compare match faling edge detection an channel 1" & vbCrLf
''            Print #f, "" & s
''            s = "clear flag ISL_ICC61F"
''            Print #f, FormatCodeStatemente(4, "SFR_PAGE(" & CCU_PAGE_NAME & "0, noSST);", "", "", "switch to page 0")
''            Print #f, ""
''            Print #f, "    CCU6_ISRL = 0x08;  //" & s
''            Print #f, ""
''            Print #f, uc.GetUserCode("(" & n & ",13)", 4)
''            Print #f, ""
''            Print #f, "  }"
''            Print #f, ""
''        End If
''    End If
''
''    If (r.v(sRegPre & "INPL_INPCC62") = iNode) Then
''        s = "if ISL_ICC62R"
''        If (r.v(sRegPre & "IENL_ENCC62R") = 1) Then
''            If (sfrset = 1) Then
''              Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, noSST);", "", "", "switch to page 3")
''            Else
''              'Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, SST2);", "", "", "switch to page 3")
''              Call GenerateCodeForSST(f, r, iNode)
''              sfrset = 1
''            End If
''              Print #f, ""
''            Print #f, "  if(CCU6_ISL & 0x10)   //" & s
''            Print #f, "  {"
''            s = "    //capture, compare match rising edge detection an channel 2" & vbCrLf
''            Print #f, "" & s
''            s = "clear flag ISL_ICC62R"
''            Print #f, FormatCodeStatemente(4, "SFR_PAGE(" & CCU_PAGE_NAME & "0, noSST);", "", "", "switch to page 0")
''            Print #f, ""
''            Print #f, "    CCU6_ISRL = 0x10;  //" & s
''            Print #f, ""
''            Print #f, uc.GetUserCode("(" & n & ",14)", 4)
''            Print #f, ""
''            Print #f, "  }"
''            Print #f, ""
''        End If
''        s = "if ISL_ICC62F"
''        If (r.v(sRegPre & "IENL_ENCC62F") = 1) Then
''            If (sfrset = 1) Then
''              Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, noSST);", "", "", "switch to page 3")
''            Else
''              'Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, SST2);", "", "", "switch to page 3")
''              Call GenerateCodeForSST(f, r, 0)
''              sfrset = 1
''            End If
''              Print #f, ""
''            Print #f, "  if(CCU6_ISL & 0x20)   //" & s
''            Print #f, "  {"
''            s = "    //capture, compare match faling edge detection an channel 2" & vbCrLf
''            Print #f, "" & s
''            s = "clear flag ISL_ICC62F"
''            Print #f, FormatCodeStatemente(4, "SFR_PAGE(" & CCU_PAGE_NAME & "0, noSST);", "", "", "switch to page 0")
''            Print #f, ""
''            Print #f, "    CCU6_ISRL = 0x20;  //" & s
''            Print #f, ""
''            Print #f, uc.GetUserCode("(" & n & ",15)", 4)
''            Print #f, ""
''            Print #f, "  }"
''            Print #f, ""
''        End If
''    End If
''
''    If (r.v(sRegPre & "INPH_INPT12") = iNode) Then
''        s = "if ISL_T12OM"
''        If (r.v(sRegPre & "IENL_ENT12OM") = 1) Then
''            If (sfrset = 1) Then
''              Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, noSST);", "", "", "switch to page 3")
''            Else
''              'Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, SST2);", "", "", "switch to page 3")
''              Call GenerateCodeForSST(f, r, iNode)
''              sfrset = 1
''            End If
''              Print #f, ""
''            Print #f, "  if(CCU6_ISL & 0x40)   //" & s
''            Print #f, "  {"
''            s = "    //timer T12 one match detection" & vbCrLf
''            Print #f, "" & s
''            s = "clear flag ISL_T12OM"
''            Print #f, FormatCodeStatemente(4, "SFR_PAGE(" & CCU_PAGE_NAME & "0, noSST);", "", "", "switch to page 0")
''            Print #f, ""
''            Print #f, "    CCU6_ISRL = 0x40;  //" & s
''            Print #f, ""
''            Print #f, uc.GetUserCode("(" & n & ",16)", 4)
''            Print #f, ""
''            Print #f, "  }"
''            Print #f, ""
''        End If
''        s = "if ISL_T12PM"
''        If (r.v(sRegPre & "IENL_ENT12PM") = 1) Then
''            If (sfrset = 1) Then
''              Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, noSST);", "", "", "switch to page 3")
''            Else
''              'Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, SST2);", "", "", "switch to page 3")
''              Call GenerateCodeForSST(f, r, iNode)
''              sfrset = 1
''            End If
''              Print #f, ""
''            Print #f, "  if(CCU6_ISL & 0x80)   //" & s
''            Print #f, "  {"
''            s = "    //timer T12 period match detection" & vbCrLf
''            Print #f, "" & s
''            s = "clear flag ISL_T12PM"
''            Print #f, FormatCodeStatemente(4, "SFR_PAGE(" & CCU_PAGE_NAME & "0, noSST);", "", "", "switch to page 0")
''            Print #f, ""
''            Print #f, "    CCU6_ISRL = 0x80;  //" & s
''            Print #f, ""
''            Print #f, uc.GetUserCode("(" & n & ",17)", 4)
''            Print #f, ""
''            Print #f, "  }"
''            Print #f, ""
''        End If
''    End If
''
''    If (r.v(sRegPre & "INPH_INPT13") = iNode) Then
''        s = "if ISH_T13CM"
''        If (r.v(sRegPre & "IENH_ENT13CM") = 1) Then
''            If (sfrset = 1) Then
''              Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, noSST);", "", "", "switch to page 3")
''            Else
''              'Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, SST2);", "", "", "switch to page 3")
''              Call GenerateCodeForSST(f, r, iNode)
''              sfrset = 1
''            End If
''              Print #f, ""
''            Print #f, "  if(CCU6_ISH & 0x01)   //" & s
''            Print #f, "  {"
''            s = "    //timer T13 compare match detection" & vbCrLf
''            Print #f, "" & s
''            s = "clear flag ISH_T13CM"
''            Print #f, FormatCodeStatemente(4, "SFR_PAGE(" & CCU_PAGE_NAME & "0, noSST);", "", "", "switch to page 0")
''            Print #f, ""
''            Print #f, "    CCU6_ISRH = 0x01;  //" & s
''            Print #f, ""
''            Print #f, uc.GetUserCode("(" & n & ",18)", 4)
''            Print #f, ""
''            Print #f, "  }"
''            Print #f, ""
''        End If
''        s = "if ISH_T13PM"
''        If (r.v(sRegPre & "IENH_ENT13PM") = 1) Then
''            If (sfrset = 1) Then
''              Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, noSST);", "", "", "switch to page 3")
''            Else
''              'Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, SST2);", "", "", "switch to page 3")
''              Call GenerateCodeForSST(f, r, iNode)
''              sfrset = 1
''            End If
''              Print #f, ""
''            Print #f, "  if(CCU6_ISH & 0x02)   //" & s
''            Print #f, "  {"
''            s = "    //timer T13 period match detection" & vbCrLf
''            Print #f, "" & s
''            s = "clear flag ISH_T13PM"
''            Print #f, FormatCodeStatemente(4, "SFR_PAGE(" & CCU_PAGE_NAME & "0, noSST);", "", "", "switch to page 0")
''            Print #f, ""
''            Print #f, "    CCU6_ISRH = 0x02;  //" & s
''            Print #f, ""
''            Print #f, uc.GetUserCode("(" & n & ",19)", 4)
''            Print #f, ""
''            Print #f, "  }"
''            Print #f, ""
''        End If
''    End If
''
''    If (r.v(sRegPre & "INPH_INPERR") = iNode) Then
''        s = "if ISH_TRPF"
''        If (r.v(sRegPre & "IENH_ENTRPF") = 1) Then
''            If (sfrset = 1) Then
''              Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, noSST);", "", "", "switch to page 3")
''            Else
''              'Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, SST2);", "", "", "switch to page 3")
''              Call GenerateCodeForSST(f, r, iNode)
''              sfrset = 1
''            End If
''              Print #f, ""
''            Print #f, "  if(CCU6_ISH & 0x04)   //" & s
''            Print #f, "  {"
''            s = "    //trap detection" & vbCrLf
''            Print #f, "" & s
''            s = "clear flag ISH_TRPF"
''            Print #f, FormatCodeStatemente(4, "SFR_PAGE(" & CCU_PAGE_NAME & "0, noSST);", "", "", "switch to page 0")
''            Print #f, ""
''            Print #f, "    CCU6_ISRH = 0x04;  //" & s
''            Print #f, ""
''            Print #f, uc.GetUserCode("(" & n & ",20)", 4)
''            Print #f, ""
''            Print #f, "  }"
''            Print #f, ""
''        End If
''        s = "if ISH_WHE"
''        If (r.v(sRegPre & "IENH_ENWHE") = 1) Then
''            If (sfrset = 1) Then
''              Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, noSST);", "", "", "switch to page 3")
''            Else
''              'Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, SST2);", "", "", "switch to page 3")
''              Call GenerateCodeForSST(f, r, iNode)
''              sfrset = 1
''            End If
''              Print #f, ""
''            Print #f, "  if(CCU6_ISH & 0x20)   //" & s
''            Print #f, "  {"
''            s = "    //wrong hall event detection" & vbCrLf
''            Print #f, "" & s
''            s = "clear flag ISH_WHE"
''            Print #f, FormatCodeStatemente(4, "SFR_PAGE(" & CCU_PAGE_NAME & "0, noSST);", "", "", "switch to page 0")
''            Print #f, ""
''            Print #f, "    CCU6_ISRH = 0x20;  //" & s
''            Print #f, ""
''            Print #f, uc.GetUserCode("(" & n & ",21)", 4)
''            Print #f, ""
''            Print #f, "  }"
''            Print #f, ""
''        End If
''        s = "if ISH_CCU_IDLE"
''        If (r.v(sRegPre & "IENH_ENIDLE") = 1) Then
''            If (sfrset = 1) Then
''              Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, noSST);", "", "", "switch to page 3")
''            Else
''              'Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, SST2);", "", "", "switch to page 3")
''              Call GenerateCodeForSST(f, r, iNode)
''              sfrset = 1
''            End If
''              Print #f, ""
''            Print #f, "  if(CCU6_ISH & 0x40)   //" & s
''            Print #f, "  {"
''            s = "    //idle state detection" & vbCrLf
''            Print #f, "" & s
''            s = "clear flag ISH_CCU_IDLE"
''            Print #f, FormatCodeStatemente(4, "SFR_PAGE(" & CCU_PAGE_NAME & "0, noSST);", "", "", "switch to page 0")
''            Print #f, ""
''            Print #f, "    CCU6_ISRH = 0x40;  //" & s
''            Print #f, ""
''            Print #f, uc.GetUserCode("(" & n & ",22)", 4)
''            Print #f, ""
''            Print #f, "  }"
''            Print #f, ""
''        End If
''    End If
''    If (r.v(sRegPre & "INPL_INPCHE") = iNode) Then
''        s = "if ISH_CHE"
''        If (r.v(sRegPre & "IENH_ENCHE") = 1) Then
''            If (sfrset = 1) Then
''              Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, noSST);", "", "", "switch to page 3")
''            Else
''              'Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, SST2);", "", "", "switch to page 3")
''              Call GenerateCodeForSST(f, r, iNode)
''              sfrset = 1
''            End If
''              Print #f, ""
''            Print #f, "  if(CCU6_ISH & 0x10)   //" & s
''            Print #f, "  {"
''            s = "    //correct hall event detection" & vbCrLf
''            Print #f, "" & s
''            s = "clear flag ISH_CHE"
''            Print #f, FormatCodeStatemente(4, "SFR_PAGE(" & CCU_PAGE_NAME & "0, noSST);", "", "", "switch to page 0")
''            Print #f, ""
''            Print #f, "    CCU6_ISRH = 0x10;  //" & s
''            Print #f, ""
''            Print #f, uc.GetUserCode("(" & n & ",23)", 4)
''            Print #f, ""
''            Print #f, "  }"
''            Print #f, ""
''        End If
''        s = "if ISH_SSTR"
''        If (r.v(sRegPre & "IENH_ENSTR") = 1) Then
''            If (sfrset = 1) Then
''              Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, noSST);", "", "", "switch to page 3")
''            Else
''              'Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, SST2);", "", "", "switch to page 3")
''              Call GenerateCodeForSST(f, r, iNode)
''              sfrset = 1
''            End If
''              Print #f, ""
''            Print #f, "  if(CCU6_ISH & 0x80)   //" & s
''            Print #f, "  {"
''            s = "    // shadow transfer has taken place." & vbCrLf
''            Print #f, "" & s
''            s = "clear flag ISH_SSTR"
''            Print #f, FormatCodeStatemente(4, "SFR_PAGE(" & CCU_PAGE_NAME & "0, noSST);", "", "", "switch to page 0")
''            Print #f, ""
''            Print #f, "    CCU6_ISRH = 0x80;  //" & s
''            Print #f, ""
''            Print #f, uc.GetUserCode("(" & n & ",24)", 4)
''            Print #f, ""
''            Print #f, "  }"
''            Print #f, ""
''        End If
''    End If
''        If (sfrset = 1) Then
''             'Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "0, RST2);", "", "", "restore the old CCU page")
''             If (iNode = 0) Then
''                 If ((r.v(CORE_PREFIX & "IPH1_PCCIP0H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP0H") + r.v(CORE_PREFIX & "IP1_PCCIP0")) = 0) Then
''                    Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, RST0);", "", "", "restore the old CCU page")
''                 ElseIf ((r.v(CORE_PREFIX & "IPH1_PCCIP0H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP0H") + r.v(CORE_PREFIX & "IP1_PCCIP0")) = 1) Then
''                    Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, RST1);", "", "", "restore the old CCU page")
''                 ElseIf ((r.v(CORE_PREFIX & "IPH1_PCCIP0H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP0H") + r.v(CORE_PREFIX & "IP1_PCCIP0")) = 2) Then
''                    Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, RST2);", "", "", "restore the old CCU page")
''                 ElseIf ((r.v(CORE_PREFIX & "IPH1_PCCIP0H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP0H") + r.v(CORE_PREFIX & "IP1_PCCIP0")) = 3) Then
''                    Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, RST3);", "", "", "restore the old CCU page")
''                 End If
''             ElseIf (iNode = 1) Then
''                 If ((r.v(CORE_PREFIX & "IPH1_PCCIP1H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP1H") + r.v(CORE_PREFIX & "IP1_PCCIP1")) = 0) Then
''                    Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, RST0);", "", "", "restore the old CCU page")
''                 ElseIf ((r.v(CORE_PREFIX & "IPH1_PCCIP1H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP1H") + r.v(CORE_PREFIX & "IP1_PCCIP1")) = 1) Then
''                    Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, RST1);", "", "", "restore the old CCU page")
''                 ElseIf ((r.v(CORE_PREFIX & "IPH1_PCCIP1H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP1H") + r.v(CORE_PREFIX & "IP1_PCCIP1")) = 2) Then
''                    Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, RST2);", "", "", "restore the old CCU page")
''                 ElseIf ((r.v(CORE_PREFIX & "IPH1_PCCIP1H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP1H") + r.v(CORE_PREFIX & "IP1_PCCIP1")) = 3) Then
''                    Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, RST3);", "", "", "restore the old CCU page")
''                 End If
''             ElseIf (iNode = 2) Then
''                 If ((r.v(CORE_PREFIX & "IPH1_PCCIP2H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP2H") + r.v(CORE_PREFIX & "IP1_PCCIP2")) = 0) Then
''                    Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, RST0);", "", "", "restore the old CCU page")
''                 ElseIf ((r.v(CORE_PREFIX & "IPH1_PCCIP2H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP2H") + r.v(CORE_PREFIX & "IP1_PCCIP2")) = 1) Then
''                    Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, RST1);", "", "", "restore the old CCU page")
''                 ElseIf ((r.v(CORE_PREFIX & "IPH1_PCCIP2H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP2H") + r.v(CORE_PREFIX & "IP1_PCCIP2")) = 2) Then
''                    Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, RST2);", "", "", "restore the old CCU page")
''                 ElseIf ((r.v(CORE_PREFIX & "IPH1_PCCIP2H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP2H") + r.v(CORE_PREFIX & "IP1_PCCIP2")) = 3) Then
''                    Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, RST3);", "", "", "restore the old CCU page")
''                 End If
''            ElseIf (iNode = 3) Then
''                 If ((r.v(CORE_PREFIX & "IPH1_PCCIP3H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP3H") + r.v(CORE_PREFIX & "IP1_PCCIP3")) = 0) Then
''                    Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, RST0);", "", "", "restore the old CCU page")
''                 ElseIf ((r.v(CORE_PREFIX & "IPH1_PCCIP3H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP3H") + r.v(CORE_PREFIX & "IP1_PCCIP3")) = 1) Then
''                    Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, RST1);", "", "", "restore the old CCU page")
''                 ElseIf ((r.v(CORE_PREFIX & "IPH1_PCCIP3H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP3H") + r.v(CORE_PREFIX & "IP1_PCCIP3")) = 2) Then
''                    Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, RST2);", "", "", "restore the old CCU page")
''                 ElseIf ((r.v(CORE_PREFIX & "IPH1_PCCIP3H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP3H") + r.v(CORE_PREFIX & "IP1_PCCIP3")) = 3) Then
''                    Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, RST3);", "", "", "restore the old CCU page")
''                 End If
''            End If
''            Print #f, ""
''             sfrset = 0
''        End If
'' End Sub


'''*****************************************************************************
'''Description:
'''        This function generates code for storage page depending on interrupt priority.
'''-----------------------------------------------------------------------------
'''Parameters:
'''        f
'''        r                reference to the Registers object
'''        iNode            number of node
'''-----------------------------------------------------------------------------
'''Returns:
'''        True            on successfull operation
'''        False           else
'''*****************************************************************************
''Sub GenerateCodeForSST(f As Variant, r As ProjectData, iNode As Integer)
''     If (iNode = 0) Then
''         If ((r.v(CORE_PREFIX & "IPH1_PCCIP0H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP0H") + r.v(CORE_PREFIX & "IP1_PCCIP0")) = 0) Then
''            Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, SST0);", "", "", "switch to page 3")
''         ElseIf ((r.v(CORE_PREFIX & "IPH1_PCCIP0H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP0H") + r.v(CORE_PREFIX & "IP1_PCCIP0")) = 1) Then
''            Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, SST1);", "", "", "switch to page 3")
''         ElseIf ((r.v(CORE_PREFIX & "IPH1_PCCIP0H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP0H") + r.v(CORE_PREFIX & "IP1_PCCIP0")) = 2) Then
''            Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, SST2);", "", "", "switch to page 3")
''         ElseIf ((r.v(CORE_PREFIX & "IPH1_PCCIP0H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP0H") + r.v(CORE_PREFIX & "IP1_PCCIP0")) = 3) Then
''             Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, SST3);", "", "", "switch to page 3")
''         End If
''     ElseIf (iNode = 1) Then
''         If ((r.v(CORE_PREFIX & "IPH1_PCCIP1H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP1H") + r.v(CORE_PREFIX & "IP1_PCCIP1")) = 0) Then
''            Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, SST0);", "", "", "switch to page 3")
''         ElseIf ((r.v(CORE_PREFIX & "IPH1_PCCIP1H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP1H") + r.v(CORE_PREFIX & "IP1_PCCIP1")) = 1) Then
''            Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, SST1);", "", "", "switch to page 3")
''         ElseIf ((r.v(CORE_PREFIX & "IPH1_PCCIP1H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP1H") + r.v(CORE_PREFIX & "IP1_PCCIP1")) = 2) Then
''            Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, SST2);", "", "", "switch to page 3")
''         ElseIf ((r.v(CORE_PREFIX & "IPH1_PCCIP1H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP1H") + r.v(CORE_PREFIX & "IP1_PCCIP1")) = 3) Then
''            Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, SST3);", "", "", "switch to page 3")
''         End If
''     ElseIf (iNode = 2) Then
''         If ((r.v(CORE_PREFIX & "IPH1_PCCIP2H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP2H") + r.v(CORE_PREFIX & "IP1_PCCIP2")) = 0) Then
''            Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, SST0);", "", "", "switch to page 3")
''         ElseIf ((r.v(CORE_PREFIX & "IPH1_PCCIP2H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP2H") + r.v(CORE_PREFIX & "IP1_PCCIP2")) = 1) Then
''            Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, SST1);", "", "", "switch to page 3")
''         ElseIf ((r.v(CORE_PREFIX & "IPH1_PCCIP2H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP2H") + r.v(CORE_PREFIX & "IP1_PCCIP2")) = 2) Then
''            Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, SST2);", "", "", "switch to page 3")
''         ElseIf ((r.v(CORE_PREFIX & "IPH1_PCCIP2H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP2H") + r.v(CORE_PREFIX & "IP1_PCCIP2")) = 3) Then
''            Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, SST3);", "", "", "switch to page 3")
''         End If
''    ElseIf (iNode = 3) Then
''         If ((r.v(CORE_PREFIX & "IPH1_PCCIP3H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP3H") + r.v(CORE_PREFIX & "IP1_PCCIP3")) = 0) Then
''            Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, SST0);", "", "", "switch to page 3")
''         ElseIf ((r.v(CORE_PREFIX & "IPH1_PCCIP3H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP3H") + r.v(CORE_PREFIX & "IP1_PCCIP3")) = 1) Then
''            Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, SST1);", "", "", "switch to page 3")
''         ElseIf ((r.v(CORE_PREFIX & "IPH1_PCCIP3H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP3H") + r.v(CORE_PREFIX & "IP1_PCCIP3")) = 2) Then
''            Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, SST2);", "", "", "switch to page 3")
''         ElseIf ((r.v(CORE_PREFIX & "IPH1_PCCIP3H") * 2 ^ r.v(CORE_PREFIX & "IPH1_PCCIP3H") + r.v(CORE_PREFIX & "IP1_PCCIP3")) = 3) Then
''            Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & CCU_PAGE_NAME & "3, SST3);", "", "", "switch to page 3")
''         End If
''    End If
''End Sub

