Attribute VB_Name = "Module1"
'#Uses "..\include\Const.inc"
'#Uses "..\include\Global.inc"
'#Uses "..\include\Format.inc"
'#Uses "..\classes\FunctionClass.cls
'#Uses "Include.inc"
Option Explicit
'*****************************************************************************
' Module:
'        T2
'-----------------------------------------------------------------------------
' Description:
'        This file contains functions for generating code for the
'        module 'T2'.
'
'-----------------------------------------------------------------------------
' History:
'
'        Rev. Author         Date        Description
'        ---------------------------------------------------------------------
'        0.1  Sunil          19-10-04    Initial version
'        0.2  Sunil          17-11-04    code statement for T2CON_CP/RL2 changed.
'        0.3  Sunil          02-12-04    RCLK and TCLK (baudrate generator bits)
'                                        related code removed.
'        0.4  Sunil          29-12-04    module prefix added.
'
'
'*****************************************************************************


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

    ' write files T2.h
    If (r.v("T2_USE_Init")) Then
        If (Not T2GenerateH(r, vIndex)) Then Exit Function
        If (Not r.AddFile(r.s("T2_HFILE"), "H")) Then Exit Function
    End If

    ' write file T2.c
    If (r.v("T2_USE_Init")) Then
        If (Not T2GenerateC(r, vIndex)) Then Exit Function
        If (Not r.AddFile(r.s("T2_CFILE"), "C")) Then Exit Function
    End If

        
    StartGenerateCode = True
    Exit Function
    
StartGenerateCodeError:
    errorbox "Code generation for T2 failed", Error$
    Exit Function
End Function


'*****************************************************************************
'Description:
'        Generates the code for the T2.c file.
'-----------------------------------------------------------------------------
'Parameters:
'        r                reference to the Registers object
'        vIndex           a parameter
'-----------------------------------------------------------------------------
'Returns:
'        True            on successful operation
'        False           else
'*****************************************************************************
Function T2GenerateC(r As ProjectData, vIndex As Variant) As Boolean
    On Error GoTo T2GenerateCError
    
    Dim i As Integer
    Dim f As Variant
    Dim v As Variant
    Dim d As String
    Dim dc As DAvECollection
    Dim uc As UserCode
    Dim func As FunctionClass
    Dim lCh As Long
    
    T2GenerateC = 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("T2_CFILE"))

    'open T2.c
    f = FreeFile
    Open CStr(StripFilenameAndExtension(r.LoadedFile)) & "\" & r.v("T2_CFILE") For Output As f
    
    '------------------------------------------------------------------------------------------------
    ' module header
    '------------------------------------------------------------------------------------------------
    d = FormatModuleDescription(GetModuleHeaderC("T2"))
    Print #f, Rtf.GenerateModuleHeader(DefGetValue("ProductVersion"), StripPath(r.LoadedFile), dc("T2").ModuleDescription, r.v("T2_CFILE"), r.v("MAIN_CPU_TYPE"), r.v("MAIN_COMPILER"), d)
          
            Print #f, uc.GetUserCode("(T2_General,1)", 0)   'USER CODE for application specific descriptions'
            Print #f, ""
            Print #f, Rtf.GenerateNote((r.v("T2_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("(T2_General,2)", 0)
            Print #f, ""
            Print #f, ""
            Print #f, SECTION_MACROS
            Print #f, ""  'DAvE local macro definitions'
            Print #f, uc.GetUserCode("(T2_General,3)", 0)
            Print #f, ""
            Print #f, ""
            Print #f, SECTION_DEFINES
            Print #f, ""  'DAvE local #define definitions'
            Print #f, uc.GetUserCode("(T2_General,4)", 0)
            Print #f, ""
            Print #f, ""
            Print #f, SECTION_TYPEDEFS
            Print #f, ""  'DAvE type defintions'
            Print #f, uc.GetUserCode("(T2_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("(T2_General,6)", 0)
            Print #f, ""
            Print #f, ""
            Print #f, SECTION_GLOBAL_VARIABLES
            Print #f, ""  'DAvE definitions of global variables'
            Print #f, uc.GetUserCode("(T2_General,7)", 0)
            Print #f, ""
            Print #f, ""
            Print #f, SECTION_EXTERNAL_PROTOTYPES
            Print #f, ""  'DAvE external declarations of imported functions'
            Print #f, uc.GetUserCode("(T2_General,8)", 0)
            Print #f, ""
            Print #f, ""
            Print #f, SECTION_LOCAL_PROTOTYPES
            Print #f, ""  'DAvE declarations of internal local functions'
            Print #f, uc.GetUserCode("(T2_General,9)", 0)
            Print #f, ""
            Print #f, ""
    '------------------------------------------------------------------------------------------------
    ' T2_Init function
    '------------------------------------------------------------------------------------------------
    If (r.v("T2_USE_Init") = 1) Then
        Print #f, FormatFunctionHeader(r, func, "T2_NAME_Init")
            Print #f, uc.GetUserCode("(T2_Init,1)", 0)     'USER CODE for application specific descriptions'
            Print #f, ""
                      '<--                     max. 78 characters                                -->'
            Print #f, FormatFunctionDeclaration(r, func, "T2_NAME_Init")
            Print #f, "{"
            Print #f, uc.GetUserCode("(T2_Init,2)", 2)
            Print #f, ""

            '==========================================================================
            Print #f, FormatSectionHeader(2, 0, "Operating Mode")
            Print #f, ""

    If (r.l(T2_PREFIX & "T2CON_C/T2") = 0) Then
      '-------------- Timer Mode -----------
      If (r.l(T2_PREFIX & "T2CON_CP/RL2") = 0) Then
        '---- Timer and Reload mode ----

            Print #f, FormatComments(2, 1, "", "", "16-bit timer function with automatic reload when timer 2 overflows")
                    
            If (r.v(T2_PREFIX & "T2CON_EXEN2") = 1) Then
              If (r.v(T2_PREFIX & "T2MOD_EDGESEL") = 1) Then
                d = "positive"
              Else
                d = "negative"
              End If
              '---- External Reload -----
              Print #f, FormatComments(2, 1, "", "", "additional reload of T2 when a " & d & " transition occurs on pin T2EX")
              
            End If
        
            
      Else
        '---- Timer and Capture mode ----

            Print #f, FormatComments(2, 1, "", "", "16-bit timer function")

            If (r.v(T2_PREFIX & "T2CON_EXEN2") = 1) Then
              '---- External capture ----
              If (r.v(T2_PREFIX & "T2MOD_EDGESEL") = 1) Then
                d = "positive"
              Else
                d = "negative"
              End If
                Print #f, FormatComments(2, 1, "", "", "capture timer 2 when a " & d & " transition occurs on pin T2EX")
            End If
      End If
      
    Else
      '---- Counter Mode ----
      Print #f, FormatComments(2, 1, "", "", "T2_1 input pin is selected for count operation.")
      
      If (r.d(T2_PREFIX & "T2CON_CP/RL2") = 0) Then
        '---- Counter and Reload mode ----
            Print #f, FormatComments(2, 1, "", "", "16-bit counter function with automatic reload when timer 2 overflows")
    
        If (r.v(T2_PREFIX & "T2CON_EXEN2") = 1) Then
              If (r.v(T2_PREFIX & "T2MOD_EDGESEL") = 1) Then
                d = "positive"
              Else
                d = "negative"
              End If
              '---- External Reload -----
              Print #f, FormatComments(2, 1, "", "", "additional reload of T2 when a " & d & " transition occurs on pin T2EX")
              
            End If
      Else
        '---- Counter and Capture mode ----
        
            Print #f, FormatComments(2, 1, "", "", "16-bit counter function")

            If (r.v(T2_PREFIX & "T2CON_EXEN2") = 1) Then
              '---- External capture ----
              If (r.v(T2_PREFIX & "T2MOD_EDGESEL") = 1) Then
                d = "positive"
              Else
                d = "negative"
              End If
                Print #f, FormatComments(2, 1, "", "", "capture timer 2 when a " & d & " transition occurs on pin T2EX")
            End If
      End If
    End If
          
      If (r.v(T2_PREFIX & "T2MOD_T2RHEN") = 1) Then
        Print #f, FormatComments(2, 1, "", "", "Timer2 external start is enabled")
        If (r.v(T2_PREFIX & "T2MOD_T2REGS") = 1) Then
                d = "Rising"
              Else
                d = "Falling"
              End If
                Print #f, FormatComments(2, 1, "", "", d & " edge is selected at pin T2EX for external timer start")
      End If
        
        If (r.v(T2_PREFIX & "T2MOD_PREN") = 1) Then
            If r.l(T2_PREFIX & "T2MOD_T2PRE") = 0 Then
                Print #f, FormatComments(2, 1, "", "", "Prescaler enabled - input clock = " & "fPCLK")
            Else
                Print #f, FormatComments(2, 1, "", "", "Prescaler enabled - input clock = " & "fPCLK/" & 2 ^ r.l(T2_PREFIX & "T2MOD_T2PRE"))
            End If
        End If
        
        Print #f, FormatComments(2, 1, "", "", "the timer 2 resolution is " & GetTimer2Resolution(r) & " " & TXT_US)
        Print #f, FormatComments(2, 1, "", "", "the timer 2 overflow is " & GetTimer2Overflow(r) & " " & TXT_US)
        

        If (r.v(T2_PREFIX & "T2MOD_DCEN") = 1) Then
            Print #f, FormatComments(2, 1, "", "", "enable timer 2 as an up/down counter depending on pin T2EX")
            Print #f, FormatComments(2, 1, "", "", "the timer 2 underflow is " & GetTimer2Underflow(r) & " " & TXT_US)
        End If
        
        If r.v("Timer2_EXF2_Pin_P1.5_Used") = 1 Then
                Print #f, FormatComments(2, 1, "", "", "Pin P1.5 (EXF2_0) is selected for EXF2 output")
            ElseIf r.v("Timer2_EXF2_Pin_P0.1_Used") = 1 Then
                Print #f, FormatComments(2, 1, "", "", "Pin P0.1 (EXF2_1) is selected for EXF2 output")
        End If
        
        
        If (r.v(CORE_PREFIX & "IEN0_ET2") = 0) Then
                Print #f, FormatComments(2, 1, "", "", "timer 2 interrupt: disabled")
        Else
                Print #f, FormatComments(2, 1, "", "", "timer 2 interrupt: enabled")
        End If
        
        If (r.v(T2_PREFIX & "T2CON_TR2") = 0) Then
                Print #f, FormatComments(2, 1, "", "", "timer 2 remains stopped")
        Else
                Print #f, FormatComments(2, 1, "", "", "timer 2 will be started")
        End If
   
           Print #f, ""
            '==========================================================================
            Print #f, FormatSectionHeader(2, 0, "Register Initialization")
            Print #f, ""

            If (r.sfr(T2_PREFIX & "T2H") <> 0 Or r.sfr(T2_PREFIX & "T2L") <> 0) Then
                    Print #f, FormatCodeStatemente(2, T2_PREFIX & "T2L", "=", FormatTextOutput(r.sfr(T2_PREFIX & "T2L"), "H2"), "load timer 2  register,   low byte")
                    Print #f, ""
                    Print #f, FormatCodeStatemente(2, T2_PREFIX & "T2H", "=", FormatTextOutput(r.sfr(T2_PREFIX & "T2H"), "H2"), "load timer 2  register,   high byte")
            Else
                    Print #f, FormatComments(2, 0, "", "", "the reset values of T2H and T2L are not changed")
            End If
            Print #f, ""
            If (r.sfr(T2_PREFIX & "RC2H") <> 0 Or r.sfr(T2_PREFIX & "RC2L") <> 0) Then
                    Print #f, FormatCodeStatemente(2, T2_PREFIX & "RC2L", "=", FormatTextOutput(r.sfr(T2_PREFIX & "RC2L"), "H2"), "load timer 2 reload/capture register,   low byte")
                    Print #f, FormatCodeStatemente(2, T2_PREFIX & "RC2H", "=", FormatTextOutput(r.sfr(T2_PREFIX & "RC2H"), "H2"), "load timer 2 reload/capture register,   high byte")
            Else
                    Print #f, FormatComments(2, 0, "", "", "the reset values of RC2H and RC2L are not changed")
            End If
            
            If (r.v("Timer2_EXF2_Pin_P1.5_Used") = 1 Or r.v("Timer2_EXF2_Pin_P0.1_Used") = 1) Then
                Print #f, ""
                Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & PORT_PAGE_NAME & "2, noSST);", "", "", "switch to page 2 without saving")
                
                If r.v("Timer2_EXF2_Pin_P1.5_Used") = 1 Then
                    Print #f, FormatCodeStatemente(2, "P1_ALTSEL0", "|=", "(ubyte)0x20", "configure alternate function register 0")
                    Print #f, FormatCodeStatemente(2, "P1_ALTSEL1", "&=", "~(ubyte)0x20", "configure alternate function register 1")
                    Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & PORT_PAGE_NAME & "0, noSST);", "", "", "switch to page 0 without saving")
                    Print #f, FormatCodeStatemente(2, "P1_DIR", "|=", "(ubyte)0x20", "set output direction")
                    Print #f, ""
                End If
                
                If r.v("Timer2_EXF2_Pin_P0.1_Used") = 1 Then
                    Print #f, FormatCodeStatemente(2, "P0_ALTSEL0", "|=", "(ubyte)0x02", "configure alternate function register 0")
                    Print #f, FormatCodeStatemente(2, "P0_ALTSEL1", "&=", "~(ubyte)0x02", "configure alternate function register 1")
                    Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & PORT_PAGE_NAME & "0, noSST);", "", "", "switch to page 0 without saving")
                    Print #f, FormatCodeStatemente(2, "P0_DIR", "|=", "(ubyte)0x02", "set output direction")
                    Print #f, ""
                End If
                
            End If
          
            
            Print #f, FormatCodeStatemente(2, T2_PREFIX & "T2MOD", "=", FormatTextOutput(r.sfr(T2_PREFIX & "T2MOD"), "H2"), "load timer 2 mode register")
            
            If (r.l(T2_PREFIX & "T2CON_C/T2") = 1) Then
                Print #f, ""
                Print #f, FormatCodeStatemente(2, Identifier(r, SfrBitStatement(r, T2_PREFIX & "T2CON_C/T2", 1)), "", "", "Enable counter operation")
                Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "3, noSST);", "", "", "switch to page 3")
                Print #f, FormatCodeStatemente(2, SCU_PREFIX & "MODPISEL2", "|=", "(ubyte)0x04", "configure peripheral input select register2")
                Print #f, FormatCodeStatemente(2, "SFR_PAGE(" & SCU_PAGE_NAME & "0, noSST);", "", "", "switch to page 0")
            End If
            Print #f, ""
            
            If (r.l(T2_PREFIX & "T2CON_CP/RL2") = 1) Then
                Print #f, FormatCodeStatemente(2, Identifier(r, SfrBitStatement(r, T2_PREFIX & "T2CON_CP/RL2", 1)), "", "", "Capture/Reload select")
            End If
            
            If (r.l(T2_PREFIX & "T2CON_EXEN2") = 1) Then
                Print #f, FormatCodeStatemente(2, SfrBitStatement(r, T2_PREFIX & "T2CON_EXEN2", 1), "", "", "External enable control")
            End If
            
            If (r.v(CORE_PREFIX & "IEN0_ET2") = 1) Then
                  Print #f, FormatComments(2, 1, "", "", "timer 2 Interrupt enable bit is set in SHINT_vInit() function")
            End If

            Print #f, ""
            '--------------------------------------------------------------------------
            Print #f, uc.GetUserCode("(T2_Init,3)", 2)
            
            Print #f, ""
            
            If (r.v(T2_PREFIX & "T2CON_TR2") = 1) Then
                    Print #f, "  " & SfrBitStatement(r, T2_PREFIX & "T2CON_TR2", 1) & " " & _
                                    FormatComments(0, 0, "", "", "start timer")
            Else
                    Print #f, FormatComments(2, 0, "", "", "timer 2 remains stopped")
            End If
            
            Print #f, ""
            Print #f, "} " & END_OF_FUNCTION & r.v("T2_NAME_Init")
            Print #f, ""
            Print #f, ""
    End If

    '------------------------------------------------------------------------------------------------
            Print #f, uc.GetUserCode("(T2_General,10)", 0)
            Print #f, ""
    
    'close file
    Close f
    
    T2GenerateC = True
    Exit Function
    
T2GenerateCError:
    errorbox "Error T2GenerateC", Err.Description
    Close f
    Exit Function
End Function


'*****************************************************************************
'Description:
'        Generates the code for the T2.h file.
'-----------------------------------------------------------------------------
'Parameters:
'        r                reference to the Registers object
'        vIndex           a parameter
'-----------------------------------------------------------------------------
'Returns:
'        True            on successful operation
'        False           else
'*****************************************************************************
Function T2GenerateH(r As ProjectData, vIndex As Variant) As Boolean
    On Error GoTo T2GenerateHError
    
    Dim i 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
    Dim lCh As Long
   
    T2GenerateH = 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("T2_HFILE"))
    
    'open T2.h
    f = FreeFile
    Open CStr(StripFilenameAndExtension(r.LoadedFile)) & "\" & r.v("T2_HFILE") For Output As f
    
    '------------------------------------------------------------------------------------------------
    ' module header
    '------------------------------------------------------------------------------------------------
    d = FormatModuleDescription(GetModuleHeaderH("T2"))
    Print #f, Rtf.GenerateModuleHeader(DefGetValue("ProductVersion"), StripPath(r.LoadedFile), dc("T2").ModuleDescription, r.v("T2_HFILE"), r.v("MAIN_CPU_TYPE"), r.v("MAIN_COMPILER"), d)
            
            Print #f, uc.GetUserCode("(T2_Header,1)", 0)
            Print #f, ""
            Print #f, Rtf.GenerateNote((r.v("T2_Notes")))
            Print #f, ""
            Print #f, "#ifndef _" & StripExtension(r.v("T2_HFILE")) & "_H_"
            Print #f, "#define _" & StripExtension(r.v("T2_HFILE")) & "_H_"
            Print #f, ""
            Print #f, SECTION_PROJECT_INCLUDES
            Print #f, ""  'DAvE includes'
            Print #f, uc.GetUserCode("(T2_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("(T2_Header,3)", 0)
            Print #f, ""
            Print #f, ""
            Print #f, SECTION_DEFINES
            Print #f, ""  'DAvE global #define definitions'
            Print #f, uc.GetUserCode("(T2_Header,4)", 0)
            Print #f, ""

            'the T2 function library does not use constants

            Print #f, SECTION_TYPEDEFS
            Print #f, ""  'DAvE type definitions'
            Print #f, uc.GetUserCode("(T2_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("(T2_Header,6)", 0)
            Print #f, ""
            Print #f, ""
            Print #f, SECTION_GLOBAL_VARIABLES
            Print #f, ""  'DAvE definition of global variables'
            Print #f, uc.GetUserCode("(T2_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("T2_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("(T2_Header,8)", 0)
            Print #f, ""
            Print #f, ""
                          'DAvE declarations of global macros'
    '------------------------------------------------------------------------------------------------
    ' T2_StartTmr macro
    '------------------------------------------------------------------------------------------------
    If (r.v("T2_USE_StartTmr") = 1) Then
    Print #f, FormatFunctionHeader(r, func, "T2_NAME_StartTmr")

            Print #f, "#define " & r.v("T2_NAME_StartTmr") & "() " & SfrBitStatement(r, T2_PREFIX & "T2CON_TR2", 1, False)
            Print #f, ""
            Print #f, ""
    End If
  
    '------------------------------------------------------------------------------------------------
    ' T2_StopTmr macro
    '------------------------------------------------------------------------------------------------
    If (r.v("T2_USE_StopTmr") = 1) Then
    Print #f, FormatFunctionHeader(r, func, "T2_NAME_StopTmr")

            Print #f, "#define " & r.v("T2_NAME_StopTmr") & "() " & SfrBitStatement(r, T2_PREFIX & "T2CON_TR2", 0, False)
            Print #f, ""
            Print #f, ""
    End If
  
    '------------------------------------------------------------------------------------------------
    ' T2_ReadTmr macro
    '------------------------------------------------------------------------------------------------
    If (r.v("T2_USE_ReadTmr") = 1) Then
    Print #f, FormatFunctionHeader(r, func, "T2_NAME_ReadTmr")
           If (r.v("MAIN_COMPILER") = "Keil") Then
              Print #f, "#define " & r.v("T2_NAME_ReadTmr") & "() " & T2_PREFIX & "T2LH"
           Else
              Print #f, "#define " & r.v("T2_NAME_ReadTmr") & "() ((((uword)" & SfrName(r, T2_PREFIX & "T2H") & ") << 8) + " & SfrName(r, T2_PREFIX & "T2L") & ")"
           End If
           Print #f, ""
           Print #f, ""
    End If
    '------------------------------------------------------------------------------------------------
    ' T2_SetRC2Reg macro
    '------------------------------------------------------------------------------------------------
    If (r.v("T2_USE_SetRC2Reg") = 1) Then
    Print #f, FormatFunctionHeader(r, func, "T2_NAME_SetRC2Reg")

            If (r.v("MAIN_COMPILER") = "Keil") Then
               Print #f, "#define " & r.v("T2_NAME_SetRC2Reg") & "(Value)  " & T2_PREFIX & "RC2LH" & " = " & "Value"
            Else
               Print #f, "#define " & r.v("T2_NAME_SetRC2Reg") & "(Value) { uword uwTmp = Value; \"
               Print #f, "    " & SfrName(r, T2_PREFIX & "RC2H") & " = (ubyte)(uwTmp >> 8); " & SfrName(r, T2_PREFIX & "RC2L") & " = (ubyte)uwTmp; }"
            End If
            Print #f, ""
            Print #f, ""
    End If
    '------------------------------------------------------------------------------------------------
    ' T2_GetRC2Reg macro
    '------------------------------------------------------------------------------------------------
    If (r.v("T2_USE_GetRC2Reg") = 1) Then
    Print #f, FormatFunctionHeader(r, func, "T2_NAME_GetRC2Reg")

            If (r.v("MAIN_COMPILER") = "Keil") Then
                Print #f, "#define " & r.v("T2_NAME_GetRC2Reg") & "() " & T2_PREFIX & "RC2LH"
            Else
               Print #f, "#define " & r.v("T2_NAME_GetRC2Reg") & "() ((((uword)" & SfrName(r, T2_PREFIX & "RC2H") & ") << 8) + " & SfrName(r, T2_PREFIX & "RC2L") & ")"
            End If
            Print #f, ""
            Print #f, ""
    End If
  
    '------------------------------------------------------------------------------------------------
            Print #f, SECTION_INTERRUPT_VECTORS
            Print #f, ""  'DAvE interrupt vector definitions
            Print #f, ""

    If (r.v("T2_USE_IsrTmr") = 1) Then
            'Print #f, "#define T2INT   " & IntNumber(&H2B)
            Print #f, FormatComments(0, 0, "", "", "Shared interrupt vector definitions are defined in SHARED_INT.H")
    End If
            Print #f, ""
            Print #f, uc.GetUserCode("(T2_Header,9)", 0)
            Print #f, ""
            Print #f, "#endif  // ifndef _" & StripExtension(r.v("T2_HFILE")) & "_H_"
    
    'close file
    Close f
    
    T2GenerateH = True
    Exit Function
    
T2GenerateHError:
    Close f
    Exit Function
End Function

