Attribute VB_Name = "Module1"
'#Uses "..\include\Const.inc"
'#Uses "..\include\Global.inc"
'#Uses "..\include\Format.inc"
'#Uses "..\classes\FunctionClass.cls
'#Uses "..\include\Port.inc"
'#Uses "Include.inc"
'#Uses "..\classes\PortPin.cls"
Option Explicit
'*****************************************************************************
' Module:
'        IR
'-----------------------------------------------------------------------------
' Description:
'        This file contains functions for generating code for the
'        module 'IR'.
'
'-----------------------------------------------------------------------------
' History:
'
'        Rev. Author         Date        Description
'        ---------------------------------------------------------------------
'        0.1  Radhish        27-10-04    initial version
'        0.2  Radhish        29-11-04    code added in IR_Init function
'        0.3  radhish        27-12-04    Module name appended before register names
'       0.4   radhish        03-02-05    code for NMI added
'        0.5  radhish        08-02-05    Codegeneration part for EXINT0 and 1 modified(ISR part also)
'*****************************************************************************


'*****************************************************************************
'Description:
'        This functions initiates the code generation for the IR 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

    ' write files IR.h
    If (r.v("IR_USE_Init")) Then
        If (Not IRGenerateH(r, vIndex)) Then Exit Function
                   If (Not r.AddFile(r.s("IR_HFILE"), "H")) Then Exit Function
    End If

    ' write file IR.c
    If (r.v("IR_USE_Init")) Then
        If (Not IRGenerateC(r, vIndex)) Then Exit Function
                   If (Not r.AddFile(r.s("IR_CFILE"), "C")) Then Exit Function
    End If

        
    StartGenerateCode = True
    Exit Function
    
StartGenerateCodeError:
    Errorbox("Code generation for IR failed", Error$)
    Exit Function
End Function


'*****************************************************************************
'Description:
'        Generates the code for the IR.c file.
'-----------------------------------------------------------------------------
'Parameters:
'        r                reference to the Registers object
'        vIndex           a parameter
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Function IRGenerateC(r As ProjectData, vIndex As Variant) As Boolean
    On Error GoTo IRGenerateCError
    
    Dim iInt As Integer
    Dim f As Variant
    Dim v As Variant
    Dim d As String
    Dim k As Integer
    Dim dc As DAvECollection
    Dim uc As UserCode
    Dim func As FunctionClass
    
    IRGenerateC = False

    Set dc = ObjectCollection("MODULENAMES")
    Set uc = New UserCode
    Set func = New FunctionClass

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

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

    'open IR.c
    f = FreeFile
    Open CStr(StripFilenameAndExtension(r.LoadedFile)) & "\" & r.v("IR_CFILE") For Output As f
    
    '------------------------------------------------------------------------------------------------
    ' module header
    '------------------------------------------------------------------------------------------------
    d = FormatModuleDescription(GetModuleHeaderC("IR"))
    Print #f, Rtf.GenerateModuleHeader(DefGetValue("ProductVersion"), StripPath(r.LoadedFile), dc("IR").ModuleDescription, r.v("IR_CFILE"), r.v("MAIN_CPU_TYPE"), r.v("MAIN_COMPILER"), d)
          
            Print #f, uc.GetUserCode("(IR_General,1)", 0)   'USER CODE for application specific descriptions'
            Print #f, ""
            Print #f, Rtf.GenerateNote((r.v("IR_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("(IR_General,2)", 0)
            Print #f, ""
            Print #f, ""
            Print #f, SECTION_MACROS
            Print #f, ""  'DAvE local macro definitions'
            Print #f, uc.GetUserCode("(IR_General,3)", 0)
            Print #f, ""
            Print #f, ""
            Print #f, SECTION_DEFINES
            Print #f, ""  'DAvE local #define definitions'
            Print #f, uc.GetUserCode("(IR_General,4)", 0)
            Print #f, ""
            Print #f, ""
            Print #f, SECTION_TYPEDEFS
            Print #f, ""  'DAvE type defintions'
            Print #f, uc.GetUserCode("(IR_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("(IR_General,6)", 0)
            Print #f, ""
            Print #f, ""
            Print #f, SECTION_GLOBAL_VARIABLES
            Print #f, ""  'DAvE definitions of global variables'
            Print #f, uc.GetUserCode("(IR_General,7)", 0)
            Print #f, ""
            Print #f, ""
            Print #f, SECTION_EXTERNAL_PROTOTYPES
            Print #f, ""  'DAvE external declarations of imported functions'
            Print #f, uc.GetUserCode("(IR_General,8)", 0)
            Print #f, ""
            Print #f, ""
            Print #f, SECTION_LOCAL_PROTOTYPES
            Print #f, ""  'DAvE declarations of internal local functions'
            Print #f, uc.GetUserCode("(IR_General,9)", 0)
            Print #f, ""
            Print #f, ""
    '------------------------------------------------------------------------------------------------
    ' IR_Init function
    '------------------------------------------------------------------------------------------------
    If (r.v("IR_USE_Init") = 1) Then
    Print #f, FormatFunctionHeader(r, func, "IR_NAME_Init")
            Print #f, uc.GetUserCode("(IR_Init,1)", 0)     'USER CODE for application specific descriptions'
            Print #f, ""
                      '<--                     max. 78 characters                                -->'
            Print #f, FormatFunctionDeclaration(r, func, "IR_NAME_Init")
            Print #f, "{"
            Print #f, uc.GetUserCode("(IR_Init,2)", 2)
            Print #f, ""
            
            
            Print #f, FormatComments(2, 0, "", "", "------ Port initialization for Interrupt module-----")
           Print #f, ""
           
           If (r.v("MuxFor_EXINT0_0") > 0) Then
                d = "Pin P0.5 (input)"
                Print #f, FormatComments(2, 1, "", "", d)
                d = "- used as External interrupt 0 input  pin  "
                Print #f, FormatComments(2, 1, "", "", d)
                Print #f, ""
          
           End If
           '***************************** Added by jag on 31/01/06 ***************************************
            If (r.v("MuxFor_EXINT0_1") > 0) Then
                d = "Pin P1.4 (input)"
                Print #f, FormatComments(2, 1, "", "", d)
                d = "- used as External interrupt 0 input  pin  "
                Print #f, FormatComments(2, 1, "", "", d)
                Print #f, ""
          
           End If
          '***************************** Added by jag on 31/01/06 ***************************************

          If (r.v("MuxFor_EXINT1") > 0) Then
                d = "Pin P2.0 (input)"
                Print #f, FormatComments(2, 1, "", "", d)
                d = "- used as External interrupt1 input pin  "
                Print #f, FormatComments(2, 1, "", "", d)
                Print #f, ""
          End If

              If (r.v("MuxFor_EXINT2") > 0) Then
                    d = "Pin P2.1 (input)"
                    Print #f, FormatComments(2, 1, "", "", d)
                    d = "- used as External interrupt2 input pin  "
                    Print #f, FormatComments(2, 1, "", "", d)
                    Print #f, ""
              End If
              If (r.v("MuxFor_EXINT3") > 0) Then
                    d = "Pin P1.1 (input)"
                    Print #f, FormatComments(2, 1, "", "", d)
                    d = "- used as External interrupt3 input pin  "
                    Print #f, FormatComments(2, 1, "", "", d)
                    Print #f, ""
              End If
                    
              If (r.v("MuxFor_EXINT4") > 0) Then
                    d = "Pin P3.7 (input)"
                    Print #f, FormatComments(2, 1, "", "", d)
                    d = "- used as External interrupt4 input pin  "
                    Print #f, FormatComments(2, 1, "", "", d)
                    Print #f, ""
              End If
              If (r.v("MuxFor_EXINT5") > 0) Then
                    d = "Pin P1.5 (input)"
                    Print #f, FormatComments(2, 1, "", "", d)
                    d = "- used as External interrupt5 input pin  "
                    Print #f, FormatComments(2, 1, "", "", d)
                    Print #f, ""
              End If
                    
             If (r.v("MuxFor_EXINT6") > 0) Then
                    d = "Pin P1.6 (input)"
                    Print #f, FormatComments(2, 1, "", "", d)
                    d = "- used as External interrupt6 input pin  "
                    Print #f, FormatComments(2, 1, "", "", d)
                    Print #f, ""
             End If
      Print #f, FormatComments(2, 0, "", "", "---------- Non Maskable Interrupt configuration ----------")
      Print #f, ""
      If (r.v(SCU_PREFIX & "NMICON_NMIWDT") = 1) Then
            Print #f, FormatComments(2, 1, "", "", " NMIWDT enabled")
       Else
            Print #f, FormatComments(2, 1, "", "", " NMIWDT disabled")
       End If
        If (r.v(SCU_PREFIX & "NMICON_NMIPLL") = 1) Then
            Print #f, FormatComments(2, 1, "", "", " NMIPLL enabled")
       Else
            Print #f, FormatComments(2, 1, "", "", " NMIPLL disabled")
       End If
        If (r.v(SCU_PREFIX & "NMICON_NMIFLASH") = 1) Then
            Print #f, FormatComments(2, 1, "", "", " NMIFLASH enabled")
       Else
            Print #f, FormatComments(2, 1, "", "", " NMIFLASH disabled")
       End If
        If (r.v(SCU_PREFIX & "NMICON_NMIOCDS") = 1) Then
            Print #f, FormatComments(2, 1, "", "", " NMIOCDS enabled")
       Else
            Print #f, FormatComments(2, 1, "", "", " NMIOCDS disabled")
       End If
        If (r.v(SCU_PREFIX & "NMICON_NMIVDD") = 1) Then
            Print #f, FormatComments(2, 1, "", "", " NMIVDD enabled")
       Else
            Print #f, FormatComments(2, 1, "", "", " NMIVDD disabled")
       End If
        If (r.v(SCU_PREFIX & "NMICON_NMIVDDP") = 1) Then
            Print #f, FormatComments(2, 1, "", "", " NMIVDDP enabled")
       Else
            Print #f, FormatComments(2, 1, "", "", " NMIVDDP disabled")
       End If
        If (r.v(SCU_PREFIX & "NMICON_NMIECC") = 1) Then
            Print #f, FormatComments(2, 1, "", "", " NMIECC enabled")
       Else
            Print #f, FormatComments(2, 1, "", "", " NMIECC disabled")
       End If
       
        Print #f, FormatCodeStatemente(2, SCU_PREFIX & "NMICON", "=", FormatTextOutput(r.sfr(SCU_PREFIX & "NMICON"), "H2"), " NMI Control Register ")
       
    For iInt = 0 To 1
            Print #f, FormatComments(2, 1, "", "", "---------- external interrupt " & iInt & " ----------")

      If (r.v(CORE_PREFIX & "IEN0_EX" & iInt) = 1) Then
            Print #f, FormatComments(2, 1, "", "", "enabled")

         
       k = r.v(SCU_PREFIX & "EXICON0_EXINT" & iInt)
        If (k = 0) Then
            Print #f, FormatComments(2, 1, "", "", "Interrupt on falling edge")
'            Print #f, "  " & SfrBitStatement(r, CORE_PREFIX & "TCON_IT" & iInt, 1)

            Print #f, ""
           ElseIf (k = 1) Then
           Print #f, FormatComments(2, 1, "", "", "Interrupt on rising edge")
'           Print #f, "  " & SfrBitStatement(r, CORE_PREFIX & "TCON_IT" & iInt, 1)

             ElseIf (k = 2) Then
           Print #f, FormatComments(2, 1, "", "", "Interrupt on rising and falling edge")
'           Print #f, "  " & SfrBitStatement(r, CORE_PREFIX & "TCON_IT" & iInt, 1)

            
          
             Else
           Print #f, FormatComments(2, 1, "", "", "Bypass the Edge selection")
'           Print #f, "  " & SfrBitStatement(r, CORE_PREFIX & "TCON_IT" & iInt, 0)


          End If
      k = r.v(CORE_PREFIX & "TCON_IT" & iInt)
             If (k = 0) Then
            Print #f, FormatComments(2, 1, "", "", "Low level Triggered")
            Print #f, "  " & SfrBitStatement(r, CORE_PREFIX & "TCON_IT" & iInt, 0)
            ElseIf (k = 1) Then
            
            Print #f, FormatComments(2, 1, "", "", "falling edge triggered")
            Print #f, "  " & SfrBitStatement(r, CORE_PREFIX & "TCON_IT" & iInt, 1)
            End If
      Else
            Print #f, FormatComments(2, 1, "", "", "disabled")
      End If
            Print #f, ""

    Next iInt
    If (iInt = 2) Then
            Print #f, FormatComments(2, 1, "", "", "---------- external interrupt " & iInt & " ----------")

      If (r.v(CORE_PREFIX & "IEN1_EX" & iInt) = 1) Then
            Print #f, FormatComments(2, 1, "", "", "enabled")

                    
       k = r.v(SCU_PREFIX & "EXICON0_EXINT" & iInt)
        If (k = 0) Then
            Print #f, FormatComments(2, 1, "", "", "Interrupt on falling edge")
        ElseIf (k = 1) Then
            Print #f, FormatComments(2, 1, "", "", "Interrupt on rising edge")
        Else
            Print #f, FormatComments(2, 1, "", "", "Interrupt on rising and falling edge")
        End If
      Else
            Print #f, FormatComments(2, 1, "", "", "disabled")
      End If
            Print #f, ""

   End If
 
      If (r.v(CORE_PREFIX & "IEN1_EXM") = 1) Then
         iInt = 3
         
            Print #f, FormatComments(2, 1, "", "", "enabled")

            
          If (IsAlternatePinFree(r, "EXINT3")) Then
          Print #f, FormatComments(2, 1, "", "", "---------- external interrupt " & iInt & " ----------")

         k = r.v(SCU_PREFIX & "EXICON0_EXINT" & iInt)
'        If (k = 0) Then
'            Print #f, FormatComments(2, 1, "", "", "Interrupt on falling edge")
'
'
'
'           ElseIf (k = 1) Then
'           Print #f, FormatComments(2, 1, "", "", "Interrupt on rising edge")
'
'
'          Else
'           Print #f, FormatComments(2, 1, "", "", "Interrupt on rising and falling edge")
'
'
'
'          End If
          
          If (k = 0) Then
             Print #f, FormatComments(2, 1, "", "", "Interrupt on falling edge")
          ElseIf (k = 1) Then
             Print #f, FormatComments(2, 1, "", "", "Interrupt on rising edge")
          ElseIf (k = 2) Then
             Print #f, FormatComments(2, 1, "", "", "Interrupt on rising and falling edge")
          Else
             Print #f, FormatComments(2, 1, "", "", "disabled")
          End If
          End If
          
         iInt = 4
         If (IsAlternatePinFree(r, "EXINT4")) Then
         Print #f, FormatComments(2, 1, "", "", "---------- external interrupt " & iInt & " ----------")

         k = r.v(SCU_PREFIX & "EXICON1_EXINT" & iInt)
'        If (k = 0) Then
'            Print #f, FormatComments(2, 1, "", "", "Interrupt on falling edge")
'
'
'           ElseIf (k = 1) Then
'           Print #f, FormatComments(2, 1, "", "", "Interrupt on rising edge")
'
'
'          Else
'           Print #f, FormatComments(2, 1, "", "", "Interrupt on rising and falling edge")
'
'
'
'
'          End If
           If (k = 0) Then
              Print #f, FormatComments(2, 1, "", "", "Interrupt on falling edge")
           ElseIf (k = 1) Then
              Print #f, FormatComments(2, 1, "", "", "Interrupt on rising edge")
           ElseIf (k = 2) Then
              Print #f, FormatComments(2, 1, "", "", "Interrupt on rising and falling edge")
           Else
              Print #f, FormatComments(2, 1, "", "", "disabled")
           End If
          End If
          iInt = 5
          If (IsAlternatePinFree(r, "EXINT5")) Then
          Print #f, FormatComments(2, 1, "", "", "---------- external interrupt " & iInt & " ----------")
          k = r.v(SCU_PREFIX & "EXICON1_EXINT" & iInt)
'          If (k = 0) Then
'            Print #f, FormatComments(2, 1, "", "", "Interrupt on falling edge")
'
'
'           ElseIf (k = 1) Then
'           Print #f, FormatComments(2, 1, "", "", "Interrupt on rising edge")
'
'
'          Else
'           Print #f, FormatComments(2, 1, "", "", "Interrupt on rising and falling edge")
'
'
'
'          End If
           If (k = 0) Then
               Print #f, FormatComments(2, 1, "", "", "Interrupt on falling edge")
           ElseIf (k = 1) Then
               Print #f, FormatComments(2, 1, "", "", "Interrupt on rising edge")
           ElseIf (k = 2) Then
               Print #f, FormatComments(2, 1, "", "", "Interrupt on rising and falling edge")
           Else
               Print #f, FormatComments(2, 1, "", "", "disabled")
           End If
          End If
          iInt = 6
        If (IsAlternatePinFree(r, "EXINT6")) Then
        Print #f, FormatComments(2, 1, "", "", "---------- external interrupt " & iInt & " ----------")

        k = r.v(SCU_PREFIX & "EXICON1_EXINT" & iInt)
'        If (k = 0) Then
'            Print #f, FormatComments(2, 1, "", "", "Interrupt on falling edge")
'
'           ElseIf (k = 1) Then
'           Print #f, FormatComments(2, 1, "", "", "Interrupt on rising edge")
'
'           Else
'           Print #f, FormatComments(2, 1, "", "", "Interrupt on rising and falling edge")
'
'
'
'          End If
           If (k = 0) Then
               Print #f, FormatComments(2, 1, "", "", "Interrupt on falling edge")
           ElseIf (k = 1) Then
               Print #f, FormatComments(2, 1, "", "", "Interrupt on rising edge")
           ElseIf (k = 2) Then
               Print #f, FormatComments(2, 1, "", "", "Interrupt on rising and falling edge")
           Else
               Print #f, FormatComments(2, 1, "", "", "disabled")
           End If
          End If
      Else
      Print #f, FormatComments(2, 1, "", "", "---------- external interrupt 3 to 6----------")
            Print #f, FormatComments(2, 1, "", "", "disabled")
      End If
            Print #f, ""
        v = 0
        v = v + r.sfr(CORE_PREFIX & "IEN0")
        v = v And &H7F                              ' This is to avoid EA bit enable in INT.C coz it should be enabled at the end of whole initialization in main.c
        'Print #f, FormatCodeStatemente(2, CORE_PREFIX & "IEN0", "=", FormatTextOutput(r.sfr(CORE_PREFIX & "IEN0"), "H2"), " interrupt enable  register 0")
        Print #f, FormatCodeStatemente(2, CORE_PREFIX & "IEN0", "=", FormatTextOutput(v, "H2"), " interrupt enable  register 0")
        Print #f, FormatCodeStatemente(2, CORE_PREFIX & "IEN1", "=", FormatTextOutput(r.sfr(CORE_PREFIX & "IEN1"), "H2"), " interrupt enable register 1")
        'Print #f, FormatCodeStatemente(2, CORE_PREFIX & "TCON", "=", FormatTextOutput(r.sfr(CORE_PREFIX & "TCON"), "H2"), " timer0/1 control register ")
        Print #f, FormatCodeStatemente(2, SCU_PREFIX & "EXICON0", "=", FormatTextOutput(r.sfr(SCU_PREFIX & "EXICON0"), "H2"), "external interrupt trigger select register 0")
        Print #f, FormatCodeStatemente(2, SCU_PREFIX & "EXICON1", "=", FormatTextOutput(r.sfr(SCU_PREFIX & "EXICON1"), "H2"), "external interrupt trigger select register 1")
        
       '***************************** Added by jag on 31/01/06 ***************************************
        Print #f, FormatCodeStatemente(2, CORE_PREFIX & "MODPISEL", "=", FormatTextOutput(r.sfr(CORE_PREFIX & "MODPISEL"), "H2"), "peripheral input select register ")
       '***************************** Added by jag on 31/01/06 ***************************************
            Print #f, uc.GetUserCode("(IR_Init,3)", 2)
            Print #f, ""
            Print #f, "} " & END_OF_FUNCTION & r.v("IR_NAME_Init")
            Print #f, ""
            Print #f, ""
           '*************************************** Added by jag on 1/02/06*********************************
            If ((r.v("T21_Interrupt_Select") = 1) And (r.v(CORE_PREFIX & "IEN1_EX2") = 1)) Then
               Print #f, FormatCommentsForSource(2, 1, "*********************************************************************************")
               Print #f, FormatCommentsForSource(2, 1, "Note : Timer21 interrupt is selected." & _
                         "The ISR for the External Interrupt 2 is generated in T21.C file.")
               Print #f, FormatCommentsForSource(2, 1, "*********************************************************************************")
               Print #f, ""
            End If
           '*************************************** Added by jag on 1/02/06*********************************
    End If
    '------------------------------------------------------------------------------------------------
  ' IR_IsrNMI function
    '------------------------------------------------------------------------------------------------
'      If (r.v("IR_USE_IsrNMI") = 1) Then
'        Print #f, FormatFunctionHeader(r, func, "IR_NAME_IsrNMI")
'            Print #f, uc.GetUserCode("(IR_IsrNMI,1)", 0) 'USER CODE for application specific descriptions'
'            Print #f, ""
'                      '<--                     max. 78 characters                                -->'
'            Print #f, IsrDeclaration(r, r.v("IR_NAME_IsrNMI"), "NMIINT")
'            Print #f, "{"
'             Print #f, ""
'
'             If (r.v(SCU_PREFIX & "NMICON_NMIWDT") = 1) Then
'
'Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, SST2);", "", "", "switch to page0")
'                Print #f, ""
'             Print #f, "  if( NMISR & 0x01 )" & "// if NMIWDT request flag is set"
'             Print #f, "  {"
'
'               d = SCU_PREFIX & "NMISR_FNMIWDT"
'             If (d <> "") Then
'                        ' the interrupt request flag must be cleared by software
'            Print #f, "      " & SfrBitStatement(r, d, 0)
'            Else
'                 ' the interrupt request flag is automatically cleared by hardware
'            End If
'
'            Print #f, ""
'            Print #f, " " & uc.GetUserCode("(IR_IsrNMI,2)", 2)
'             Print #f, ""
''Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, RST2);", "", "", "restore the old SCU page")
'
'             Print #f, "   }"
'            End If
'              If (r.v(SCU_PREFIX & "NMICON_NMIPLL") = 1) Then
'                 If (r.v(SCU_PREFIX & "NMICON_NMIWDT") = 1) Then
'                    Print #f, ""
'                 Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, noSST);", "", "", "switch to page0 with out saving")
'                 Else
'                    Print #f, ""
'                Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, SST2);", "", "", "switch to page0")
'              End If
'                 Print #f, ""
'             Print #f, "  if( NMISR & 0x02 )" & "// if NMIPLL request flag is set"
'             Print #f, "  {"
'
'               d = SCU_PREFIX & "NMISR_FNMIPLL"
'             If (d <> "") Then
'                        ' the interrupt request flag must be cleared by software
'            Print #f, "     " & SfrBitStatement(r, d, 0)
'            Else
'                 ' the interrupt request flag is automatically cleared by hardware
'            End If
'
'            Print #f, ""
'            Print #f, uc.GetUserCode("(IR_IsrNMI,3)", 2)
'           Print #f, ""
''Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, RST2);", "", "", "restore the old SCU page")
'
'            Print #f, "   }"
'            End If
'              If (r.v(SCU_PREFIX & "NMICON_NMIFLASH") = 1) Then
'                   If ((r.v(SCU_PREFIX & "NMICON_NMIWDT") = 1) Or (r.v(SCU_PREFIX & "NMICON_NMIPLL") = 1)) Then
'                 Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, noSST);", "", "", "switch to page0 with out saving")
'                 Else
'                Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, SST2);", "", "", "switch to page0")
'              End If
'                 Print #f, ""
'             Print #f, "  if( NMISR & 0x04 )" & "// if NMIFLASH request flag is set"
'             Print #f, "  {"
'
'               d = SCU_PREFIX & "NMISR_FNMIFLASH"
'             If (d <> "") Then
'                        ' the interrupt request flag must be cleared by software
'            Print #f, "      " & SfrBitStatement(r, d, 0)
'            Else
'                 ' the interrupt request flag is automatically cleared by hardware
'            End If
'
'            Print #f, ""
'            Print #f, uc.GetUserCode("(IR_IsrNMI,4)", 2)
'           Print #f, ""
''Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, RST2);", "", "", "restore the old SCU page")
'
'            Print #f, "   }"
'            End If
'              If (r.v(SCU_PREFIX & "NMICON_NMIOCDS") = 1) Then
'
'    If ((r.v(SCU_PREFIX & "NMICON_NMIWDT") = 1) Or (r.v(SCU_PREFIX & "NMICON_NMIPLL") = 1) Or (r.v(SCU_PREFIX & "NMICON_NMIFLASH") = 1)) Then
'                 Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, noSST);", "", "", "switch to page0 with out saving")
'                 Else
'                Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, SST2);", "", "", "switch to page0")
'              End If
'                 Print #f, ""
'             Print #f, "   if( NMISR & 0x08 )" & "// if NMIOCDS request flag is set"
'             Print #f, "   {"
'
'               d = SCU_PREFIX & "NMISR_FNMIOCDS"
'             If (d <> "") Then
'                        ' the interrupt request flag must be cleared by software
'            Print #f, "   " & SfrBitStatement(r, d, 0)
'            Else
'                 ' the interrupt request flag is automatically cleared by hardware
'            End If
'
'            Print #f, ""
'            Print #f, uc.GetUserCode("(IR_IsrNMI,5)", 2)
'             Print #f, ""
''Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, RST2);", "", "", "restore the old SCU page")
'
'              Print #f, "   }"
'            End If
'              If (r.v(SCU_PREFIX & "NMICON_NMIVDD") = 1) Then
'
' If ((r.v(SCU_PREFIX & "NMICON_NMIWDT") = 1) Or (r.v(SCU_PREFIX & "NMICON_NMIPLL") = 1) Or (r.v(SCU_PREFIX & "NMICON_NMIFLASH") = 1) Or (r.v(SCU_PREFIX & "NMICON_NMIOCDS") = 1)) Then
'                 Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, noSST);", "", "", "switch to page0 with out saving")
'                 Else
'                Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, SST2);", "", "", "switch to page0")
'              End If
'                 Print #f, ""
'             Print #f, "   if( NMISR & 0x10 )" & "// if NMIVDD request flag is set"
'             Print #f, "   {"
'
'               d = SCU_PREFIX & "NMISR_FNMIVDD"
'             If (d <> "") Then
'                        ' the interrupt request flag must be cleared by software
'            Print #f, "      " & SfrBitStatement(r, d, 0)
'            Else
'                 ' the interrupt request flag is automatically cleared by hardware
'            End If
'
'            Print #f, ""
'            Print #f, uc.GetUserCode("(IR_IsrNMI,6)", 2)
'             Print #f, ""
''             Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, RST2);", "", "", "restore the old SCU page")
'
'             Print #f, "   }"
'            End If
'              If (r.v(SCU_PREFIX & "NMICON_NMIVDDP") = 1) Then
' If ((r.v(SCU_PREFIX & "NMICON_NMIWDT") = 1) Or (r.v(SCU_PREFIX & "NMICON_NMIPLL") = 1) Or (r.v(SCU_PREFIX & "NMICON_NMIFLASH") = 1) Or (r.v(SCU_PREFIX & "NMICON_NMIOCDS") = 1) Or (r.v(SCU_PREFIX & "NMICON_NMIVDD") = 1)) Then
'                 Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, noSST);", "", "", "switch to page0 with out saving")
'                 Else
'                Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, SST2);", "", "", "switch to page0")
'              End If
'                 Print #f, ""
'             Print #f, "  if( NMISR & 0x20 )" & "// if NMIVDDP request flag is set"
'             Print #f, "  {"
'
'               d = SCU_PREFIX & "NMISR_FNMIVDDP"
'             If (d <> "") Then
'                        ' the interrupt request flag must be cleared by software
'            Print #f, "      " & SfrBitStatement(r, d, 0)
'            Else
'                 ' the interrupt request flag is automatically cleared by hardware
'            End If
'
'            Print #f, ""
'            Print #f, uc.GetUserCode("(IR_IsrNMI,7)", 2)
'             Print #f, ""
''             Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, RST2);", "", "", "restore the old SCU page")
'
'             Print #f, "   }"
'            End If
'              If (r.v(SCU_PREFIX & "NMICON_NMIECC") = 1) Then
'
' If ((r.v(SCU_PREFIX & "NMICON_NMIWDT") = 1) Or (r.v(SCU_PREFIX & "NMICON_NMIPLL") = 1) Or (r.v(SCU_PREFIX & "NMICON_NMIFLASH") = 1) Or (r.v(SCU_PREFIX & "NMICON_NMIOCDS") = 1) Or (r.v(SCU_PREFIX & "NMICON_NMIVDD") = 1) Or (r.v(SCU_PREFIX & "NMICON_NMIVDDP") = 1)) Then
'                 Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, noSST);", "", "", "switch to page0 with out saving")
'                 Else
'                Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, SST2);", "", "", "switch to page0")
'              End If
'                 Print #f, ""
'             Print #f, "   if( NMISR & 0x40 )" & "// if NMIECC request flag is set"
'             Print #f, "   {"
'
'               d = SCU_PREFIX & "NMISR_FNMIECC"
'             If (d <> "") Then
'                        ' the interrupt request flag must be cleared by software
'            Print #f, "      " & SfrBitStatement(r, d, 0)
'            Else
'                 ' the interrupt request flag is automatically cleared by hardware
'            End If
'
'              Print #f, ""
'            Print #f, uc.GetUserCode("(IR_IsrNMI,8)", 2)
'             Print #f, ""
'
'              Print #f, "   }"
'            End If
'
'            Print #f, ""
'        Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, RST2);", "", "", "restore the old SCU page")
'
''            Print #f, uc.GetUserCode("(IR_IsrNMI,2)", 2)
'            Print #f, ""
'            Print #f, "} " & END_OF_FUNCTION & r.v("IR_NAME_IsrNMI")
'            Print #f, ""
'            Print #f, ""
'        End If
            
If (r.v("IR_USE_IsrNMI") = 1) Then
        
   If (r.v("ISR_CHOICE") = 1) Then
        Print #f, FormatFunctionHeader(r, func, "IR_NAME_IsrNMI")
        Print #f, uc.GetUserCode("(IR_IsrNMI,1)", 0) 'USER CODE for application specific descriptions'
        Print #f, ""
                     '<--                     max. 78 characters                                -->'
        Print #f, IsrDeclaration(r, r.v("IR_NAME_IsrNMI"), "NMIINT")
        Print #f, "{"
        Print #f, ""
        
        Print #f, " " & uc.GetUserCode("(IR_IsrNMI,2)", 2)
        Print #f, ""
'        Print #f, ""
'        Print #f, FormatCodeStatemente(2, "_push_(SYSCON0);", "", "", "")
'        Print #f, FormatCodeStatemente(2, "RESET_RMAP();", "", "", "")
'        Print #f, ""
 
 
        
'        Print #f, FormatCodeStatemente(2, "STR_PAGE(" & SCU_PAGE_NAME & "0, _su);", "", "", "push current SCU page and switch to page0")
'        Print #f, ""
        Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, noSST);", "", "", "switch to page0 without saving")
        Print #f, ""
 
 
        If (r.v(SCU_PREFIX & "NMICON_NMIWDT") = 1) Then
'            Print #f, FormatCodeStatemente(2, "STR_PAGE(" & SCU_PAGE_NAME & "0, _su);", "", "", "push current SCU page and switch to page0")
'            Print #f, ""
            Print #f, "  if( NMISR & 0x01 )" & "// if NMIWDT request flag is set"
            Print #f, "  {"
            d = SCU_PREFIX & "NMISR_FNMIWDT"
            If (d <> "") Then
                     ' the interrupt request flag must be cleared by software
                Print #f, "      " & SfrBitStatement(r, d, 0)
            Else
                 ' the interrupt request flag is automatically cleared by hardware
            End If
            Print #f, ""
            Print #f, " " & uc.GetUserCode("(IR_IsrNMI,3)", 2)
            Print #f, ""
' Print #f, FormatCodeStatemente(2, "RST_PAGE(_su);", "", "", "restore the old SCU page")
            Print #f, "   }"
        End If
        If (r.v(SCU_PREFIX & "NMICON_NMIPLL") = 1) Then
'             If (r.v(SCU_PREFIX & "NMICON_NMIWDT") = 1) Then
'                  Print #f, ""
'                  Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, noSST);", "", "", "switch to page0 with out saving")
'             Else
'                 Print #f, ""
'                 Print #f, FormatCodeStatemente(2, "STR_PAGE(" & SCU_PAGE_NAME & "0, _su);", "", "", "push current SCU page and switch to page0")
'             End If
                 Print #f, ""
             Print #f, "  if( NMISR & 0x02 )" & "// if NMIPLL request flag is set"
             Print #f, "  {"
             d = SCU_PREFIX & "NMISR_FNMIPLL"
             If (d <> "") Then
                        ' the interrupt request flag must be cleared by software
                Print #f, "     " & SfrBitStatement(r, d, 0)
             Else
                 ' the interrupt request flag is automatically cleared by hardware
             End If
             Print #f, ""
             Print #f, uc.GetUserCode("(IR_IsrNMI,4)", 2)
             Print #f, ""
'Print #f, FormatCodeStatemente(2, "RST_PAGE(_su);", "", "", "restore the old SCU page")
             Print #f, "   }"
        End If
        If (r.v(SCU_PREFIX & "NMICON_NMIFLASH") = 1) Then
'            If ((r.v(SCU_PREFIX & "NMICON_NMIWDT") = 1) Or (r.v(SCU_PREFIX & "NMICON_NMIPLL") = 1)) Then
'                 Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, noSST);", "", "", "switch to page0 with out saving")
'            Else
'                 Print #f, FormatCodeStatemente(2, "STR_PAGE(" & SCU_PAGE_NAME & "0, _su);", "", "", "push current SCU page and switch to page0")
'            End If
            Print #f, ""
            Print #f, "  if( NMISR & 0x04 )" & "// if NMIFLASH request flag is set"
            Print #f, "  {"
            d = SCU_PREFIX & "NMISR_FNMIFLASH"
            If (d <> "") Then
                       ' the interrupt request flag must be cleared by software
               Print #f, "      " & SfrBitStatement(r, d, 0)
            Else
                 ' the interrupt request flag is automatically cleared by hardware
            End If
            Print #f, ""
            Print #f, uc.GetUserCode("(IR_IsrNMI,5)", 2)
            Print #f, ""
'Print #f, FormatCodeStatemente(2, "RST_PAGE(_su);", "", "", "restore the old SCU page")
            Print #f, "   }"
        End If
        If (r.v(SCU_PREFIX & "NMICON_NMIOCDS") = 1) Then
'           If ((r.v(SCU_PREFIX & "NMICON_NMIWDT") = 1) Or (r.v(SCU_PREFIX & "NMICON_NMIPLL") = 1) Or (r.v(SCU_PREFIX & "NMICON_NMIFLASH") = 1)) Then
'              Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, noSST);", "", "", "switch to page0 with out saving")
'           Else
'              Print #f, FormatCodeStatemente(2, "STR_PAGE(" & SCU_PAGE_NAME & "0, _su);", "", "", "push current SCU page and switch to page0")
'           End If
           Print #f, ""
           Print #f, "   if( NMISR & 0x08 )" & "// if NMIOCDS request flag is set"
           Print #f, "   {"
           d = SCU_PREFIX & "NMISR_FNMIOCDS"
           If (d <> "") Then
                       ' the interrupt request flag must be cleared by software
              Print #f, "   " & SfrBitStatement(r, d, 0)
           Else
                ' the interrupt request flag is automatically cleared by hardware
           End If
           Print #f, ""
           Print #f, uc.GetUserCode("(IR_IsrNMI,6)", 2)
           Print #f, ""
'Print #f, FormatCodeStatemente(2, "RST_PAGE(_su);", "", "", "restore the old SCU page")
           Print #f, "   }"
        End If
        If (r.v(SCU_PREFIX & "NMICON_NMIVDD") = 1) Then
'           If ((r.v(SCU_PREFIX & "NMICON_NMIWDT") = 1) Or (r.v(SCU_PREFIX & "NMICON_NMIPLL") = 1) Or (r.v(SCU_PREFIX & "NMICON_NMIFLASH") = 1) Or (r.v(SCU_PREFIX & "NMICON_NMIOCDS") = 1)) Then
'               Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, noSST);", "", "", "switch to page0 with out saving")
'           Else
'               Print #f, FormatCodeStatemente(2, "STR_PAGE(" & SCU_PAGE_NAME & "0, _su);", "", "", "push current SCU page and switch to page0")
'           End If
           Print #f, ""
           Print #f, "   if( NMISR & 0x10 )" & "// if NMIVDD request flag is set"
           Print #f, "   {"
           d = SCU_PREFIX & "NMISR_FNMIVDD"
           If (d <> "") Then
                        ' the interrupt request flag must be cleared by software
              Print #f, "      " & SfrBitStatement(r, d, 0)
           Else
                ' the interrupt request flag is automatically cleared by hardware
           End If
           Print #f, ""
           Print #f, uc.GetUserCode("(IR_IsrNMI,7)", 2)
           Print #f, ""
'          Print #f, FormatCodeStatemente(2, "RST_PAGE(_su);", "", "", "restore the old SCU page")
           Print #f, "   }"
        End If
        If (r.v(SCU_PREFIX & "NMICON_NMIVDDP") = 1) Then
'           If ((r.v(SCU_PREFIX & "NMICON_NMIWDT") = 1) Or (r.v(SCU_PREFIX & "NMICON_NMIPLL") = 1) Or (r.v(SCU_PREFIX & "NMICON_NMIFLASH") = 1) Or (r.v(SCU_PREFIX & "NMICON_NMIOCDS") = 1) Or (r.v(SCU_PREFIX & "NMICON_NMIVDD") = 1)) Then
'               Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, noSST);", "", "", "switch to page0 with out saving")
'           Else
'               Print #f, FormatCodeStatemente(2, "STR_PAGE(" & SCU_PAGE_NAME & "0, _su);", "", "", "push current SCU page and switch to page0")
'           End If
           Print #f, ""
           Print #f, "  if( NMISR & 0x20 )" & "// if NMIVDDP request flag is set"
           Print #f, "  {"
           d = SCU_PREFIX & "NMISR_FNMIVDDP"
           If (d <> "") Then
                     ' the interrupt request flag must be cleared by software
               Print #f, "      " & SfrBitStatement(r, d, 0)
           Else
               ' the interrupt request flag is automatically cleared by hardware
           End If
           Print #f, ""
           Print #f, uc.GetUserCode("(IR_IsrNMI,8)", 2)
           Print #f, ""
'          Print #f, FormatCodeStatemente(2, "RST_PAGE(_su);", "", "", "restore the old SCU page")
           Print #f, "   }"
        End If
        If (r.v(SCU_PREFIX & "NMICON_NMIECC") = 1) Then
'           If ((r.v(SCU_PREFIX & "NMICON_NMIWDT") = 1) Or (r.v(SCU_PREFIX & "NMICON_NMIPLL") = 1) Or (r.v(SCU_PREFIX & "NMICON_NMIFLASH") = 1) Or (r.v(SCU_PREFIX & "NMICON_NMIOCDS") = 1) Or (r.v(SCU_PREFIX & "NMICON_NMIVDD") = 1) Or (r.v(SCU_PREFIX & "NMICON_NMIVDDP") = 1)) Then
'              Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, noSST);", "", "", "switch to page0 with out saving")
'           Else
'              Print #f, FormatCodeStatemente(2, "STR_PAGE(" & SCU_PAGE_NAME & "0, _su);", "", "", "push current SCU page and switch to page0")
'           End If
              Print #f, ""
           Print #f, "   if( NMISR & 0x40 )" & "// if NMIECC request flag is set"
           Print #f, "   {"
           d = SCU_PREFIX & "NMISR_FNMIECC"
           If (d <> "") Then
                     ' the interrupt request flag must be cleared by software
               Print #f, "      " & SfrBitStatement(r, d, 0)
           Else
               ' the interrupt request flag is automatically cleared by hardware
           End If
           Print #f, ""
           Print #f, uc.GetUserCode("(IR_IsrNMI,9)", 2)
           Print #f, ""
           Print #f, "   }"
        End If
        Print #f, ""
        
        'Print #f, FormatCodeStatemente(2, "RST_PAGE(_su);", "", "", "restore the old SCU page")
        'Print #f, FormatCodeStatemente(2, "_pop_(" & SCU_PAGE_NAME & "0);", "", "", "restore the old SCU page")
'       Print #f, uc.GetUserCode("(IR_IsrNMI,2)", 2)
        
'        Print #f, ""
'        Print #f, FormatCodeStatemente(2, "_pop_(SYSCON0);", "", "", "")
'        Print #f, ""
      
        Print #f, ""
        Print #f, "} " & END_OF_FUNCTION & r.v("IR_NAME_IsrNMI")
        Print #f, ""
        Print #f, ""
  ElseIf (r.v("ISR_CHOICE") = 2) Then
        
        Print #f, FormatFunctionHeader(r, func, "IR_NAME_IsrNMI")
        Print #f, uc.GetUserCode("(IR_IsrNMI,1)", 0) 'USER CODE for application specific descriptions'
        Print #f, ""
                     '<--                     max. 78 characters                                -->'
        Print #f, IsrDeclaration(r, r.v("IR_NAME_IsrNMI"), "NMIINT")
        Print #f, "{"
        Print #f, ""
        
        Print #f, " " & uc.GetUserCode("(IR_IsrNMI,2)", 2)
        Print #f, ""
'         Print #f, FormatCodeStatemente(2, "STR_PAGE(" & SCU_PAGE_NAME & "0, _su);", "", "", "push current SCU page and switch to page0")
'         Print #f, ""
          Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, noSST);", "", "", "switch to page0 without saving")
          Print #f, ""
        If (r.v(SCU_PREFIX & "NMICON_NMIWDT") = 1) Then
'            Print #f, FormatCodeStatemente(2, "STR_PAGE(" & SCU_PAGE_NAME & "0, _su);", "", "", "push current SCU page and switch to page0")
'            Print #f, ""
            Print #f, "  if( NMISR & 0x01 )" & "// if NMIWDT request flag is set"
            Print #f, "  {"
            d = SCU_PREFIX & "NMISR_FNMIWDT"
            If (d <> "") Then
                     ' the interrupt request flag must be cleared by software
                Print #f, "      " & SfrBitStatement(r, d, 0)
            Else
                 ' the interrupt request flag is automatically cleared by hardware
            End If
            Print #f, ""
            Print #f, " " & uc.GetUserCode("(IR_IsrNMI,3)", 2)
            Print #f, ""
'Print #f, FormatCodeStatemente(2, "RST_PAGE(_su);", "", "", "restore the old SCU page")
            Print #f, "   }"
        End If
        If (r.v(SCU_PREFIX & "NMICON_NMIPLL") = 1) Then
'             If (r.v(SCU_PREFIX & "NMICON_NMIWDT") = 1) Then
'                  Print #f, ""
'                  Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, noSST);", "", "", "switch to page0 with out saving")
'             Else
'                  Print #f, ""
'                  Print #f, FormatCodeStatemente(2, "STR_PAGE(" & SCU_PAGE_NAME & "0, _su);", "", "", "push current SCU page and switch to page0")
'             End If
                 Print #f, ""
             Print #f, "  if( NMISR & 0x02 )" & "// if NMIPLL request flag is set"
             Print #f, "  {"
             d = SCU_PREFIX & "NMISR_FNMIPLL"
             If (d <> "") Then
                        ' the interrupt request flag must be cleared by software
                Print #f, "     " & SfrBitStatement(r, d, 0)
             Else
                 ' the interrupt request flag is automatically cleared by hardware
             End If
             Print #f, ""
             Print #f, uc.GetUserCode("(IR_IsrNMI,4)", 2)
             Print #f, ""
'Print #f, FormatCodeStatemente(2, "RST_PAGE(_su);", "", "", "restore the old SCU page")
             Print #f, "   }"
        End If
        If (r.v(SCU_PREFIX & "NMICON_NMIFLASH") = 1) Then
'            If ((r.v(SCU_PREFIX & "NMICON_NMIWDT") = 1) Or (r.v(SCU_PREFIX & "NMICON_NMIPLL") = 1)) Then
'                 Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, noSST);", "", "", "switch to page0 with out saving")
'            Else
'                 Print #f, FormatCodeStatemente(2, "STR_PAGE(" & SCU_PAGE_NAME & "0, _su);", "", "", "push current SCU page and switch to page0")
'            End If
            Print #f, ""
            Print #f, "  if( NMISR & 0x04 )" & "// if NMIFLASH request flag is set"
            Print #f, "  {"
            d = SCU_PREFIX & "NMISR_FNMIFLASH"
            If (d <> "") Then
                       ' the interrupt request flag must be cleared by software
               Print #f, "      " & SfrBitStatement(r, d, 0)
            Else
                 ' the interrupt request flag is automatically cleared by hardware
            End If
            Print #f, ""
            Print #f, uc.GetUserCode("(IR_IsrNMI,5)", 2)
            Print #f, ""
'Print #f, FormatCodeStatemente(2, "RST_PAGE(_su);", "", "", "restore the old SCU page")
            Print #f, "   }"
        End If
        If (r.v(SCU_PREFIX & "NMICON_NMIOCDS") = 1) Then
'           If ((r.v(SCU_PREFIX & "NMICON_NMIWDT") = 1) Or (r.v(SCU_PREFIX & "NMICON_NMIPLL") = 1) Or (r.v(SCU_PREFIX & "NMICON_NMIFLASH") = 1)) Then
'              Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, noSST);", "", "", "switch to page0 with out saving")
'           Else
'              Print #f, FormatCodeStatemente(2, "STR_PAGE(" & SCU_PAGE_NAME & "0, _su);", "", "", "push current SCU page and switch to page0")
'           End If
           Print #f, ""
           Print #f, "   if( NMISR & 0x08 )" & "// if NMIOCDS request flag is set"
           Print #f, "   {"
           d = SCU_PREFIX & "NMISR_FNMIOCDS"
           If (d <> "") Then
                       ' the interrupt request flag must be cleared by software
              Print #f, "   " & SfrBitStatement(r, d, 0)
           Else
                ' the interrupt request flag is automatically cleared by hardware
           End If
           Print #f, ""
           Print #f, uc.GetUserCode("(IR_IsrNMI,6)", 2)
           Print #f, ""
'Print #f, FormatCodeStatemente(2, "RST_PAGE(_su);", "", "", "restore the old SCU page")
           Print #f, "   }"
        End If
        If (r.v(SCU_PREFIX & "NMICON_NMIVDD") = 1) Then
'           If ((r.v(SCU_PREFIX & "NMICON_NMIWDT") = 1) Or (r.v(SCU_PREFIX & "NMICON_NMIPLL") = 1) Or (r.v(SCU_PREFIX & "NMICON_NMIFLASH") = 1) Or (r.v(SCU_PREFIX & "NMICON_NMIOCDS") = 1)) Then
'               Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, noSST);", "", "", "switch to page0 with out saving")
'           Else
'               Print #f, FormatCodeStatemente(2, "STR_PAGE(" & SCU_PAGE_NAME & "0, _su);", "", "", "push current SCU page and switch to page0")
'           End If
           Print #f, ""
           Print #f, "   if( NMISR & 0x10 )" & "// if NMIVDD request flag is set"
           Print #f, "   {"
           d = SCU_PREFIX & "NMISR_FNMIVDD"
           If (d <> "") Then
                        ' the interrupt request flag must be cleared by software
              Print #f, "      " & SfrBitStatement(r, d, 0)
           Else
                ' the interrupt request flag is automatically cleared by hardware
           End If
           Print #f, ""
           Print #f, uc.GetUserCode("(IR_IsrNMI,7)", 2)
           Print #f, ""
'             Print #f, FormatCodeStatemente(2, "RST_PAGE(_su);", "", "", "restore the old SCU page")
           Print #f, "   }"
        End If
        If (r.v(SCU_PREFIX & "NMICON_NMIVDDP") = 1) Then
'           If ((r.v(SCU_PREFIX & "NMICON_NMIWDT") = 1) Or (r.v(SCU_PREFIX & "NMICON_NMIPLL") = 1) Or (r.v(SCU_PREFIX & "NMICON_NMIFLASH") = 1) Or (r.v(SCU_PREFIX & "NMICON_NMIOCDS") = 1) Or (r.v(SCU_PREFIX & "NMICON_NMIVDD") = 1)) Then
'               Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, noSST);", "", "", "switch to page0 with out saving")
'           Else
'               Print #f, FormatCodeStatemente(2, "STR_PAGE(" & SCU_PAGE_NAME & "0, _su);", "", "", "push current SCU page and switch to page0")
'           End If
           Print #f, ""
           Print #f, "  if( NMISR & 0x20 )" & "// if NMIVDDP request flag is set"
           Print #f, "  {"
           d = SCU_PREFIX & "NMISR_FNMIVDDP"
           If (d <> "") Then
                     ' the interrupt request flag must be cleared by software
               Print #f, "      " & SfrBitStatement(r, d, 0)
           Else
               ' the interrupt request flag is automatically cleared by hardware
           End If
           Print #f, ""
           Print #f, uc.GetUserCode("(IR_IsrNMI,8)", 2)
           Print #f, ""
'              Print #f, FormatCodeStatemente(2, "RST_PAGE(_su);", "", "", "restore the old SCU page")
           Print #f, "   }"
        End If
        If (r.v(SCU_PREFIX & "NMICON_NMIECC") = 1) Then
'           If ((r.v(SCU_PREFIX & "NMICON_NMIWDT") = 1) Or (r.v(SCU_PREFIX & "NMICON_NMIPLL") = 1) Or (r.v(SCU_PREFIX & "NMICON_NMIFLASH") = 1) Or (r.v(SCU_PREFIX & "NMICON_NMIOCDS") = 1) Or (r.v(SCU_PREFIX & "NMICON_NMIVDD") = 1) Or (r.v(SCU_PREFIX & "NMICON_NMIVDDP") = 1)) Then
'              Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, noSST);", "", "", "switch to page0 with out saving")
'           Else
'              Print #f, FormatCodeStatemente(2, "STR_PAGE(" & SCU_PAGE_NAME & "0, _su);", "", "", "push current SCU page and switch to page0")
'           End If
              Print #f, ""
           Print #f, "   if( NMISR & 0x40 )" & "// if NMIECC request flag is set"
           Print #f, "   {"
           d = SCU_PREFIX & "NMISR_FNMIECC"
           If (d <> "") Then
                     ' the interrupt request flag must be cleared by software
               Print #f, "      " & SfrBitStatement(r, d, 0)
           Else
               ' the interrupt request flag is automatically cleared by hardware
           End If
           Print #f, ""
           Print #f, uc.GetUserCode("(IR_IsrNMI,9)", 2)
           Print #f, ""
           Print #f, "   }"
        End If
        Print #f, ""
        
        'Print #f, FormatCodeStatemente(2, "RST_PAGE(_su);", "", "", "restore the old SCU page")
'       Print #f, uc.GetUserCode("(IR_IsrNMI,2)", 2)
        Print #f, ""
        Print #f, "} " & END_OF_FUNCTION & r.v("IR_NAME_IsrNMI")
        Print #f, ""
        Print #f, ""
  End If
        
End If
           
    '------------------------------------------------------------------------------------------------
    ' IR_IsrExt(i) function
    '------------------------------------------------------------------------------------------------

'    For iInt = 0 To 1
'
'        If (r.v("IR_USE_IsrExt" & iInt) = 1) Then
'        Print #f, FormatFunctionHeader(r, func, "IR_NAME_IsrExt" & iInt)
'            Print #f, uc.GetUserCode("(IR_IsrExt" & iInt & ",1)", 0) 'USER CODE for application specific descriptions'
'            Print #f, ""
'                      '<--                     max. 78 characters                                -->'
'            Print #f, IsrDeclaration(r, r.v("IR_NAME_IsrExt" & iInt), "EXT" & iInt & "INT")
'            Print #f, "{"
'Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, SST2);", "", "", "switch to page0")
'
'        d = SCU_PREFIX & "IRCON0_EXINT" & iInt
'        If (d <> "") Then
'                        ' the interrupt request flag must be cleared by software
'            Print #f, "  " & SfrBitStatement(r, d, 0)
'                Else
'                        ' the interrupt request flag is automatically cleared by hardware
'        End If
'
'            Print #f, ""
'            Print #f, uc.GetUserCode("(IR_IsrExt" & iInt & ",2)", 2)
'            Print #f, ""
'Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, RST2);", "", "", "restore the old SCU page")
'
'            Print #f, "} " & END_OF_FUNCTION & r.v("IR_NAME_IsrExt" & iInt)
'            Print #f, ""
'            Print #f, ""
'        End If
'
'    Next iInt
    
    
For iInt = 0 To 1

    If (r.v("IR_USE_IsrExt" & iInt) = 1) Then
       If (r.v("ISR_CHOICE") = 1) Then
            Print #f, FormatFunctionHeader(r, func, "IR_NAME_IsrExt" & iInt)
            Call GetDescriptionForISR(r, f)
            Print #f, uc.GetUserCode("(IR_IsrExt" & iInt & ",1)", 0) 'USER CODE for application specific descriptions'
            Print #f, ""
                      '<--                     max. 78 characters                                -->'
            Print #f, IsrDeclaration(r, r.v("IR_NAME_IsrExt" & iInt), "EXT" & iInt & "INT")
            Print #f, "{"
            
            Print #f, uc.GetUserCode("(IR_IsrExt" & iInt & ",2)", 2)
            Print #f, ""
            Print #f, ""
            
            'Print #f, FormatCodeStatemente(2, "_push_(SYSCON0);", "", "", "push the current RMAP")
            
            If (r.v("MAIN_COMPILER") = "SDCC") Then
                Print #f, FormatCodeStatemente(2, "pushsyscon();", "", "", "push the current RMAP")
            ElseIf (r.v("MAIN_COMPILER") = "Keil") Then
                Print #f, FormatCodeStatemente(2, "_push_(SYSCON0);", "", "", "push the current RMAP")
            End If
            
            Print #f, FormatCodeStatemente(2, "RESET_RMAP();", "", "", "resets RMAP")
            Print #f, ""
 
            If (iInt = 0) Then
                If ((r.v(CORE_PREFIX & "IPH_PX0H") * 2 ^ r.v(CORE_PREFIX & "IPH_PX0H") + r.v(CORE_PREFIX & "IP_PX0")) = 0) Then
                    Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, SST0);", "", "", "switch to page0")
                ElseIf ((r.v(CORE_PREFIX & "IPH_PX0H") * 2 ^ r.v(CORE_PREFIX & "IPH_PX0H") + r.v(CORE_PREFIX & "IP_PX0")) = 1) Then
                    Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, SST1);", "", "", "switch to page0")
                ElseIf ((r.v(CORE_PREFIX & "IPH_PX0H") * 2 ^ r.v(CORE_PREFIX & "IPH_PX0H") + r.v(CORE_PREFIX & "IP_PX0")) = 2) Then
                    Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, SST2);", "", "", "switch to page0")
                ElseIf ((r.v(CORE_PREFIX & "IPH_PX0H") * 2 ^ r.v(CORE_PREFIX & "IPH_PX0H") + r.v(CORE_PREFIX & "IP_PX0")) = 3) Then
                    Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, SST3);", "", "", "switch to page0")
                End If
            ElseIf (iInt = 1) Then
                If ((r.v(CORE_PREFIX & "IPH_PX1H") * 2 ^ r.v(CORE_PREFIX & "IPH_PX1H") + r.v(CORE_PREFIX & "IP_PX1")) = 0) Then
                    Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, SST0);", "", "", "switch to page0")
                ElseIf ((r.v(CORE_PREFIX & "IPH_PX1H") * 2 ^ r.v(CORE_PREFIX & "IPH_PX1H") + r.v(CORE_PREFIX & "IP_PX1")) = 1) Then
                    Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, SST1);", "", "", "switch to page0")
                ElseIf ((r.v(CORE_PREFIX & "IPH_PX1H") * 2 ^ r.v(CORE_PREFIX & "IPH_PX1H") + r.v(CORE_PREFIX & "IP_PX1")) = 2) Then
                    Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, SST2);", "", "", "switch to page0")
                ElseIf ((r.v(CORE_PREFIX & "IPH_PX1H") * 2 ^ r.v(CORE_PREFIX & "IPH_PX1H") + r.v(CORE_PREFIX & "IP_PX1")) = 3) Then
                   Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, SST3);", "", "", "switch to page0")
                End If
            End If

            d = SCU_PREFIX & "IRCON0_EXINT" & iInt
            If (d <> "") Then
                        ' the interrupt request flag must be cleared by software
               Print #f, "  " & SfrBitStatement(r, d, 0)
            Else
                        ' the interrupt request flag is automatically cleared by hardware
            End If

            Print #f, ""
            Print #f, uc.GetUserCode("(IR_IsrExt" & iInt & ",3)", 2)
            Print #f, ""
            
            If (iInt = 0) Then
                If ((r.v(CORE_PREFIX & "IPH_PX0H") * 2 ^ r.v(CORE_PREFIX & "IPH_PX0H") + r.v(CORE_PREFIX & "IP_PX0")) = 0) Then
                    Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, RST0);", "", "", "restore the old SCU page")
                ElseIf ((r.v(CORE_PREFIX & "IPH_PX0H") * 2 ^ r.v(CORE_PREFIX & "IPH_PX0H") + r.v(CORE_PREFIX & "IP_PX0")) = 1) Then
                    Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, RST1);", "", "", "restore the old SCU page")
                ElseIf ((r.v(CORE_PREFIX & "IPH_PX0H") * 2 ^ r.v(CORE_PREFIX & "IPH_PX0H") + r.v(CORE_PREFIX & "IP_PX0")) = 2) Then
                    Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, RST2);", "", "", "restore the old SCU page")
                ElseIf ((r.v(CORE_PREFIX & "IPH_PX0H") * 2 ^ r.v(CORE_PREFIX & "IPH_PX0H") + r.v(CORE_PREFIX & "IP_PX0")) = 3) Then
                   Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, RST3);", "", "", "restore the old SCU page")
                End If
            ElseIf (iInt = 1) Then
                If ((r.v(CORE_PREFIX & "IPH_PX1H") * 2 ^ r.v(CORE_PREFIX & "IPH_PX1H") + r.v(CORE_PREFIX & "IP_PX1")) = 0) Then
                    Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, RST0);", "", "", "restore the old SCU page")
                ElseIf ((r.v(CORE_PREFIX & "IPH_PX1H") * 2 ^ r.v(CORE_PREFIX & "IPH_PX1H") + r.v(CORE_PREFIX & "IP_PX1")) = 1) Then
                    Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, RST1);", "", "", "restore the old SCU page")
                ElseIf ((r.v(CORE_PREFIX & "IPH_PX1H") * 2 ^ r.v(CORE_PREFIX & "IPH_PX1H") + r.v(CORE_PREFIX & "IP_PX1")) = 2) Then
                    Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, RST2);", "", "", "restore the old SCU page")
                ElseIf ((r.v(CORE_PREFIX & "IPH_PX1H") * 2 ^ r.v(CORE_PREFIX & "IPH_PX1H") + r.v(CORE_PREFIX & "IP_PX1")) = 3) Then
                     Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, RST3);", "", "", "restore the old SCU page")
                End If
            End If

            Print #f, ""
            
            'Print #f, FormatCodeStatemente(2, "_pop_(SYSCON0);", "", "", "restore the old RMAP")
            
            If (r.v("MAIN_COMPILER") = "SDCC") Then
                Print #f, FormatCodeStatemente(2, "popsyscon();", "", "", "restore the old RMAP")
            ElseIf (r.v("MAIN_COMPILER") = "Keil") Then
                Print #f, FormatCodeStatemente(2, "_pop_(SYSCON0);", "", "", "restore the old RMAP")
            End If
            
            Print #f, ""

            Print #f, "} " & END_OF_FUNCTION & r.v("IR_NAME_IsrExt" & iInt)
            Print #f, ""
            Print #f, ""
        ElseIf (r.v("ISR_CHOICE") = 2) Then
            Print #f, FormatFunctionHeader(r, func, "IR_NAME_IsrExt" & iInt)
            Call GetDescriptionForISR(r, f)
            Print #f, uc.GetUserCode("(IR_IsrExt" & iInt & ",1)", 0) 'USER CODE for application specific descriptions'
            Print #f, ""
                      '<--                     max. 78 characters                                -->'
            Print #f, IsrDeclaration(r, r.v("IR_NAME_IsrExt" & iInt), "EXT" & iInt & "INT")
            Print #f, "{"
            Print #f, uc.GetUserCode("(IR_IsrExt" & iInt & ",2)", 2)
            Print #f, ""
            If (iInt = 0) Then
                If ((r.v(CORE_PREFIX & "IPH_PX0H") * 2 ^ r.v(CORE_PREFIX & "IPH_PX0H") + r.v(CORE_PREFIX & "IP_PX0")) = 0) Then
                    Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, SST0);", "", "", "switch to page0")
                ElseIf ((r.v(CORE_PREFIX & "IPH_PX0H") * 2 ^ r.v(CORE_PREFIX & "IPH_PX0H") + r.v(CORE_PREFIX & "IP_PX0")) = 1) Then
                    Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, SST1);", "", "", "switch to page0")
                ElseIf ((r.v(CORE_PREFIX & "IPH_PX0H") * 2 ^ r.v(CORE_PREFIX & "IPH_PX0H") + r.v(CORE_PREFIX & "IP_PX0")) = 2) Then
                    Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, SST2);", "", "", "switch to page0")
                ElseIf ((r.v(CORE_PREFIX & "IPH_PX0H") * 2 ^ r.v(CORE_PREFIX & "IPH_PX0H") + r.v(CORE_PREFIX & "IP_PX0")) = 3) Then
                    Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, SST3);", "", "", "switch to page0")
                End If
            ElseIf (iInt = 1) Then
                If ((r.v(CORE_PREFIX & "IPH_PX1H") * 2 ^ r.v(CORE_PREFIX & "IPH_PX1H") + r.v(CORE_PREFIX & "IP_PX1")) = 0) Then
                    Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, SST0);", "", "", "switch to page0")
                ElseIf ((r.v(CORE_PREFIX & "IPH_PX1H") * 2 ^ r.v(CORE_PREFIX & "IPH_PX1H") + r.v(CORE_PREFIX & "IP_PX1")) = 1) Then
                    Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, SST1);", "", "", "switch to page0")
                ElseIf ((r.v(CORE_PREFIX & "IPH_PX1H") * 2 ^ r.v(CORE_PREFIX & "IPH_PX1H") + r.v(CORE_PREFIX & "IP_PX1")) = 2) Then
                    Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, SST2);", "", "", "switch to page0")
                ElseIf ((r.v(CORE_PREFIX & "IPH_PX1H") * 2 ^ r.v(CORE_PREFIX & "IPH_PX1H") + r.v(CORE_PREFIX & "IP_PX1")) = 3) Then
                    Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, SST3);", "", "", "switch to page0")
                End If
            End If
            d = SCU_PREFIX & "IRCON0_EXINT" & iInt
            If (d <> "") Then
                        ' the interrupt request flag must be cleared by software
               Print #f, "  " & SfrBitStatement(r, d, 0)
            Else
                        ' the interrupt request flag is automatically cleared by hardware
            End If

            Print #f, ""
            Print #f, uc.GetUserCode("(IR_IsrExt" & iInt & ",3)", 2)
            Print #f, ""
            If (iInt = 0) Then
                If ((r.v(CORE_PREFIX & "IPH_PX0H") * 2 ^ r.v(CORE_PREFIX & "IPH_PX0H") + r.v(CORE_PREFIX & "IP_PX0")) = 0) Then
                    Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, RST0);", "", "", "restore the old SCU page")
                ElseIf ((r.v(CORE_PREFIX & "IPH_PX0H") * 2 ^ r.v(CORE_PREFIX & "IPH_PX0H") + r.v(CORE_PREFIX & "IP_PX0")) = 1) Then
                    Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, RST1);", "", "", "restore the old SCU page")
                ElseIf ((r.v(CORE_PREFIX & "IPH_PX0H") * 2 ^ r.v(CORE_PREFIX & "IPH_PX0H") + r.v(CORE_PREFIX & "IP_PX0")) = 2) Then
                    Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, RST2);", "", "", "restore the old SCU page")
                ElseIf ((r.v(CORE_PREFIX & "IPH_PX0H") * 2 ^ r.v(CORE_PREFIX & "IPH_PX0H") + r.v(CORE_PREFIX & "IP_PX0")) = 3) Then
                    Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, RST3);", "", "", "restore the old SCU page")
                End If
            ElseIf (iInt = 1) Then
                If ((r.v(CORE_PREFIX & "IPH_PX1H") * 2 ^ r.v(CORE_PREFIX & "IPH_PX1H") + r.v(CORE_PREFIX & "IP_PX1")) = 0) Then
                    Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, RST0);", "", "", "restore the old SCU page")
                ElseIf ((r.v(CORE_PREFIX & "IPH_PX1H") * 2 ^ r.v(CORE_PREFIX & "IPH_PX1H") + r.v(CORE_PREFIX & "IP_PX1")) = 1) Then
                    Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, RST1);", "", "", "restore the old SCU page")
                ElseIf ((r.v(CORE_PREFIX & "IPH_PX1H") * 2 ^ r.v(CORE_PREFIX & "IPH_PX1H") + r.v(CORE_PREFIX & "IP_PX1")) = 2) Then
                    Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, RST2);", "", "", "restore the old SCU page")
                ElseIf ((r.v(CORE_PREFIX & "IPH_PX1H") * 2 ^ r.v(CORE_PREFIX & "IPH_PX1H") + r.v(CORE_PREFIX & "IP_PX1")) = 3) Then
                    Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, RST3);", "", "", "restore the old SCU page")
                End If
            End If
            Print #f, "} " & END_OF_FUNCTION & r.v("IR_NAME_IsrExt" & iInt)
            Print #f, ""
            Print #f, ""
        End If
     End If
Next iInt
    
    
    
'      If (r.v("IR_USE_IsrExt2") = 1) Then
'      If Not (r.v("T21_Interrupt_Select") = 1) Then
'        Print #f, FormatFunctionHeader(r, func, "IR_NAME_IsrExt2")
'            Print #f, uc.GetUserCode("(IR_IsrExt2,1)", 0) 'USER CODE for application specific descriptions'
'            Print #f, ""
'                      '<--                     max. 78 characters                                -->'
'            Print #f, IsrDeclaration(r, r.v("IR_NAME_IsrExt2"), "EXT2INT")
'            Print #f, "{"
'            Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, SST2);", "", "", "switch to page0")
'
'        d = SCU_PREFIX & "IRCON0_EXINT2"
'        If (d <> "") Then
'                        ' the interrupt request flag must be cleared by software
'            Print #f, "  " & SfrBitStatement(r, d, 0)
'                Else
'                        ' the interrupt request flag is automatically cleared by hardware
'        End If
'
'            Print #f, ""
'            Print #f, uc.GetUserCode("(IR_IsrExt2,2)", 2)
'            Print #f, ""
'            Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, RST2);", "", "", "restore the old SCU page")
'
'            Print #f, "} " & END_OF_FUNCTION & r.v("IR_NAME_IsrExt2")
'            Print #f, ""
'            Print #f, ""
'        End If
'    End If
    
'      If (r.v("IR_USE_IsrExt3") = 1) Then
'        Print #f, FormatFunctionHeader(r, func, "IR_NAME_IsrExt3")
'            Print #f, uc.GetUserCode("(IR_IsrExt3,1)", 0) 'USER CODE for application specific descriptions'
'            Print #f, ""
'                      '<--                     max. 78 characters                                -->'
'            Print #f, IsrDeclaration(r, r.v("IR_NAME_IsrExt3"), "EXT3INT")
'            Print #f, "{"
'  Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, SST2);", "", "", "switch to page0")
'
'       If (IsAlternatePinFree(r, "EXINT3")) Then
'       Print #f, "if(IRCON0 & 0x08)"
'       Print #f, "{"
'        d = SCU_PREFIX & "IRCON0_EXINT3"
'        If (d <> "") Then
'                        ' the interrupt request flag must be cleared by software
'            Print #f, "  " & SfrBitStatement(r, d, 0)
'                Else
'                        ' the interrupt request flag is automatically cleared by hardware
'        End If
'
'         Print #f, ""
'        Print #f, uc.GetUserCode("(IR_IsrExt3 ,2)", 2)
''        Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, RST2);", "", "", "restore the old SCU page")
'
'         Print #f, "} "
' Print #f, ""
'       End If
'
'       If (IsAlternatePinFree(r, "EXINT4")) Then
'Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, noSST);", "", "", "switch to page0 without saving")
'
'        Print #f, "if(IRCON0 & 0x10)"
'       Print #f, "{"
'
'        d = SCU_PREFIX & "IRCON0_EXINT4"
'        If (d <> "") Then
'                        ' the interrupt request flag must be cleared by software
'            Print #f, "  " & SfrBitStatement(r, d, 0)
'                Else
'                        ' the interrupt request flag is automatically cleared by hardware
'
'       End If
'        Print #f, ""
'        Print #f, uc.GetUserCode("(IR_IsrExt3 ,3)", 2)
''Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, RST2);", "", "", "restore the old SCU page")
'
'         Print #f, "} "
'         Print #f, ""
'       End If
'        If (IsAlternatePinFree(r, "EXINT5")) Then
'Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, noSST);", "", "", "switch to page0 without saving")
'
'         Print #f, "if(IRCON0 & 0x20)"
'       Print #f, "{"
'
'        d = SCU_PREFIX & "IRCON0_EXINT5"
'        If (d <> "") Then
'                        ' the interrupt request flag must be cleared by software
'            Print #f, "  " & SfrBitStatement(r, d, 0)
'                Else
'                        ' the interrupt request flag is automatically cleared by hardware
'        End If
'         Print #f, ""
'            Print #f, uc.GetUserCode("(IR_IsrExt3 ,4)", 2)
''Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, RST2);", "", "", "restore the old SCU page")
'
'         Print #f, ""
'          Print #f, "} "
'        End If
'        If (IsAlternatePinFree(r, "EXINT6")) Then
'Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, noSST);", "", "", "switch to page0 without saving")
'
'         Print #f, "if(IRCON0 & 0x40)"
'       Print #f, "{"
'
'        d = SCU_PREFIX & "IRCON0_EXINT6"
'        If (d <> "") Then
'                        ' the interrupt request flag must be cleared by software
'            Print #f, "  " & SfrBitStatement(r, d, 0)
'                Else
'                        ' the interrupt request flag is automatically cleared by hardware
'        End If
'         Print #f, ""
'         Print #f, uc.GetUserCode("(IR_IsrExt3 ,5)", 2)
'       Print #f, ""
'
'        Print #f, "} "
'        End If
'
'            Print #f, ""
'       Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, RST2);", "", "", "restore the old SCU page")
'
''            Print #f, uc.GetUserCode("(IR_IsrExt3 ,2)", 2)
'            Print #f, ""
'            Print #f, "} " & END_OF_FUNCTION & r.v("IR_NAME_IsrExt3")
'            Print #f, ""
'            Print #f, ""
'        End If
    
    
If (Not IsCpuTypeOK(r)) Then

If (Not ((r.v(SCU_PREFIX & "EXICON0_EXINT3") = 3) And (r.v(SCU_PREFIX & "EXICON1_EXINT4") = 3) And (r.v(SCU_PREFIX & "EXICON1_EXINT5") = 3) And (r.v(SCU_PREFIX & "EXICON1_EXINT6") = 3))) Then
If (r.v("IR_USE_IsrExt3") = 1) Then
   If (r.v("ISR_CHOICE") = 1) Then
        
        Print #f, FormatFunctionHeader(r, func, "IR_NAME_IsrExt3")
        Call GetDescriptionForISR(r, f)
        Print #f, uc.GetUserCode("(IR_IsrExt3,1)", 0) 'USER CODE for application specific descriptions'
        Print #f, ""
                      '<--                     max. 78 characters                                -->'
        Print #f, IsrDeclaration(r, r.v("IR_NAME_IsrExt3"), "EXT3INT")
        Print #f, "{"
        
        Print #f, ""
        
        'Print #f, FormatCodeStatemente(2, "_push_(SYSCON0);", "", "", "push the current RMAP")
        
        If (r.v("MAIN_COMPILER") = "SDCC") Then
            Print #f, FormatCodeStatemente(2, "pushsyscon();", "", "", "push the current RMAP")
        ElseIf (r.v("MAIN_COMPILER") = "Keil") Then
            Print #f, FormatCodeStatemente(2, "_push_(SYSCON0);", "", "", "push the current RMAP")
        End If
        
        Print #f, FormatCodeStatemente(2, "RESET_RMAP();", "", "", "resets RMAP")
        Print #f, ""
        
        Print #f, uc.GetUserCode("(IR_IsrExt3,2)", 2)
        Print #f, ""
       
        If ((r.v(CORE_PREFIX & "IPH1_PXMH") * 2 ^ r.v(CORE_PREFIX & "IPH1_PXMH") + r.v(CORE_PREFIX & "IP1_PXM")) = 0) Then
            Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, SST0);", "", "", "switch to page0")
        ElseIf ((r.v(CORE_PREFIX & "IPH1_PXMH") * 2 ^ r.v(CORE_PREFIX & "IPH1_PXMH") + r.v(CORE_PREFIX & "IP1_PXM")) = 1) Then
            Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, SST1);", "", "", "switch to page0")
        ElseIf ((r.v(CORE_PREFIX & "IPH1_PXMH") * 2 ^ r.v(CORE_PREFIX & "IPH1_PXMH") + r.v(CORE_PREFIX & "IP1_PXM")) = 2) Then
            Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, SST2);", "", "", "switch to page0")
        ElseIf ((r.v(CORE_PREFIX & "IPH1_PXMH") * 2 ^ r.v(CORE_PREFIX & "IPH1_PXMH") + r.v(CORE_PREFIX & "IP1_PXM")) = 3) Then
             Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, SST3);", "", "", "switch to page0")
        End If
        
        If (r.v(SCU_PREFIX & "EXICON0_EXINT3") <> 3) Then
        
        If (IsAlternatePinFree(r, "EXINT3")) Then
           Print #f, "if(IRCON0 & 0x08)"
           Print #f, "{"
           d = SCU_PREFIX & "IRCON0_EXINT3"
           If (d <> "") Then
                     ' the interrupt request flag must be cleared by software
               Print #f, "  " & SfrBitStatement(r, d, 0)
           Else
                       ' the interrupt request flag is automatically cleared by hardware
           End If
           Print #f, ""
           Print #f, uc.GetUserCode("(IR_IsrExt3 ,3)", 2)
           '        Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, RST2);", "", "", "restore the old SCU page")
           Print #f, "} "
           Print #f, ""
       End If
       End If
       If (r.v(SCU_PREFIX & "EXICON1_EXINT4") <> 3) Then
       If (IsAlternatePinFree(r, "EXINT4")) Then
          'Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, noSST);", "", "", "switch to page0 without saving")
          Print #f, "if(IRCON0 & 0x10)"
          Print #f, "{"
          d = SCU_PREFIX & "IRCON0_EXINT4"
          If (d <> "") Then
                    ' the interrupt request flag must be cleared by software
              Print #f, "  " & SfrBitStatement(r, d, 0)
          Else
                    ' the interrupt request flag is automatically cleared by hardware
          End If
          Print #f, ""
          Print #f, uc.GetUserCode("(IR_IsrExt3 ,4)", 2)
          'Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, RST2);", "", "", "restore the old SCU page")
          Print #f, "} "
          Print #f, ""
       End If
       End If
       If (r.v(SCU_PREFIX & "EXICON1_EXINT5") <> 3) Then
       If (IsAlternatePinFree(r, "EXINT5")) Then
          'Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, noSST);", "", "", "switch to page0 without saving")
          Print #f, "if(IRCON0 & 0x20)"
          Print #f, "{"
          d = SCU_PREFIX & "IRCON0_EXINT5"
          If (d <> "") Then
                     ' the interrupt request flag must be cleared by software
              Print #f, "  " & SfrBitStatement(r, d, 0)
          Else
                     ' the interrupt request flag is automatically cleared by hardware
          End If
          Print #f, ""
          Print #f, uc.GetUserCode("(IR_IsrExt3 ,5)", 2)
                     'Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, RST2);", "", "", "restore the old SCU page")
          Print #f, ""
          Print #f, "} "
       End If
       End If
       If (r.v(SCU_PREFIX & "EXICON1_EXINT6") <> 3) Then
       If (IsAlternatePinFree(r, "EXINT6")) Then
           'Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, noSST);", "", "", "switch to page0 without saving")
           Print #f, "if(IRCON0 & 0x40)"
           Print #f, "{"
           d = SCU_PREFIX & "IRCON0_EXINT6"
           If (d <> "") Then
                     ' the interrupt request flag must be cleared by software
               Print #f, "  " & SfrBitStatement(r, d, 0)
           Else
                     ' the interrupt request flag is automatically cleared by hardware
           End If
           Print #f, ""
           Print #f, uc.GetUserCode("(IR_IsrExt3 ,6)", 2)
           Print #f, ""
           Print #f, "} "
       End If
        
       End If
        
        Print #f, ""
        If ((r.v(CORE_PREFIX & "IPH1_PXMH") * 2 ^ r.v(CORE_PREFIX & "IPH1_PXMH") + r.v(CORE_PREFIX & "IP1_PXM")) = 0) Then
            Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, RST0);", "", "", "restore the old SCU page")
        ElseIf ((r.v(CORE_PREFIX & "IPH1_PXMH") * 2 ^ r.v(CORE_PREFIX & "IPH1_PXMH") + r.v(CORE_PREFIX & "IP1_PXM")) = 1) Then
            Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, RST1);", "", "", "restore the old SCU page")
        ElseIf ((r.v(CORE_PREFIX & "IPH1_PXMH") * 2 ^ r.v(CORE_PREFIX & "IPH1_PXMH") + r.v(CORE_PREFIX & "IP1_PXM")) = 2) Then
            Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, RST2);", "", "", "restore the old SCU page")
        ElseIf ((r.v(CORE_PREFIX & "IPH1_PXMH") * 2 ^ r.v(CORE_PREFIX & "IPH1_PXMH") + r.v(CORE_PREFIX & "IP1_PXM")) = 3) Then
             Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0,RST3);", "", "", "restore the old SCU page")
        End If
           
        Print #f, ""
        
        'Print #f, FormatCodeStatemente(2, "_pop_(SYSCON0);", "", "", "restore the old RMAP")
        
        If (r.v("MAIN_COMPILER") = "SDCC") Then
            Print #f, FormatCodeStatemente(2, "popsyscon();", "", "", "restore the old RMAP")
        ElseIf (r.v("MAIN_COMPILER") = "Keil") Then
            Print #f, FormatCodeStatemente(2, "_pop_(SYSCON0);", "", "", "restore the old RMAP")
        End If
        
        Print #f, ""
       
'            Print #f, uc.GetUserCode("(IR_IsrExt3 ,2)", 2)
        Print #f, ""
        Print #f, "} " & END_OF_FUNCTION & r.v("IR_NAME_IsrExt3")
        Print #f, ""
        Print #f, ""
   ElseIf (r.v("ISR_CHOICE") = 2) Then
        Print #f, FormatFunctionHeader(r, func, "IR_NAME_IsrExt3")
        Call GetDescriptionForISR(r, f)
        Print #f, uc.GetUserCode("(IR_IsrExt3,1)", 0) 'USER CODE for application specific descriptions'
        Print #f, ""
                      '<--                     max. 78 characters                                -->'
        Print #f, IsrDeclaration(r, r.v("IR_NAME_IsrExt3"), "EXT3INT")
        Print #f, "{"
        
        Print #f, uc.GetUserCode("(IR_IsrExt3,2)", 2)
        Print #f, ""
       
        If ((r.v(CORE_PREFIX & "IPH1_PXMH") * 2 ^ r.v(CORE_PREFIX & "IPH1_PXMH") + r.v(CORE_PREFIX & "IP1_PXM")) = 0) Then
            Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, SST0);", "", "", "switch to page0")
        ElseIf ((r.v(CORE_PREFIX & "IPH1_PXMH") * 2 ^ r.v(CORE_PREFIX & "IPH1_PXMH") + r.v(CORE_PREFIX & "IP1_PXM")) = 1) Then
            Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, SST1);", "", "", "switch to page0")
        ElseIf ((r.v(CORE_PREFIX & "IPH1_PXMH") * 2 ^ r.v(CORE_PREFIX & "IPH1_PXMH") + r.v(CORE_PREFIX & "IP1_PXM")) = 2) Then
            Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, SST2);", "", "", "switch to page0")
        ElseIf ((r.v(CORE_PREFIX & "IPH1_PXMH") * 2 ^ r.v(CORE_PREFIX & "IPH1_PXMH") + r.v(CORE_PREFIX & "IP1_PXM")) = 3) Then
            Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, SST3);", "", "", "switch to page0")
        End If
        
        If (r.v(SCU_PREFIX & "EXICON0_EXINT3") <> 3) Then
        
        If (IsAlternatePinFree(r, "EXINT3")) Then
           Print #f, "if(IRCON0 & 0x08)"
           Print #f, "{"
           d = SCU_PREFIX & "IRCON0_EXINT3"
           If (d <> "") Then
                     ' the interrupt request flag must be cleared by software
               Print #f, "  " & SfrBitStatement(r, d, 0)
           Else
                       ' the interrupt request flag is automatically cleared by hardware
           End If
           Print #f, ""
           Print #f, uc.GetUserCode("(IR_IsrExt3 ,3)", 2)
           '        Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, RST2);", "", "", "restore the old SCU page")
           Print #f, "} "
           Print #f, ""
        End If
        End If
       If (r.v(SCU_PREFIX & "EXICON1_EXINT4") <> 3) Then
       If (IsAlternatePinFree(r, "EXINT4")) Then
          'Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, noSST);", "", "", "switch to page0 without saving")
          Print #f, "if(IRCON0 & 0x10)"
          Print #f, "{"
          d = SCU_PREFIX & "IRCON0_EXINT4"
          If (d <> "") Then
                    ' the interrupt request flag must be cleared by software
              Print #f, "  " & SfrBitStatement(r, d, 0)
          Else
                    ' the interrupt request flag is automatically cleared by hardware
          End If
          Print #f, ""
          Print #f, uc.GetUserCode("(IR_IsrExt3 ,4)", 2)
          'Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, RST2);", "", "", "restore the old SCU page")
          Print #f, "} "
          Print #f, ""
       End If
       End If
       If (r.v(SCU_PREFIX & "EXICON1_EXINT5") <> 3) Then
       If (IsAlternatePinFree(r, "EXINT5")) Then
         ' Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, noSST);", "", "", "switch to page0 without saving")
          Print #f, "if(IRCON0 & 0x20)"
          Print #f, "{"
          d = SCU_PREFIX & "IRCON0_EXINT5"
          If (d <> "") Then
                     ' the interrupt request flag must be cleared by software
              Print #f, "  " & SfrBitStatement(r, d, 0)
          Else
                     ' the interrupt request flag is automatically cleared by hardware
          End If
          Print #f, ""
          Print #f, uc.GetUserCode("(IR_IsrExt3 ,5)", 2)
                     'Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, RST2);", "", "", "restore the old SCU page")
          Print #f, ""
          Print #f, "} "
       End If
       End If
       If (r.v(SCU_PREFIX & "EXICON1_EXINT6") <> 3) Then
       If (IsAlternatePinFree(r, "EXINT6")) Then
           'Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, noSST);", "", "", "switch to page0 without saving")
           Print #f, "if(IRCON0 & 0x40)"
           Print #f, "{"
           d = SCU_PREFIX & "IRCON0_EXINT6"
           If (d <> "") Then
                     ' the interrupt request flag must be cleared by software
               Print #f, "  " & SfrBitStatement(r, d, 0)
           Else
                     ' the interrupt request flag is automatically cleared by hardware
           End If
           Print #f, ""
           Print #f, uc.GetUserCode("(IR_IsrExt3 ,6)", 2)
           Print #f, ""
           Print #f, "} "
       End If
       End If
        Print #f, ""
        
        
        If ((r.v(CORE_PREFIX & "IPH1_PXMH") * 2 ^ r.v(CORE_PREFIX & "IPH1_PXMH") + r.v(CORE_PREFIX & "IP1_PXM")) = 0) Then
            Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, RST0);", "", "", "restore the old SCU page")
        ElseIf ((r.v(CORE_PREFIX & "IPH1_PXMH") * 2 ^ r.v(CORE_PREFIX & "IPH1_PXMH") + r.v(CORE_PREFIX & "IP1_PXM")) = 1) Then
            Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, RST1);", "", "", "restore the old SCU page")
        ElseIf ((r.v(CORE_PREFIX & "IPH1_PXMH") * 2 ^ r.v(CORE_PREFIX & "IPH1_PXMH") + r.v(CORE_PREFIX & "IP1_PXM")) = 2) Then
            Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, RST2);", "", "", "restore the old SCU page")
        ElseIf ((r.v(CORE_PREFIX & "IPH1_PXMH") * 2 ^ r.v(CORE_PREFIX & "IPH1_PXMH") + r.v(CORE_PREFIX & "IP1_PXM")) = 3) Then
            Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, RST3);", "", "", "restore the old SCU page")
        End If
            
'            Print #f, uc.GetUserCode("(IR_IsrExt3 ,2)", 2)
        Print #f, ""
        Print #f, "} " & END_OF_FUNCTION & r.v("IR_NAME_IsrExt3")
        Print #f, ""
        Print #f, ""
   End If
  End If
 End If
End If
    
    
    '------------------------------------------------------------------------------------------------
            Print #f, uc.GetUserCode("(IR_General,10)", 0)
            Print #f, ""
    
    'close file
    Close f
    
    IRGenerateC = True
    Exit Function
    
IRGenerateCError:
    errorbox "error ir.c", Err.Description
    Close f
    Exit Function
End Function


'*****************************************************************************
'Description:
'        Generates the code for the IR.h file.
'-----------------------------------------------------------------------------
'Parameters:
'        r                reference to the Registers object
'        vIndex           a parameter
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Function IRGenerateH(r As ProjectData, vIndex As Variant) As Boolean
    On Error GoTo IRGenerateHError
    
    Dim iInt As Integer
    Dim f As Variant
    Dim d As String
    Dim dc As DAvECollection
    Dim uc As UserCode
    Dim func As FunctionClass
    Dim l As Long
    Dim sName As String
   
    IRGenerateH = False

    Set dc = ObjectCollection("MODULENAMES")
    Set uc = New UserCode
    Set func = New FunctionClass

    'refresh the decriptions of the functions and macros
   Call RefreshFunctionDescriptions(func, r)
    
    'read usercode
    uc.ReadFile ((StripFilenameAndExtension(r.LoadedFile)) & "\" & r.v("IR_HFILE"))
    
    'open IR.h
    f = FreeFile
    Open CStr(StripFilenameAndExtension(r.LoadedFile)) & "\" & r.v("IR_HFILE") For Output As f
    
    '------------------------------------------------------------------------------------------------
    ' module header
    '------------------------------------------------------------------------------------------------
    d = FormatModuleDescription(GetModuleHeaderH("IR"))
    Print #f, Rtf.GenerateModuleHeader(DefGetValue("ProductVersion"), StripPath(r.LoadedFile), dc("IR").ModuleDescription, r.v("IR_HFILE"), r.v("MAIN_CPU_TYPE"), r.v("MAIN_COMPILER"), d)
    
            
            Print #f, uc.GetUserCode("(IR_Header,1)", 0)
            Print #f, ""
            Print #f, Rtf.GenerateNote((r.v("IR_Notes")))
            Print #f, ""
            Print #f, "#ifndef _" & StripExtension(r.v("IR_HFILE")) & "_H_"
            Print #f, "#define _" & StripExtension(r.v("IR_HFILE")) & "_H_"
            Print #f, ""
            Print #f, SECTION_PROJECT_INCLUDES
            Print #f, ""  'DAvE includes'
            Print #f, uc.GetUserCode("(IR_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("(IR_Header,3)", 0)
            Print #f, ""
            Print #f, ""
            Print #f, SECTION_DEFINES
            Print #f, ""  'DAvE global #define definitions'
            Print #f, uc.GetUserCode("(IR_Header,4)", 0)
            Print #f, ""

           

            Print #f, ""
            Print #f, SECTION_TYPEDEFS
            Print #f, ""  'DAvE type definitions'
            Print #f, uc.GetUserCode("(IR_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("(IR_Header,6)", 0)
            Print #f, ""
            Print #f, ""
            Print #f, SECTION_GLOBAL_VARIABLES
            Print #f, ""  'DAvE definition of global variables'
            Print #f, uc.GetUserCode("(IR_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
        ' 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")
        sName = 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("IR_USE_" & sName) = 1) And (func.FunctionSort(d) = 1)) Then
            Print #f, FormatFunctionDeclaration(r, func, d) & ";"
        End If
    Next l

            Print #f, ""
            Print #f, uc.GetUserCode("(IR_Header,8)", 0)
            Print #f, ""
            Print #f, ""
                          'DAvE declarations of global macros'
    '------------------------------------------------------------------------------------------------
    ' IR_EnableAll macro
    '------------------------------------------------------------------------------------------------
    If (r.v("IR_USE_EnableAll") = 1) Then
    Print #f, FormatFunctionHeader(r, func, "IR_NAME_EnableAll")

            Print #f, "#define " & r.v("IR_NAME_EnableAll") & "() " & SfrBitStatement(r, CORE_PREFIX & "IEN0_EA", 1, False)
            Print #f, ""
            Print #f, ""
    End If
  
    '------------------------------------------------------------------------------------------------
    ' IR_DisableAll macro
    '------------------------------------------------------------------------------------------------
    If (r.v("IR_USE_DisableAll") = 1) Then
    Print #f, FormatFunctionHeader(r, func, "IR_NAME_DisableAll")

            Print #f, "#define " & r.v("IR_NAME_DisableAll") & "() " & SfrBitStatement(r, CORE_PREFIX & "IEN0_EA", 0, False)
            Print #f, ""
            Print #f, ""
    End If

    '------------------------------------------------------------------------------------------------
    ' IR_EnableInterrupt macro
    '------------------------------------------------------------------------------------------------
    If (r.v("IR_USE_EnableInterrupt") = 1) Then
    Print #f, FormatFunctionHeader(r, func, "IR_NAME_EnableInterrupt")

            Print #f, "#define " & (r.v("IR_NAME_EnableInterrupt")) & "(Interrupt) _IE(Interrupt)"
            Print #f, ""
            Print #f, "#define _IE(Interrupt) ENA_##Interrupt "
            Print #f, ""

'        For iInt = 0 To NUMBER_OF_EXT_INTERRUPTS - 1
'            Print #f, "#define ENA_" & FillRight(20, r.v("IR_PARA_EXTERNAL_INT" & iInt)) & " " & SfrBitStatement(r, ExtIntEnableBit(iInt), 1, False)
'        Next iInt
'            Print #f, "#define ENA_" & FillRight(20, r.v("IR_PARA_EXTERNAL_INT0")) & " " & SfrBitStatement(r, CORE_PREFIX & "IEN0_EX0", 1, False)
'            Print #f, "#define ENA_" & FillRight(20, r.v("IR_PARA_EXTERNAL_INT1")) & " " & SfrBitStatement(r, CORE_PREFIX & "IEN0_EX1", 1, False)
'            Print #f, "#define ENA_" & FillRight(20, r.v("IR_PARA_EXTERNAL_INT2")) & " " & SfrBitStatement(r, CORE_PREFIX & "IEN1_EX2", 1, False)
'            Print #f, "#define ENA_" & FillRight(20, r.v("IR_PARA_EXTERNAL_INT3")) & " " & SfrBitStatement(r, CORE_PREFIX & "IEN1_EXM", 1, False)
'            Print #f, "#define ENA_" & FillRight(20, r.v("IR_PARA_ADC_INT")) & " " & SfrBitStatement(r, CORE_PREFIX & "IEN1_EADC", 1, False)
'            Print #f, "#define ENA_" & FillRight(20, r.v("IR_PARA_CCU6_NODE0_INT")) & " " & SfrBitStatement(r, CORE_PREFIX & "IEN1_ECCIP0", 1, False)
'            Print #f, "#define ENA_" & FillRight(20, r.v("IR_PARA_CCU6_NODE1_INT")) & " " & SfrBitStatement(r, CORE_PREFIX & "IEN1_ECCIP1", 1, False)
'            Print #f, "#define ENA_" & FillRight(20, r.v("IR_PARA_CCU6_NODE2_INT")) & " " & SfrBitStatement(r, CORE_PREFIX & "IEN1_ECCIP2", 1, False)
'            Print #f, "#define ENA_" & FillRight(20, r.v("IR_PARA_CCU6_NODE3_INT")) & " " & SfrBitStatement(r, CORE_PREFIX & "IEN1_ECCIP3", 1, False)
'            Print #f, "#define ENA_" & FillRight(20, r.v("IR_PARA_T0_INT")) & " " & SfrBitStatement(r, CORE_PREFIX & "IEN0_ET0", 1, False)
'            Print #f, "#define ENA_" & FillRight(20, r.v("IR_PARA_T1_INT")) & " " & SfrBitStatement(r, CORE_PREFIX & "IEN0_ET1", 1, False)
'            Print #f, "#define ENA_" & FillRight(20, r.v("IR_PARA_T2_OVERFLOW_INT")) & " " & SfrBitStatement(r, CORE_PREFIX & "IEN0_ET2", 1, False)
'            Print #f, "#define ENA_" & FillRight(20, r.v("IR_PARA_UART_INT")) & " " & SfrBitStatement(r, CORE_PREFIX & "IEN0_ES", 1, False)
'            Print #f, "#define ENA_" & FillRight(20, r.v("IR_PARA_SSC_INT")) & " " & SfrBitStatement(r, CORE_PREFIX & "IEN1_ESSC", 1, False)
             Print #f, "#define ENA_" & FillRight(20, r.v("IR_PARA_EXTERNAL_INT0")) & " " & SfrBitStatement(r, CORE_PREFIX & "IEN0_EX0", 1, False) & "       " & FormatComments(0, 0, "", "", "Enables External 0 Interrupt")
             Print #f, "#define ENA_" & FillRight(20, r.v("IR_PARA_EXTERNAL_INT1")) & " " & SfrBitStatement(r, CORE_PREFIX & "IEN0_EX1", 1, False) & "       " & FormatComments(0, 0, "", "", "Enables External 1 Interrupt")
             Print #f, "#define ENA_" & FillRight(20, r.v("IR_PARA_XINTR8_INT")) & " " & SfrBitStatement(r, CORE_PREFIX & "IEN1_EX2", 1, False) & "       " & FormatComments(0, 0, "", "", "Enables External 2,T21,UART1 and BRG1 Interrupts")
             If (Not IsCpuTypeOK(r)) Then
                Print #f, "#define ENA_" & FillRight(20, r.v("IR_PARA_EXTERNAL_INT3")) & " " & SfrBitStatement(r, CORE_PREFIX & "IEN1_EXM", 1, False) & "       " & FormatComments(0, 0, "", "", "Enables External 3,4,5,6 Interrupts")
                Print #f, "#define ENA_" & FillRight(20, r.v("IR_PARA_ADC_INT")) & " " & SfrBitStatement(r, CORE_PREFIX & "IEN1_EADC", 1, False) & "      " & FormatComments(0, 0, "", "", "Enables ADC Interrupts")
                Print #f, "#define ENA_" & FillRight(20, r.v("IR_PARA_CCU6_NODE0_INT")) & " " & SfrBitStatement(r, CORE_PREFIX & "IEN1_ECCIP0", 1, False) & "    " & FormatComments(0, 0, "", "", "Enables CCU6 Node 0 Interrupt")
                Print #f, "#define ENA_" & FillRight(20, r.v("IR_PARA_CCU6_NODE1_INT")) & " " & SfrBitStatement(r, CORE_PREFIX & "IEN1_ECCIP1", 1, False) & "    " & FormatComments(0, 0, "", "", "Enables CCU6 Node 1 Interrupt")
                Print #f, "#define ENA_" & FillRight(20, r.v("IR_PARA_CCU6_NODE2_INT")) & " " & SfrBitStatement(r, CORE_PREFIX & "IEN1_ECCIP2", 1, False) & "    " & FormatComments(0, 0, "", "", "Enables CCU6 Node 2 Interrupt")
                Print #f, "#define ENA_" & FillRight(20, r.v("IR_PARA_CCU6_NODE3_INT")) & " " & SfrBitStatement(r, CORE_PREFIX & "IEN1_ECCIP3", 1, False) & "    " & FormatComments(0, 0, "", "", "Enables CCU6 Node 3 Interrupt")
             Else
               Print #f, "#define ENA_" & FillRight(20, r.v("IR_PARA_XINTR9_INT")) & " " & SfrBitStatement(r, CORE_PREFIX & "IEN1_EXM", 1, False) & "       " & FormatComments(0, 0, "", "", "Enables External 3,4,5,6 and MultiCAN Node 3 Interrupts")
               Print #f, "#define ENA_" & FillRight(20, r.v("IR_PARA_XINTR6_INT")) & " " & SfrBitStatement(r, CORE_PREFIX & "IEN1_EADC", 1, False) & "      " & FormatComments(0, 0, "", "", "Enables MultiCAN Nodes 1 ,2 and ADC Interrupts")
               Print #f, "#define ENA_" & FillRight(20, r.v("IR_PARA_XINTR10_INT")) & " " & SfrBitStatement(r, CORE_PREFIX & "IEN1_ECCIP0", 1, False) & "    " & FormatComments(0, 0, "", "", "Enables CCU6 Node 0 and MultiCAN Node 4 Interrupts")
               Print #f, "#define ENA_" & FillRight(20, r.v("IR_PARA_XINTR11_INT")) & " " & SfrBitStatement(r, CORE_PREFIX & "IEN1_ECCIP1", 1, False) & "    " & FormatComments(0, 0, "", "", "Enables CCU6 Node 1 and MultiCAN Node 5 Interrupts")
               Print #f, "#define ENA_" & FillRight(20, r.v("IR_PARA_XINTR12_INT")) & " " & SfrBitStatement(r, CORE_PREFIX & "IEN1_ECCIP2", 1, False) & "    " & FormatComments(0, 0, "", "", "Enables CCU6 Node 2 and MultiCAN Node 6 Interrupts")
               Print #f, "#define ENA_" & FillRight(20, r.v("IR_PARA_XINTR13_INT")) & " " & SfrBitStatement(r, CORE_PREFIX & "IEN1_ECCIP3", 1, False) & "    " & FormatComments(0, 0, "", "", "Enables CCU6 Node 3 and MultiCAN Node 7 Interrupts")
             End If
             Print #f, "#define ENA_" & FillRight(20, r.v("IR_PARA_T0_INT")) & " " & SfrBitStatement(r, CORE_PREFIX & "IEN0_ET0", 1, False) & "       " & FormatComments(0, 0, "", "", "Enables Timer 0 Interrupt")
             Print #f, "#define ENA_" & FillRight(20, r.v("IR_PARA_T1_INT")) & " " & SfrBitStatement(r, CORE_PREFIX & "IEN0_ET1", 1, False) & "       " & FormatComments(0, 0, "", "", "Enables Timer 1 Interrupt")
             Print #f, "#define ENA_" & FillRight(20, r.v("IR_PARA_XINTR5_INT")) & " " & SfrBitStatement(r, CORE_PREFIX & "IEN0_ET2", 1, False) & "       " & FormatComments(0, 0, "", "", "Enables T2,BRG and MultiCAN Node 0 Interrupts")
             Print #f, "#define ENA_" & FillRight(20, r.v("IR_PARA_UART_INT")) & " " & SfrBitStatement(r, CORE_PREFIX & "IEN0_ES", 1, False) & "        " & FormatComments(0, 0, "", "", "Enables UART Interrupt")
             Print #f, "#define ENA_" & FillRight(20, r.v("IR_PARA_SSC_INT")) & " " & SfrBitStatement(r, CORE_PREFIX & "IEN1_ESSC", 1, False) & "      " & FormatComments(0, 0, "", "", "Enables SSC Interrupt")
            Print #f, ""
            Print #f, ""
    End If
 
    '------------------------------------------------------------------------------------------------
    ' IR_DisableInterrupt macro
    '------------------------------------------------------------------------------------------------
    If (r.v("IR_USE_DisableInterrupt") = 1) Then
    Print #f, FormatFunctionHeader(r, func, "IR_NAME_DisableInterrupt")

            Print #f, "#define " & (r.v("IR_NAME_DisableInterrupt")) & "(Interrupt) _ID(Interrupt)"
            Print #f, ""
            Print #f, "#define _ID(Interrupt) DIS_##Interrupt "
            Print #f, ""

'        For iInt = 0 To NUMBER_OF_EXT_INTERRUPTS - 1
'            Print #f, "#define DIS_" & FillRight(20, r.v("IR_PARA_EXTERNAL_INT" & iInt)) & " " & SfrBitStatement(r, ExtIntEnableBit(iInt), 0, False)
'        Next iInt
'            Print #f, "#define DIS_" & FillRight(20, r.v("IR_PARA_EXTERNAL_INT0")) & " " & SfrBitStatement(r, CORE_PREFIX & "IEN0_EX0", 0, False)
'            Print #f, "#define DIS_" & FillRight(20, r.v("IR_PARA_EXTERNAL_INT1")) & " " & SfrBitStatement(r, CORE_PREFIX & "IEN0_EX1", 0, False)
'            Print #f, "#define DIS_" & FillRight(20, r.v("IR_PARA_EXTERNAL_INT2")) & " " & SfrBitStatement(r, CORE_PREFIX & "IEN1_EX2", 0, False)
'            Print #f, "#define DIS_" & FillRight(20, r.v("IR_PARA_EXTERNAL_INT3")) & " " & SfrBitStatement(r, CORE_PREFIX & "IEN1_EXM", 0, False)
'              Print #f, "#define DIS_" & FillRight(20, r.v("IR_PARA_ADC_INT")) & " " & SfrBitStatement(r, CORE_PREFIX & "IEN1_EADC", 0, False)
'            Print #f, "#define DIS_" & FillRight(20, r.v("IR_PARA_CCU6_NODE0_INT")) & " " & SfrBitStatement(r, CORE_PREFIX & "IEN1_ECCIP0", 0, False)
'            Print #f, "#define DIS_" & FillRight(20, r.v("IR_PARA_CCU6_NODE1_INT")) & " " & SfrBitStatement(r, CORE_PREFIX & "IEN1_ECCIP1", 0, False)
'            Print #f, "#define DIS_" & FillRight(20, r.v("IR_PARA_CCU6_NODE2_INT")) & " " & SfrBitStatement(r, CORE_PREFIX & "IEN1_ECCIP2", 0, False)
'            Print #f, "#define DIS_" & FillRight(20, r.v("IR_PARA_CCU6_NODE3_INT")) & " " & SfrBitStatement(r, CORE_PREFIX & "IEN1_ECCIP3", 0, False)
'            Print #f, "#define DIS_" & FillRight(20, r.v("IR_PARA_T0_INT")) & " " & SfrBitStatement(r, CORE_PREFIX & "IEN0_ET0", 0, False)
'            Print #f, "#define DIS_" & FillRight(20, r.v("IR_PARA_T1_INT")) & " " & SfrBitStatement(r, CORE_PREFIX & "IEN0_ET1", 0, False)
'            Print #f, "#define DIS_" & FillRight(20, r.v("IR_PARA_T2_OVERFLOW_INT")) & " " & SfrBitStatement(r, CORE_PREFIX & "IEN0_ET2", 0, False)
'            Print #f, "#define DIS_" & FillRight(20, r.v("IR_PARA_UART_INT")) & " " & SfrBitStatement(r, CORE_PREFIX & "IEN0_ES", 0, False)
'            Print #f, "#define DIS_" & FillRight(20, r.v("IR_PARA_SSC_INT")) & " " & SfrBitStatement(r, CORE_PREFIX & "IEN1_ESSC", 0, False)
            Print #f, "#define DIS_" & FillRight(20, r.v("IR_PARA_EXTERNAL_INT0")) & " " & SfrBitStatement(r, CORE_PREFIX & "IEN0_EX0", 0, False) & "       " & FormatComments(0, 0, "", "", "Disables External 0 Interrupt")
            Print #f, "#define DIS_" & FillRight(20, r.v("IR_PARA_EXTERNAL_INT1")) & " " & SfrBitStatement(r, CORE_PREFIX & "IEN0_EX1", 0, False) & "       " & FormatComments(0, 0, "", "", "Disables External 1 Interrupt")
            Print #f, "#define DIS_" & FillRight(20, r.v("IR_PARA_XINTR8_INT")) & " " & SfrBitStatement(r, CORE_PREFIX & "IEN1_EX2", 0, False) & "       " & FormatComments(0, 0, "", "", "Disables External 2,T21,UART1 and BRG1 Interrupts")
            If (Not IsCpuTypeOK(r)) Then
                Print #f, "#define DIS_" & FillRight(20, r.v("IR_PARA_EXTERNAL_INT3")) & " " & SfrBitStatement(r, CORE_PREFIX & "IEN1_EXM", 0, False) & "       " & FormatComments(0, 0, "", "", "Disables External 3,4,5,6 Interrupts")
                Print #f, "#define DIS_" & FillRight(20, r.v("IR_PARA_ADC_INT")) & " " & SfrBitStatement(r, CORE_PREFIX & "IEN1_EADC", 0, False) & "      " & FormatComments(0, 0, "", "", "Disables ADC Interrupts")
                Print #f, "#define DIS_" & FillRight(20, r.v("IR_PARA_CCU6_NODE0_INT")) & " " & SfrBitStatement(r, CORE_PREFIX & "IEN1_ECCIP0", 0, False) & "    " & FormatComments(0, 0, "", "", "Disables CCU6 Node 0 Interrupt")
                Print #f, "#define DIS_" & FillRight(20, r.v("IR_PARA_CCU6_NODE1_INT")) & " " & SfrBitStatement(r, CORE_PREFIX & "IEN1_ECCIP1", 0, False) & "    " & FormatComments(0, 0, "", "", "Disables CCU6 Node 1 Interrupt")
                Print #f, "#define DIS_" & FillRight(20, r.v("IR_PARA_CCU6_NODE2_INT")) & " " & SfrBitStatement(r, CORE_PREFIX & "IEN1_ECCIP2", 0, False) & "    " & FormatComments(0, 0, "", "", "Disables CCU6 Node 2 Interrupt")
                Print #f, "#define DIS_" & FillRight(20, r.v("IR_PARA_CCU6_NODE3_INT")) & " " & SfrBitStatement(r, CORE_PREFIX & "IEN1_ECCIP3", 0, False) & "    " & FormatComments(0, 0, "", "", "Disables CCU6 Node 3 Interrupt")
                Print #f, "#define DIS_" & FillRight(20, r.v("IR_PARA_T0_INT")) & " " & SfrBitStatement(r, CORE_PREFIX & "IEN0_ET0", 0, False)
            Else
                Print #f, "#define DIS_" & FillRight(20, r.v("IR_PARA_XINTR9_INT")) & " " & SfrBitStatement(r, CORE_PREFIX & "IEN1_EXM", 0, False) & "       " & FormatComments(0, 0, "", "", "Disables External 3,4,5,6 and MultiCAN Node 3 Interrupts")
                Print #f, "#define DIS_" & FillRight(20, r.v("IR_PARA_XINTR6_INT")) & " " & SfrBitStatement(r, CORE_PREFIX & "IEN1_EADC", 0, False) & "      " & FormatComments(0, 0, "", "", "Disables MultiCAN Nodes 1 ,2 and ADC Interrupts")
                Print #f, "#define DIS_" & FillRight(20, r.v("IR_PARA_XINTR10_INT")) & " " & SfrBitStatement(r, CORE_PREFIX & "IEN1_ECCIP0", 0, False) & "    " & FormatComments(0, 0, "", "", "Disables CCU6 Node 0 and MultiCAN Node 4 Interrupts")
                Print #f, "#define DIS_" & FillRight(20, r.v("IR_PARA_XINTR11_INT")) & " " & SfrBitStatement(r, CORE_PREFIX & "IEN1_ECCIP1", 0, False) & "    " & FormatComments(0, 0, "", "", "Disables CCU6 Node 1 and MultiCAN Node 5 Interrupts")
                Print #f, "#define DIS_" & FillRight(20, r.v("IR_PARA_XINTR12_INT")) & " " & SfrBitStatement(r, CORE_PREFIX & "IEN1_ECCIP2", 0, False) & "    " & FormatComments(0, 0, "", "", "Disables CCU6 Node 2 and MultiCAN Node 6 Interrupts")
                Print #f, "#define DIS_" & FillRight(20, r.v("IR_PARA_XINTR13_INT")) & " " & SfrBitStatement(r, CORE_PREFIX & "IEN1_ECCIP3", 0, False) & "    " & FormatComments(0, 0, "", "", "Disables CCU6 Node 3 and MultiCAN Node 7 Interrupts")
            End If
            Print #f, "#define DIS_" & FillRight(20, r.v("IR_PARA_T0_INT")) & " " & SfrBitStatement(r, CORE_PREFIX & "IEN0_ET0", 0, False) & "       " & FormatComments(0, 0, "", "", "Disables Timer 0 Interrupt")
            Print #f, "#define DIS_" & FillRight(20, r.v("IR_PARA_T1_INT")) & " " & SfrBitStatement(r, CORE_PREFIX & "IEN0_ET1", 0, False) & "       " & FormatComments(0, 0, "", "", "Disables Timer 1 Interrupt")
            Print #f, "#define DIS_" & FillRight(20, r.v("IR_PARA_XINTR5_INT")) & " " & SfrBitStatement(r, CORE_PREFIX & "IEN0_ET2", 0, False) & "       " & FormatComments(0, 0, "", "", "Disables T2,BRG and MultiCAN Node 0 Interrupts")
            Print #f, "#define DIS_" & FillRight(20, r.v("IR_PARA_UART_INT")) & " " & SfrBitStatement(r, CORE_PREFIX & "IEN0_ES", 0, False) & "        " & FormatComments(0, 0, "", "", "Disables UART Interrupt")
            Print #f, "#define DIS_" & FillRight(20, r.v("IR_PARA_SSC_INT")) & " " & SfrBitStatement(r, CORE_PREFIX & "IEN1_ESSC", 0, False) & "      " & FormatComments(0, 0, "", "", "Disables SSC Interrupt")
            Print #f, ""
            Print #f, ""
    End If

    '------------------------------------------------------------------------------------------------
            Print #f, SECTION_INTERRUPT_VECTORS
            Print #f, ""  'DAvE interrupt vector definitions
    For iInt = 0 To NUMBER_OF_EXT_INTERRUPTS - 1

        If (r.v("IR_USE_IsrExt" & iInt) = 1) Then
           If ((iInt = 0) Or (iInt = 1)) Then
            Print #f, "#define EXT" & iInt & "INT " & IntNumber(ExtIntVectorAddr(iInt))
           ElseIf (iInt = 2) Then
              Print #f, FormatComments(0, 0, "", "", "Shared interrupt vector definitions are defined in SHARED_INT.H")
           Else
              If (Not IsCpuTypeOK(r)) Then
                 Print #f, "#define EXT" & iInt & "INT " & IntNumber(ExtIntVectorAddr(iInt))
              ElseIf (r.v("IR_USE_IsrExt2") <> 1) Then
                 Print #f, FormatComments(0, 0, "", "", "Shared interrupt vector definitions are defined in SHARED_INT.H")
              End If
           End If
        End If
    
    Next iInt
 If (r.v("IR_USE_IsrNMI") = 1) Then
            Print #f, "#define NMIINT " & IntNumber(&H73)
        End If
            Print #f, ""
            Print #f, uc.GetUserCode("(IR_Header,9)", 0)
            Print #f, ""
            Print #f, "#endif  // ifndef _" & StripExtension(r.v("IR_HFILE")) & "_H_"
    
    'close file
    Close f
    
    IRGenerateH = True
    Exit Function
    
IRGenerateHError:
    errorbox "error ir.h", Err.Description
    Close f
    Exit Function
End Function

