Hello,
I am designing the application which should wait for the serial data and based on this do something. Also I should have in the same chip the clock and each minute perform some tasks. So I implemented the clock using tmr0 interrupt and I have a loop, which is waiting for the serial commands. It is working quite well, but I have problem, that my clock are not ticking well it is loosing each hour approx. 2 minutes. But I don't know why. Here is my code, I am using 16F916 with 4 Mhz external crystal resonator.

I have tmr0 prescaller in OPTION_REG = $d7 so I think, that tmr0 overflow happens 15 times per second. But seems, that it is not like this. Any suggestion?

DEFINE OSC 4
'hserin definition
DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 24h
DEFINE HSER_SPBRG 12 'DEFINE HSER_BAUD 19200 on 4 Mhz
DEFINE HSER_CLROERR 1
'variables for timer
day VAR BYTE ' Define day in the week
hour var byte ' Define hour variable
minute var byte ' Define minute variable
second var byte ' Define second variable
ticks var word ' Define pieces of seconds variable

'put port A to input output
ANSEL = 0
CMCON0= 255
' interrupt for timer
OPTION_REG = $d7
INTCON = $a0 'enable TMR0 interrupts and global interrupt
PIE1 = 0
On Interrupt Goto intManagement
clear

enable
while 1
if (manageIntSecond == 1) then
manageIntSecond = 0
second = second + 1
If second > 59 Then
second = 0
gosub manageIntMinute
ENDIF
endif
if (PIR1.5==1) then
HSERIN 10, main, [wait ("GET /"), COMMAND]
'do something here
HSEROUT ["Here I am..."]
main:
endif
wend
end

disable
intManagement:
if (INTCON.2 == 1) then
ticks = ticks + 1 ' Count pieces of seconds
If ticks >= 15 Then
if (ACTIVITY_LED == 1) then
low ACTIVITY_LED
else
high ACTIVITY_LED
endif
ticks = 0 'One second elasped - update time
manageIntSecond = 1
endif
INTCON.2 = 0
endif
INTCON.7 = 1
resume

enable
manageIntMinute:
minute = minute + 1 ' manage time update
If minute > 59 Then
minute = 0
hour = hour + 1
If hour > 23 Then
hour = 0
day = day + 1
if day > 6 THEN day = 0
Endif
Endif
return