Modified timer.h for 16f193x chips

Frank
2010-04-20
2013-05-30
  • Frank

    Frank - 2010-04-20

    The 16f193x chips have more sources to clock timer 1 so the TMR1CS bit in earlier PIC's has been replaced with TMR1CS0 and TMR1CS1. I wrote some minor mods to timer.h to get round the errors that come up if you try to use timer 1 on these devices. I'll just put the parts that need changing in timer.h if anyone wants to try them out.

    Add two sources -

    'Sources
    #define Osc 1
    #define Ext 2
    #define ExtOsc 3
    #define FOsc 4
    #define CapOsc 5

    Replace the sub SInitTimer1 with this -

    Sub SInitTimer1
    #ifdef bit(TMR1CS1)
    T1CON = TMR1Pres
    If TMR1Source = Ext Then
    Set TMR1CS1 On
    End If
    If TMR1Source = ExtOsc Then
    Set TMR1CS1 On
    Set T1OSCEN On
    End If
    If TMR1Source = FOsc Then
    Set TMR1CS0 on
    End If
    If TMR1Source = CapOsc Then
    Set TMR1CS0 on
    Set TMR1CS1 on
    End If
    #endif
    #ifndef bit(TMR1CS1)
    T1CON = TMR1Pres
    If TMR1Source = Ext Then
    Set TMR1CS On
    End If
    If TMR1Source = ExtOsc Then
    Set TMR1CS On
    Set T1OSCEN On
    End If
    #endif
    End Sub

    I've only tried it out with a 16F1936 so far.

    Frank

     
  • Frank

    Frank - 2010-04-20

    The code tag doesn't work - quote is no good either so I'm going to retry it without any tags and see if that looks better.

    Add two sources -

    'Sources
    #define Osc 1
    #define Ext 2
    #define ExtOsc 3
    #define FOsc 4
    #define CapOsc 5

    Replace the sub SInitTimer1 wih this -

    Sub SInitTimer1
    #ifdef bit(TMR1CS1)
    T1CON = TMR1Pres
    If TMR1Source = Ext Then
    Set TMR1CS1 On
    End If
    If TMR1Source = ExtOsc Then
    Set TMR1CS1 On
    Set T1OSCEN On
    End If
    If TMR1Source = FOsc Then
    Set TMR1CS0 on
    End If
    If TMR1Source = CapOsc Then
    Set TMR1CS0 on
    Set TMR1CS1 on
    End If
    #endif
    #ifndef bit(TMR1CS1)
    T1CON = TMR1Pres
    If TMR1Source = Ext Then
    Set TMR1CS On
    End If
    If TMR1Source = ExtOsc Then
    Set TMR1CS On
    Set T1OSCEN On
    End If
    #endif
    End Sub

    Frank

     

Log in to post a comment.