Here is the code in case anyone wants to compile it. IntOSC is just the bits for the internal osc
Code: Select all
Device = 18F13K22
Clock = 16
Include "IntOSC.bas"
Include "USART.bas"
Include "utils.bas"
Include "convert.bas"
Config FOSC = IRC
Dim
SecondsCount As Byte,
MinutesCount As Byte,
HourCount As Byte,
TMR1IE As PIE1.0, // TMR1 Interrupt Enable
TMR1IF As PIR1.0, // TMR1 Interrupt Flag
// TMR1ON As T1CON.0, // TMR1 Count Enable
Timer1 As TMR1L.AsWord // A quick way of creating a Word Alias
Const
TMR1StartVal = $80, // User defined TMR1 starting value
TMR1ReloadVal = TMR1StartVal + 5
Interrupt TMR1_Interrupt()
Save(0) // Back up system variables
If TMR1IF = 1 Then
TMR1IF = 0 // Clear the TMR1 Interrupt
T1CON.0 = 0 //Turn timer 1 off
TMR1H = $80 //Preload high byte with 128
TMR1L = 0 // Preload Low byte with 0
T1CON.0 = 1 // timer 1 on
SecondsCount = SecondsCount + 1
If SecondsCount = 60 Then
MinutesCount= MinutesCount +1
SecondsCount = 0
End If
If MinutesCount = 60 Then
HourCount = HourCount +1
MinutesCount = 0
End If
USART.Write ("Hour:",32,DecToStr(HourCount),32,"Minutes:",32,DecToStr(MinutesCount),32, "Seconds:",32,DecToStr(SecondsCount),13,10)
EndIf
Restore // Restore system variables
End Interrupt
Sub TMR1_Initialize()
TRISC.0 = 1 // If External clock, then set clock as an input
T1CON.0 = 0 // Timer 1 off
TMR1H = $80 //Preload with 128
TMR1L = 0 //
T1CON.0 = 1 // timer 1 on
T1CON.1 = 1 // 1 = External clock from pin RC0/T1OSO/T1CKI (on the rising edge)
// 0 = Internal clock (FOSC/4)
T1CON.2 = 0 // 1 = Do not synchronize external clock input
// 0 = Synchronize external clock input
// When T1CON.1 = 0;
// this bit is ignored.
T1CON.3 = 1
T1CON.4 = 0
T1CON.5 = 0
T1CON.6 = 0
T1CON.7 = 0
TMR1IE = 1 // Enable TMR1 Interrupts
Enable(TMR1_Interrupt) // Enable TMR1 Interrupt Handle
End Sub
// Start Of Main Program...
SecondsCount = 0 //
MinutesCount = 0
HourCount = 0
TMR1_Initialize // Setup and enable TMR1
USART.SetBaudrate(br9600)
While True
Wend