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

Option Explicit
'*****************************************************************************
' Module:
'        GPT2
'-----------------------------------------------------------------------------
' Description:
'        This file contains functions for generating code for the
'        module 'GPT2'.
'
'-----------------------------------------------------------------------------
' History:
'                 
'        Rev. Author         Date        Description
'        ----------------------------------------------------------------------
'        2.0   ahe         13.06.00     final version for C167CS
'
'        ----------------------------------------------------------------------
'        2.1   ahe         02.08.00     final version for C167CS and C161CS/JC/JI
'                                       - check if T5EUD and T6EUD exists
'                                       - changes all from timer 3 to timer 6
'                                       - added 'sAlternatePinName(6) = "T6OUT"'
'
'              ahe         13.09.00     - added For-Next in SECTION_GLOBAL_PROTOTYPES
'
'        ---------------------------------------------------------------------
'              ahe         25.10.00    final version for 
'                                      - C167CS
'                                      - C161CS/JC/JI
'                                      - C167CR/SR r2
'
'        ----------------------------------------------------------------------
'        5.0   ahe         19.04.01     final version for Pegasus
'
'        5.1   ahe         08.08.02     no changes
'
'*****************************************************************************


'*****************************************************************************
'Description:
'        This functions initiates the code generation for the GPT2 module.
'-----------------------------------------------------------------------------
'Parameters:
'        r                reference to the Registers object
'        vIndex           a parameter
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Function StartGenerateCode(r As ProjectData, vIndex As Variant) As Boolean
    On Error GoTo StartGenerateCodeError
    StartGenerateCode = False
    Dim sVarPre As String
    sVarPre = "GPT2"
    
    ' write files GPT2.h
    If (r.v(sVarPre & "_USE_Init")) Then
      If (Not GPT2GenerateH(r, vIndex)) Then Exit Function
	 	   If (Not r.AddFile(r.s(sVarPre & "_HFILE"))) Then Exit Function
    End if

    ' write file GPT2.c
    If (r.v(sVarPre & "_USE_Init")) Then
      If (Not GPT2GenerateC(r, vIndex)) Then Exit Function
	 	   If (Not r.AddFile(r.s(sVarPre & "_CFILE"))) Then Exit Function
    End if

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


'*****************************************************************************
'Description:
'        Generates the code for the GPT2.c file.
'-----------------------------------------------------------------------------
'Parameters:
'        r                reference to the Registers object
'        vIndex           a parameter
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Function GPT2GenerateC(r As ProjectData, vIndex As Variant) As Boolean
    On Error GoTo GPT2GenerateCError
    
    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 sVarPre     As String
    Dim n           As String
    Dim TimerNr     As Variant
    Dim uFrequency  As UnitType
    Dim sAlternatePinName(1 To 8) As String


    GPT2GenerateC = False

    sVarPre = "GPT2"

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

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

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

    'open GPT2.c
    f = FreeFile
    Open CStr(StripFilenameAndExtension(r.LoadedFile)) & "\" & r.v(sVarPre & "_CFILE") For Output As f
    
    '------------------------------------------------------------------------------------------------
    ' module header
    '------------------------------------------------------------------------------------------------
    d = FormatModuleDescription(GetModuleHeaderC(sVarPre))
    Print #f, Rtf.GenerateModuleHeader(DefGetValue("ProductVersion"), StripPath(r.LoadedFile), dc(sVarPre).ModuleDescription, r.v(sVarPre & "_CFILE"), r.v("MAIN_CPU_TYPE"), r.v("MAIN_COMPILER"), d)
          
    Print #f, uc.GetUserCode("(" & sVarPre & "_General,1)",0)    'USER CODE for application specific descriptions'
    Print #f, ""
    Print #f, Rtf.GenerateNote((r.v(sVarPre & "_Notes")))
    Print #f, ""
    Print #f, SECTION_PROJECT_INCLUDES
    Print #f, ""  'DAvE includes'
    Print #f, "#include """ & r.v("MAIN_HFile") & """"
    Print #f, ""
    Print #f, uc.GetUserCode("(" & sVarPre & "_General,2)",0)
    Print #f, ""
    Print #f, ""
    Print #f, SECTION_MACROS
    Print #f, ""  'DAvE local macro definitions'
    Print #f, uc.GetUserCode("(" & sVarPre & "_General,3)",0)
    Print #f, ""
    Print #f, ""
    Print #f, SECTION_DEFINES
    Print #f, ""  'DAvE local #define definitions'
    Print #f, uc.GetUserCode("(" & sVarPre & "_General,4)",0)
    Print #f, ""
    Print #f, ""
    Print #f, SECTION_TYPEDEFS
    Print #f, ""  'DAvE type defintions'
    Print #f, uc.GetUserCode("(" & sVarPre & "_General,5)",0)
    Print #f, ""
    Print #f, ""
    Print #f, SECTION_IMPORTED_GLOBAL_VARIABLES
    Print #f, ""  'DAvE external declarations of imported global variables'
    Print #f, uc.GetUserCode("(" & sVarPre & "_General,6)",0)
    Print #f, ""
    Print #f, ""
    Print #f, SECTION_GLOBAL_VARIABLES
    Print #f, ""  'DAvE definitions of global variables'
    Print #f, uc.GetUserCode("(" & sVarPre & "_General,7)",0)
    Print #f, ""
    Print #f, ""
    Print #f, SECTION_EXTERNAL_PROTOTYPES
    Print #f, ""  'DAvE external declarations of imported functions'
    Print #f, uc.GetUserCode("(" & sVarPre & "_General,8)",0)
    Print #f, ""
    Print #f, ""
    Print #f, SECTION_LOCAL_PROTOTYPES
    Print #f, ""  'DAvE declarations of internal local functions'
    Print #f, uc.GetUserCode("(" & sVarPre & "_General,9)",0)
    Print #f, ""
    Print #f, ""

    '------------------------------------------------------------------------------------------------
    ' GPT2_vInit function
    '------------------------------------------------------------------------------------------------
    n = "Init"
    If (r.v(sVarPre & "_USE_" & n) = 1) Then
      Print #f, FormatFunctionHeader(r, func, sVarPre & "_NAME_" & n) 
      Print #f, uc.GetUserCode("(" & n & ",1)",0)      'USER CODE for application specific descriptions'
      Print #f, ""
      Print #f, FormatFunctionDeclaration(r, func, sVarPre & "_NAME_" & n)  
      Print #f, "{"
      Print #f, uc.GetUserCode("(" & n & ",2)",2) 
      Print #f, ""

      '------------------------------------------------------------------------------------------------
      ' Configuration of Timer Block Prescaler 2:
      '------------------------------------------------------------------------------------------------
      Print #f, FormatSectionHeader(2, 1, "Configuration of Timer Block Prescaler 2:")

      d = "prescaler for timer block 2 is " & _
          GetBPS2Factor(r.v(GPT12_ & "T6CON_BPS2"))

      Print #f, FormatCommentsForInit(1, d)    
      Print #f, ""
      Print #f, ""


      '------------------------------------------------------------------------------------------------
      ' Configuration of the GPT2 core timer 5:
      '------------------------------------------------------------------------------------------------
      TimerNr = 5
      Print #f, FormatSectionHeader(2, 1, "Configuration of the " & sVarPre & " Core Timer 5:")

      '--------------------------------------------------------- T5CON_T5M
      If (r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "M") = 0) Then
        d = "timer " & TimerNr & " works in timer mode"
        Print #f, FormatCommentsForInit(1, d)
      End If  

      If (r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "M") = 1) Then
        d = "timer " & TimerNr & " works in counter mode"
        Print #f, FormatCommentsForInit(1, d)
      End If  

      If (r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "M") = 2) Then
        d = "timer " & TimerNr & " works as gated timer with gate active low via T" & TimerNr & "IN (" & GetPinName("T" & TimerNr & "IN") & ")"
        Print #f, FormatCommentsForInit(1, d)
      End If  

      If (r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "M") = 3) Then
        d = "timer " & TimerNr & " works as gated timer with gate active high via T" & TimerNr & "IN (" & GetPinName("T" & TimerNr & "IN") & ")"
        Print #f, FormatCommentsForInit(1, d)
      End If  

      '--------------------------------------------------------- T5CON_T5I
      If (r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "M") = 0 Or _
          r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "M") = 2 Or _
          r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "M") = 3) Then
        d = "prescaler factor is " & GetBPS2Factor(r.v(GPT12_ & "T6CON_BPS2")) * _
            2 ^ (r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "I")) 
        Print #f, FormatCommentsForInit(1, d)    
      End If  

      If (r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "M") = 1) Then 'if counter mode
        Select Case (r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "I"))
                    Case (0)
                         d = "timer " & TimerNr & " is disabled"
                    Case (1)
                         d = "timer " & TimerNr & " is clocked by positive transition on T" & TimerNr & "IN (" & GetPinName("T" & TimerNr & "IN") & ")"     
                    Case (2)
                         d = "timer " & TimerNr & " is clocked by negative transition on T" & TimerNr & "IN (" & GetPinName("T" & TimerNr & "IN") & ")" 
                    Case (3) 
                         d = "timer " & TimerNr & " is clocked by any transition on T" & TimerNr & "IN (" & GetPinName("T" & TimerNr & "IN") & ")"
                    Case (5)
                         d = "timer " & TimerNr & " is clocked by positive transition of output toggle latch T6OTL"
                    Case (6)
                         d = "timer " & TimerNr & " is clocked by negative transition of output toggle latch T6OTL"     
                    Case (7)
                         d = "timer " & TimerNr & " is clocked by any transition of output toggle latch T6OTL"     
                         
        End Select
        Print #f, FormatCommentsForInit(1, d)    
      End If  

      '--------------------------------------------------------- T5CON_T5UD
      If (r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "UD") = 0) Then
        d = "up/down control bit is reset"
      Else
        d = "up/down control bit is set"
      End If
      Print #f, FormatCommentsForInit(1, d)

      'ahe 02.08.00 start
      If (r.Regs.BitFind(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "UDE") = True) Then
          '--------------------------------------------------------- T5CON_T5UDE
          If (r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "UDE") = 0) Then
            d = "external up/down control is disabled"
            Print #f, FormatCommentsForInit(1, d)
          Else
            d = "external up/down control via T" & TimerNr & "EUD (" & GetPinName("T" & TimerNr & "EUD") & ") is enabled"
            Print #f, FormatCommentsForInit(1, d)  
          End If
      End If
      'ahe end

      '--------------------------------------------------------- T5CON_T5R
      If (r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "R") = 0) Then  'if start bit = 0
        d = "timer " & TimerNr & " run bit is reset"
        Print #f, FormatCommentsForInit(1, d)
      End If

      '--------------------------------------------------------- T5CON_T5RC
      If (r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "RC") = 1) Then
        d = "timer " & TimerNr & " is controlled by the run bit T6R"
        Print #f, FormatCommentsForInit(1, d)
      Else
        d = "timer " & TimerNr & " remote control is disabled"
        Print #f, FormatCommentsForInit(1, d)
      End If

      Print #f, ""

      v = 0

      'ahe 02.08.00 start
      If (r.Regs.BitFind(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "UDE") = True) Then
          v = v + r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "UDE") * 2 ^ 8
      End If
      'ahe end

      v = v + r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "UD") * 2 ^ 7
      v = v + r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "M") * 2 ^ 3
      v = v + r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "I")
    
      Print #f, FormatCodeStatemente(2, GPT12_ & "T" & TimerNr & "CON", "=", _
                FormatTextOutput(v, "H4"), _
                "load timer " & TimerNr & " control register")

      v = 0
      v = r.sfr(GPT12_ & "T" & TimerNr)
      Print #f, FormatCodeStatemente(2, GPT12_ & "T" & TimerNr, "=", _
                FormatTextOutput(v, "H4"), _
                "load timer " & TimerNr & " register")
      Print #f, ""

      
      '------------------------------------------------------------------------------------------------
      ' Configuration of the GPT2 core timer 6:
      '------------------------------------------------------------------------------------------------
      TimerNr = 6
      Print #f, FormatSectionHeader(2, 1, "Configuration of the " & sVarPre & " Core Timer 6:")

      '--------------------------------------------------------- T6CON_T6M
      If (r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "M") = 0) Then
        d = "timer " & TimerNr & " works in timer mode"
        Print #f, FormatCommentsForInit(1, d)
      End If  

      If (r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "M") = 1) Then
        d = "timer " & TimerNr & " works in counter mode"
        Print #f, FormatCommentsForInit(1, d)
      End If  

      If (r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "M") = 2) Then
        d = "timer " & TimerNr & " works as gated timer with gate active low via T" & TimerNr & _
            "IN (" & GetPinName("T" & TimerNr & "IN") & ")"
        Print #f, FormatCommentsForInit(1, d)
      End If  

      If (r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "M") = 3) Then
        d = "timer " & TimerNr & " works as gated timer with gate active high via T" & TimerNr & _
            "IN (" & GetPinName("T" & TimerNr & "IN") & ")"
        Print #f, FormatCommentsForInit(1, d)
      End If  

      '--------------------------------------------------------- T6CON_T6I
      If (r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "M") = 0 Or _
          r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "M") = 2 Or _
          r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "M") = 3) Then
        d = "prescaler factor is " & GetBPS2Factor(r.v(GPT12_ & "T6CON_BPS2")) * _
            2 ^ (r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "I"))
        Print #f, FormatCommentsForInit(1, d)    
      End If  

      If (r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "M") = 1) Then 'if counter mode
        Select Case (r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "I"))
                    Case (0)
                         d = "timer " & TimerNr & " is disabled"
                    Case (1)
                         d = "timer " & TimerNr & " is clocked by positive transition on T" & _
                             TimerNr & "IN (" & GetPinName("T" & TimerNr & "IN") & ")"     
                    Case (2)
                         d = "timer " & TimerNr & " is clocked by negative transition on T" & _
                             TimerNr & "IN (" & GetPinName("T" & TimerNr & "IN") & ")" 
                    Case (3) 
                         d = "timer " & TimerNr & " is clocked by any transition on T" & _
                             TimerNr & "IN (" & GetPinName("T" & TimerNr & "IN") & ")"

        End Select
        Print #f, FormatCommentsForInit(1, d)    
      End If  

      '--------------------------------------------------------- T6CON_T6UD
      If (r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "UD") = 0) Then
        d = "up/down control bit is reset"
      Else
        d = "up/down control bit is set"
      End If
      Print #f, FormatCommentsForInit(1, d)

      'ahe 02.08.00 start
      If (r.Regs.BitFind(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "UDE") = True) Then
          '--------------------------------------------------------- T6CON_T6UDE
          If (r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "UDE") = 0) Then
            d = "external up/down control is disabled"
            Print #f, FormatCommentsForInit(1, d)
          Else
            d = "external up/down control via T" & TimerNr & "EUD (" & GetPinName("T" & TimerNr & "EUD") & ") is enabled"
            Print #f, FormatCommentsForInit(1, d)  
          End If
      End If
      'ahe end
      
     '--------------------------------------------------------- T6CON_T6OE
      If (r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "OE") = 0) Then
        d = "alternate output function T6OUT (" & GetPinName("T" & TimerNr & "OUT") & ") is disabled"
      Else
        d = "alternate output function T6OUT (" & GetPinName("T" & TimerNr & "OUT") & ") is enabled"
      End If
      Print #f, FormatCommentsForInit(1, d)

     '--------------------------------------------------------- T6CON_T6OTL
      If (r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "OTL") = 0) Then
        d = "timer " & TimerNr & " output toggle latch (T" & TimerNr & "OTL) is set to 0"
      Else
        d = "timer " & TimerNr & " output toggle latch (T" & TimerNr & "OTL) is set to 1"
      End If
      Print #f, FormatCommentsForInit(1, d)
 
     '--------------------------------------------------------- T6CON_T6R
      If (r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "R") = 0) Then  'if start bit = 0
        d = "timer " & TimerNr & " run bit is reset"
        Print #f, FormatCommentsForInit(1, d)
      End If

      '--------------------------------------------------------- if T6CON_T6SR = 1
      If (r.v(GPT12_ & "T6CON_T6SR") = 1) Then
        d = "CAPREL is used as a reload register for the core timer T6"
        Print #f, FormatCommentsForInit(1, d)
      End If

      '----------------------------------------------- T6CON_T6CLR
      If (r.v(GPT12_ & "T6CON_T6CLR") = 1) Then
        d = "timer 6 is cleared on a capture"
      Else
        d = "timer 6 is not cleared on a capture"
      End If
      Print #f, FormatCommentsForInit(1, d)

      Print #f, ""

      v = 0
      v = v + r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "SR") * 2 ^ 15
      v = v + r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "CLR") * 2 ^ 14
      v = v + r.v(GPT12_ & "T" & TimerNr & "CON_BPS2") * 2 ^ 11
      v = v + r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "OTL") * 2 ^ 10
      v = v + r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "OE") * 2 ^ 9

      'ahe 02.08.00 start
      If (r.Regs.BitFind(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "UDE") = True) Then
          v = v + r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "UDE") * 2 ^ 8
      End If
      'ahe end

      v = v + r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "UD") * 2 ^ 7
      v = v + r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "M") * 2 ^ 3
      v = v + r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "I")
    
      Print #f, FormatCodeStatemente(2, GPT12_ & "T" & TimerNr & "CON", "=", _
                FormatTextOutput(v, "H4"), _
                "load timer " & TimerNr & " control register")

      v = 0
      v = r.sfr(GPT12_ & "T" & TimerNr)
      Print #f, FormatCodeStatemente(2, GPT12_ & "T" & TimerNr, "=", _
                FormatTextOutput(v, "H4"), _
                "load timer " & TimerNr & " register")
      Print #f, ""

      
      '------------------------------------------------------------------------------------------------
      ' Configuration of the GPT2 CAPREL:
      '------------------------------------------------------------------------------------------------
      Print #f, FormatSectionHeader(2, 1, "Configuration of the " & sVarPre & " CAPREL:")

      '----------------------------------------------- T5CON_T5SC
      If (r.v(GPT12_ & "T5CON_T5SC") = 1) Then
        d = "capture T5 into CAPREL is enabled"
      Else
        d = "capture T5 into CAPREL is disabled"
      End If
      Print #f, FormatCommentsForInit(1, d)

      '----------------------------------------------- T5CON_CT3
      If (r.v(GPT12_ & "T5CON_CT3") = 1) Then
        d = "capture trigger from T3 input pins"
      Else
        d = "capture trigger from pin CAPIN"
      End If
      Print #f, FormatCommentsForInit(1, d)

      '----------------------------------------------- T5CON_CI
      If (r.v(GPT12_ & "T5CON_CT3") = 1) Then
        Select Case (r.v(GPT12_ & "T5CON_CI"))
                     Case (0)
                           d = "capure is disabled"
                     Case (1)
                           d = "capture on any transition on T3IN (" & GetPinName("T3IN_CAP") & ")"
                     Case (2)
                           d = "capture on any transition on T3EUD (" & GetPinName("T3EUD_CAP") & ")"
                     Case (3)
                           d = "capture on any transition on T3IN (" & GetPinName("T3IN_CAP") & ") or T3EUD (" & GetPinName("T3EUD_CAP") & ")"
        End Select         
      Else
        Select Case (r.v(GPT12_ & "T5CON_CI"))
                     Case (0)
                           d = "capure is disabled"
                     Case (1)
                           d = "capture on positive transition on CAPIN (" & GetPinName("CAPIN") & ")"
                     Case (2)
                           d = "capture on negative transition on CAPIN (" & GetPinName("CAPIN") & ")"
                     Case (3)
                           d = "capture on any transition on CAPIN (" & GetPinName("CAPIN") & ")"
        End Select         
      End If
      Print #f, FormatCommentsForInit(1, d)

      '----------------------------------------------- T5CON_T5CLR
      If (r.v(GPT12_ & "T5CON_T5CLR") = 1) Then
        d = "timer 5 is cleared on a capture"
      Else
        d = "timer 5 is not cleared on a capture"
      End If
      Print #f, FormatCommentsForInit(1, d)

      '----------------------------------------------- T5CON_T5CC
      If (r.v(GPT12_ & "T5CON_T5CC") = 0) Then
        d = "timer 5 is just captured without any correction"
      Else
        d = "timer 5 is decremented by 1 before captured"
      End If
      Print #f, FormatCommentsForInit(1, d)

      Print #f, ""

      v = 0
      v = v + r.v(GPT12_ & "T5CON_T5SC") * 2 ^ 15
      v = v + r.v(GPT12_ & "T5CON_T5CLR") * 2 ^ 14
      v = v + r.v(GPT12_ & "T5CON_CI") * 2 ^ 12
      v = v + r.v(GPT12_ & "T5CON_T5CC") * 2 ^ 11
      v = v + r.v(GPT12_ & "T5CON_CT3") * 2 ^ 10
      Print #f, FormatCodeStatemente(2, GPT12_ & "T5CON", "|=", _
                FormatTextOutput(v, "H4"), _
                "load timer 5 control register")
      
      v = 0
      v = v + r.sfr(GPT12_ & "CAPREL")
      Print #f, FormatCodeStatemente(2, GPT12_ & "CAPREL", "=", _
                FormatTextOutput(v, "H4"), _
                "load CAPREL register")
      Print #f, ""

      '------------------------------------------------------------------------------------------------
      ' Configuration of the used GPT2 Port Pins:
      '------------------------------------------------------------------------------------------------
      Print #f, FormatSectionHeader(2, 1, "Configuration of the used " & sVarPre & " Port Pins:")

      sAlternatePinName(1) = "T6IN"
      sAlternatePinName(2) = "T5IN"
      sAlternatePinName(3) = "T3IN_CAP"
      sAlternatePinName(4) = "T3EUD_CAP"
      sAlternatePinName(5) = "CAPIN"
      sAlternatePinName(6) = "T6OUT"

      'ahe 02.08.00 start
      TimerNr = 5
      If (r.Regs.BitFind(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "UDE") = True) Then
          sAlternatePinName(7) = "T" & TimerNr & "EUD"
      End If
      'ahe end

      'ahe 02.08.00 start
      TimerNr = 6
      If (r.Regs.BitFind(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "UDE") = True) Then
          sAlternatePinName(8) = "T" & TimerNr & "EUD"
      End If
      'ahe end

      Call SetAlternatePinStatements(f, r, sAlternatePinName())
      Print #f, ""

      '------------------------------------------------------------------------------------------------
      ' Configuration of the used GPT2 Interrupts:
      '------------------------------------------------------------------------------------------------
      Print #f, FormatSectionHeader(2, 1, "Configuration of the used " & sVarPre & " Interrupts:")
      ' timer 5 interrupt
      TimerNr = 5
      Call GenerateIR(f, r, GPT12_ & "T" & TimerNr & "IC", "timer " & TimerNr)
      ' timer 6 interrupt
      TimerNr = 6
      Call GenerateIR(f, r, GPT12_ & "T" & TimerNr & "IC", "timer " & TimerNr)
      ' CAPREL interrupt
      Call GenerateIR(f, r, GPT12_ & "CRIC", "CAPREL")


      Print #f, ""
      Print #f, uc.GetUserCode("(" & sVarPre & "_Function,3)",2) 
      Print #f, ""

      TimerNr = 5
      If (r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "R") = 1) Then
        Print #f, FormatCodeStatemente(2, GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "R", _
                  "=", 1, "set timer " & TimerNr & " run bit")
        Print #f, ""
      End If

      If (r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "RC") = 1) Then
        Print #f, FormatCodeStatemente(2, GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "RC", _
                  "=", 1, "set timer " & TimerNr & " remote control bit")
        Print #f, ""
      End If

      TimerNr = 6
      If (r.v(GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "R") = 1) Then
        Print #f, FormatCodeStatemente(2, GPT12_ & "T" & TimerNr & "CON_T" & TimerNr & "R", _
                  "=", 1, "set timer " & TimerNr & " run bit")
        Print #f, ""
      End If

      Print #f, "} " & END_OF_FUNCTION & r.v(sVarPre & "_NAME_" & n)
      Print #f, ""
    End If

    '------------------------------------------------------------------------------------------------
    '------------------------------------------------------------------------------------------------
    ' GPT2_viTmr6 function
    '------------------------------------------------------------------------------------------------
    '------------------------------------------------------------------------------------------------
    TimerNr = 6
    n = "Tmr" & TimerNr
    If (IsISRSelected(r, sVarPre, GPT12_ & "T" & TimerNr & "IC", n)) Then
      Print #f, FormatFunctionHeader(r, func, sVarPre & "_NAME_" & n)        
      Print #f, uc.GetUserCode("(" & n & ",1)",0)      'USER CODE for application specific descriptions'
      Print #f, ""
      Print #f, GenerateIsrDeclaration(r, r.v(sVarPre & "_NAME_" & n), "T" & TimerNr & "INT")
      Print #f, "{"
      Print #f, uc.GetUserCode("(" & n & ",2)",2) 
      Print #f, ""
      Print #f, "} //  End of function " & r.v(sVarPre & "_NAME_" & n)
      Print #f, ""
      Print #f, ""
    End If

    '------------------------------------------------------------------------------------------------
    '------------------------------------------------------------------------------------------------
    ' GPT2_viTmr5 function
    '------------------------------------------------------------------------------------------------
    '------------------------------------------------------------------------------------------------
    TimerNr = 5
    n = "Tmr" & TimerNr
    If (IsISRSelected(r, sVarPre, GPT12_ & "T" & TimerNr & "IC", n)) Then
      Print #f, FormatFunctionHeader(r, func, sVarPre & "_NAME_" & n)        
      Print #f, uc.GetUserCode("(" & n & ",1)",0)      'USER CODE for application specific descriptions'
      Print #f, ""
      Print #f, GenerateIsrDeclaration(r, r.v(sVarPre & "_NAME_" & n), "T" & TimerNr & "INT")
      Print #f, "{"
      Print #f, uc.GetUserCode("(" & n & ",2)",2) 
      Print #f, ""
      Print #f, "} //  End of function " & r.v(sVarPre & "_NAME_" & n)
      Print #f, ""
      Print #f, ""
    End If

    '------------------------------------------------------------------------------------------------
    '------------------------------------------------------------------------------------------------
    ' GPT2_viCAPREL function
    '------------------------------------------------------------------------------------------------
    '------------------------------------------------------------------------------------------------
    n = "CAPREL"
    If (IsISRSelected(r, sVarPre, GPT12_ & "CRIC", n)) Then
      Print #f, FormatFunctionHeader(r, func, sVarPre & "_NAME_" & n)        
      Print #f, uc.GetUserCode("(" & n & ",1)",0)      'USER CODE for application specific descriptions'
      Print #f, ""
      Print #f, GenerateIsrDeclaration(r, r.v(sVarPre & "_NAME_" & n), "CRINT")
      Print #f, "{"
      Print #f, uc.GetUserCode("(" & n & ",2)",2) 
      Print #f, ""
      Print #f, "} //  End of function " & r.v(sVarPre & "_NAME_" & n)
      Print #f, ""
      Print #f, ""
    End If

    '------------------------------------------------------------------------------------------------
    ' Other function
    '------------------------------------------------------------------------------------------------

    Print #f, ""
    Print #f, ""
    Print #f, uc.GetUserCode("(" & sVarPre & "_General,10)",0)
    Print #f, ""
    
    'close file
    Close f
    
    GPT2GenerateC = True
    Exit Function
    
GPT2GenerateCError:
    Close f
    Exit Function
End Function


'*****************************************************************************
'Description:
'        Generates the code for the GPT2.h file.
'-----------------------------------------------------------------------------
'Parameters:
'        r                reference to the Registers object
'        vIndex           a parameter
'-----------------------------------------------------------------------------
'Returns:
'        True            on successfull operation
'        False           else
'*****************************************************************************
Function GPT2GenerateH(r As ProjectData, vIndex As Variant) As Boolean
    On Error GoTo GPT2GenerateHError
    
    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 para    As ParameterClass
    Dim sVarPre As String
    Dim n       As String
    Dim v       As Integer
    Dim l       As Long
   
    GPT2GenerateH = False

    sVarPre = "GPT2"

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

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

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

    n = "TIMER_5"
    Print #f, FormatParameterStatement(r, para, sVarPre & "_PARA_" & n, "5")
    n = "TIMER_6"
    Print #f, FormatParameterStatement(r, para, sVarPre & "_PARA_" & n, "6")

    Print #f, uc.GetUserCode("(" & sVarPre & "_Header,4)",0)
    Print #f, ""
    Print #f, ""
    Print #f, SECTION_TYPEDEFS
    Print #f, ""  'DAvE type definitions'
    Print #f, uc.GetUserCode("(" & sVarPre & "_Header,5)",0)
    Print #f, ""
    Print #f, ""
    Print #f, SECTION_IMPORTED_GLOBAL_VARIABLES
    Print #f, ""  'DAvE external declarations of imported global variables'
    Print #f, uc.GetUserCode("(" & sVarPre & "_Header,6)",0)
    Print #f, ""
    Print #f, ""
    Print #f, SECTION_GLOBAL_VARIABLES
    Print #f, ""  'DAvE definition of global variables'
    Print #f, uc.GetUserCode("(" & sVarPre & "_Header,7)",0)
    Print #f, ""
    Print #f, ""
    Print #f, SECTION_GLOBAL_PROTOTYPES
    Print #f, ""  'DAvE declarations of functions which should become global'
    
    ' for each function in this 'func' object
    For l = 1 To func.FunctionCount
      ' get the function name which was insert in 'Include.inc' with
      'AddFunction()'
      d = func.FunctionName(l)
      ' get only the third part of the function name (e.g "Init")
      n = Right(d, Len(d) - Instr(d, "NAME") - Len("NAME"))
      ' only if the use variable of the function is selected and the function is a really function
      ' not a macro or a ISR
      If (r.v(sVarPre & "_USE_" & n) = 1 AND func.FunctionSort(d) = 1) Then
            Print #f, FormatFunctionDeclaration(r, func, d) & ";"
      End If
    Next l
    
    Print #f, ""
    Print #f, uc.GetUserCode("(" & sVarPre & "_Header,8)",0)
    Print #f, ""
    
                          'DAvE declarations of global macros'
    
    '------------------------------------------------------------------------------------------------
    '------------------------------------------------------------------------------------------------
    ' GPT2_vStartTmr macro
    '------------------------------------------------------------------------------------------------
    '------------------------------------------------------------------------------------------------
    n = "StartTmr"
    If (r.v(sVarPre & "_USE_" & n) = 1) Then
      Print #f, FormatFunctionHeader(r, func, sVarPre & "_NAME_" & n)        
      Print #f, "#define " & FormatFunctionDeclaration(r, func, sVarPre & "_NAME_" & n) & _
                " " & r.v(sVarPre & "_NAME_" & n) & "_##TimerNr()" 
      Print #f, "#define " & r.v(sVarPre & "_NAME_" & n) & "_" & _
                r.v(sVarPre & "_PARA_TIMER_5") & "() " & GPT12_ & "T5CON_T5R = 1"
      Print #f, "#define " & r.v(sVarPre & "_NAME_" & n) & "_" & _
                r.v(sVarPre & "_PARA_TIMER_6") & "() " & GPT12_ & "T6CON_T6R = 1"
      Print #f, ""                                                                                    
      Print #f, ""
    End If

    '------------------------------------------------------------------------------------------------
    '------------------------------------------------------------------------------------------------
    ' GPT2_vStopTmr macro
    '------------------------------------------------------------------------------------------------
    '------------------------------------------------------------------------------------------------
    n = "StopTmr"
    If (r.v(sVarPre & "_USE_" & n) = 1) Then
      Print #f, FormatFunctionHeader(r, func, sVarPre & "_NAME_" & n)        
      Print #f, "#define " & FormatFunctionDeclaration(r, func, sVarPre & "_NAME_" & n) & " " _
                & r.v(sVarPre & "_NAME_" & n) & "_##TimerNr()" 
      Print #f, "#define " & r.v(sVarPre & "_NAME_" & n) & "_" & _
                r.v(sVarPre & "_PARA_TIMER_5") & "() " & GPT12_ & "T5CON_T5R = 0; " & GPT12_ & "T5CON_T5RC = 0"
      Print #f, "#define " & r.v(sVarPre & "_NAME_" & n) & "_" & _
                r.v(sVarPre & "_PARA_TIMER_6") & "() " & GPT12_ & "T6CON_T6R = 0"
      Print #f, ""                                                                                    
      Print #f, ""
    End If

    '------------------------------------------------------------------------------------------------
    '------------------------------------------------------------------------------------------------
    ' GPT2_vClearTmr macro
    '------------------------------------------------------------------------------------------------
    '------------------------------------------------------------------------------------------------
    n = "ClearTmr"
    If (r.v(sVarPre & "_USE_" & n) = 1) Then
      Print #f, FormatFunctionHeader(r, func, sVarPre & "_NAME_" & n)        
      Print #f, "#define " & FormatFunctionDeclaration(r, func, sVarPre & "_NAME_" & n) & " " & _
                r.v(sVarPre & "_NAME_" & n) & "_##TimerNr()" 
      Print #f, "#define " & r.v(sVarPre & "_NAME_" & n) & "_" & _
                r.v(sVarPre & "_PARA_TIMER_5") & "() " & _
                GPT12_ & "T5CON_T5R = 0; " & GPT12_ & "T5 = 0x0000; " & GPT12_ & "T5CON_T5RC = 0"
      Print #f, "#define " & r.v(sVarPre & "_NAME_" & n) & "_" & _
                r.v(sVarPre & "_PARA_TIMER_6") & "() " & _
                GPT12_ & "T6CON_T6R = 0; " & GPT12_ & "T6 = 0x0000"
      Print #f, ""                                                                                    
      Print #f, ""
    End If

    '------------------------------------------------------------------------------------------------
    '------------------------------------------------------------------------------------------------
    ' GPT2_ReadTmr macro
    '------------------------------------------------------------------------------------------------
    '------------------------------------------------------------------------------------------------
    n = "ReadTmr"
    If (r.v(sVarPre & "_USE_" & n) = 1) Then
      Print #f, FormatFunctionHeader(r, func, sVarPre & "_NAME_" & n)        

      Print #f, "#define " & FormatFunctionDeclaration(r, func, sVarPre & "_NAME_" & n) & " " & _
                r.v(sVarPre & "_NAME_" & n) & "_##TimerNr()" 
      Print #f, "#define " & r.v(sVarPre & "_NAME_" & n) & "_" & _
                r.v(sVarPre & "_PARA_TIMER_5") & "() " & _
                GPT12_ & "T5"
      Print #f, "#define " & r.v(sVarPre & "_NAME_" & n) & "_" & _
                r.v(sVarPre & "_PARA_TIMER_6") & "() " & _
                GPT12_ & "T6"
      Print #f, ""                                                                                    
      Print #f, ""
    End If

    '------------------------------------------------------------------------------------------------
    '------------------------------------------------------------------------------------------------
    ' GPT2_ReadCAPREL macro
    '------------------------------------------------------------------------------------------------
    '------------------------------------------------------------------------------------------------
    n = "ReadCAPREL"
    If (r.v(sVarPre & "_USE_" & n) = 1) Then
      Print #f, FormatFunctionHeader(r, func, sVarPre & "_NAME_" & n)        
      Print #f, "#define " & FormatFunctionDeclaration(r, func, sVarPre & "_NAME_" & n) & " " & _
                GPT12_ & "CAPREL" 
      Print #f, ""                                                                                    
      Print #f, ""
    End If

    '------------------------------------------------------------------------------------------------
    '------------------------------------------------------------------------------------------------
    ' GPT2_vLoadTmr macro
    '------------------------------------------------------------------------------------------------
    '------------------------------------------------------------------------------------------------
    n = "LoadTmr"
    If (r.v(sVarPre & "_USE_" & n) = 1) Then
      Print #f, FormatFunctionHeader(r, func, sVarPre & "_NAME_" & n)        
      Print #f, "#define " & FormatFunctionDeclaration(r, func, sVarPre & "_NAME_" & n) & " " & _
                r.v(sVarPre & "_NAME_" & n) & "_##TimerNr(Value)" 
      Print #f, "#define " & r.v(sVarPre & "_NAME_" & n) & "_" & _
                r.v(sVarPre & "_PARA_TIMER_5") & "(Value) " & _
                GPT12_ & "T5 = Value"
      Print #f, "#define " & r.v(sVarPre & "_NAME_" & n) & "_" & _
                r.v(sVarPre & "_PARA_TIMER_6") & "(Value) " & _
                GPT12_ & "T6 = Value"
      Print #f, ""                                                                                    
      Print #f, ""
    End If

    '------------------------------------------------------------------------------------------------
    '------------------------------------------------------------------------------------------------
    ' GPT2_LoadCAPREL macro
    '------------------------------------------------------------------------------------------------
    '------------------------------------------------------------------------------------------------
    n = "LoadCAPREL"
    If (r.v(sVarPre & "_USE_" & n) = 1) Then
      Print #f, FormatFunctionHeader(r, func, sVarPre & "_NAME_" & n)        
      Print #f, "#define " & FormatFunctionDeclaration(r, func, sVarPre & "_NAME_" & n) & " " & _
                GPT12_ & "CAPREL = Value" 
      Print #f, ""                                                                                    
      Print #f, ""
    End If

    '------------------------------------------------------------------------------------------------
    '------------------------------------------------------------------------------------------------
    ' GPT2_vSetToggLatch macro
    '------------------------------------------------------------------------------------------------
    '------------------------------------------------------------------------------------------------
    n = "SetToggLatch"
    If (r.v(sVarPre & "_USE_" & n) = 1) Then
      Print #f, FormatFunctionHeader(r, func, sVarPre & "_NAME_" & n)                       
      Print #f, "#define " & FormatFunctionDeclaration(r, func, sVarPre & "_NAME_" & n) & _
                " " & GPT12_ & "T6CON_T6OTL = 1" 
      Print #f, ""                                                                                    
      Print #f, ""
    End If

    '------------------------------------------------------------------------------------------------
    '------------------------------------------------------------------------------------------------
    ' GPT2_vClrToggLatch macro
    '------------------------------------------------------------------------------------------------
    '------------------------------------------------------------------------------------------------
    n = "ClrToggLatch"
    If (r.v(sVarPre & "_USE_" & n) = 1) Then
      Print #f, FormatFunctionHeader(r, func, sVarPre & "_NAME_" & n)                       
      Print #f, "#define " & FormatFunctionDeclaration(r, func, sVarPre & "_NAME_" & n) & _
                " " & GPT12_ & "T6CON_T6OTL = 0" 
      Print #f, ""                                                                                    
      Print #f, ""
    End If

    '------------------------------------------------------------------------------------------------
    '------------------------------------------------------------------------------------------------
    ' GPT2_vCountUp macro
    '------------------------------------------------------------------------------------------------
    '------------------------------------------------------------------------------------------------
    n = "CountUp"
    If (r.v(sVarPre & "_USE_" & n) = 1) Then
      Print #f, FormatFunctionHeader(r, func, sVarPre & "_NAME_" & n)        
      Print #f, "#define " & FormatFunctionDeclaration(r, func, sVarPre & "_NAME_" & n) & " " & r.v(sVarPre & "_NAME_" & n) & "_##TimerNr()
      Print #f, "#define " & r.v(sVarPre & "_NAME_" & n) & "_" & r.v(sVarPre & "_PARA_TIMER_5") & _
                "() " & GPT12_ & "T5CON_T5UD = 0"
      Print #f, "#define " & r.v(sVarPre & "_NAME_" & n) & "_" & r.v(sVarPre & "_PARA_TIMER_6") & _
                "() " & GPT12_ & "T6CON_T6UD = 0"
      Print #f, ""                                                                                    
      Print #f, ""
    End If

    '------------------------------------------------------------------------------------------------
    '------------------------------------------------------------------------------------------------
    ' GPT2_vCountDown macro
    '------------------------------------------------------------------------------------------------
    '------------------------------------------------------------------------------------------------
    n = "CountDown"
    If (r.v(sVarPre & "_USE_" & n) = 1) Then
      Print #f, FormatFunctionHeader(r, func, sVarPre & "_NAME_" & n)        
      Print #f, "#define " & FormatFunctionDeclaration(r, func, sVarPre & "_NAME_" & n) & " " & r.v(sVarPre & "_NAME_" & n) & "_##TimerNr()
      Print #f, "#define " & r.v(sVarPre & "_NAME_" & n) & "_" & r.v(sVarPre & "_PARA_TIMER_5") & _
                "() " & GPT12_ & "T5CON_T5UD = 1"
      Print #f, "#define " & r.v(sVarPre & "_NAME_" & n) & "_" & r.v(sVarPre & "_PARA_TIMER_6") & _
                "() " & GPT12_ & "T6CON_T6UD = 1"
      Print #f, ""                                                                                    
      Print #f, ""
    End If

    '------------------------------------------------------------------------------------------------
    '------------------------------------------------------------------------------------------------
    ' GPT2_vSetTmrRemoteControl macro
    '------------------------------------------------------------------------------------------------
    '------------------------------------------------------------------------------------------------
    n = "SetTmrRemoteControl"
    If (r.v(sVarPre & "_USE_" & n) = 1) Then
      Print #f, FormatFunctionHeader(r, func, sVarPre & "_NAME_" & n)        
      Print #f, "#define " & FormatFunctionDeclaration(r, func, sVarPre & "_NAME_" & n) & _
                " " & r.v(sVarPre & "_NAME_" & n) & "_##TimerNr()" 
      Print #f, "#define " & r.v(sVarPre & "_NAME_" & n) & "_" & _
                r.v(sVarPre & "_PARA_TIMER_5") & "() " & GPT12_ & "T5CON_T5RC = 1"
      Print #f, ""                                                                                    
      Print #f, ""
    End If

    '------------------------------------------------------------------------------------------------
    ' Interrupt Vectors
    '------------------------------------------------------------------------------------------------
    Print #f, SECTION_INTERRUPT_VECTORS
    Print #f, ""  'DAvE interrupt vector definitions
    
    n = "Tmr5"
    If (IsISRSelected(r, sVarPre, GPT12_ & "T5IC", n)) Then
      v = 37  
      Print #f, "#define T5INT " & FormatTextOutput(v, "H2")
    End If
    
    n = "Tmr6"
    If (IsISRSelected(r, sVarPre, GPT12_ & "T6IC", n)) Then
      v = 38
      Print #f, "#define T6INT " & FormatTextOutput(v, "H2")
    End If

    n = "CAPREL"
    If (IsISRSelected(r, sVarPre, GPT12_ & "CRIC", n)) Then
      v = 39
      Print #f, "#define CRINT " & FormatTextOutput(v, "H2")
    End If
    
    Print #f, ""
    Print #f, uc.GetUserCode("(" & sVarPre & "_Header,9)",0)
    Print #f, ""
    Print #f, ""
    Print #f, "#endif  // ifndef _" & StripExtension(r.v(sVarPre & "_HFILE")) & "_H_"


    
    'close file
    Close f
    
    GPT2GenerateH = True
    Exit Function
    
GPT2GenerateHError:
    Close f
    Exit Function
End Function


