PDA

View Full Version : HELP with Year counter



sanatana
- 20th February 2005, 15:48
Hello Everyone
I Need some of your expert help in solving my problem.
This what i am trying to do.
I want to be able to tell when 365 days has being reach on my data logger
I am using Pic18F452 and my Timer1 has already being used for a different task so i can't use that.
i am now trying to use the 1Hz pulse coming from my DS1307 connected to RB0 interupt pin.
But the problem is a word variable can only hold 65536 counts which is just over 18 hours but i want to count 24 hours
18x 60x60 =64800
24x60x60=86400
The idea is that if i can be able to to know when 1 day is reached all i have to do to check for when a year
has reached is to know when 365 days has being reached.


Hope to get your help
Santana

can i do something like this or any simpler way any of you might have would be much appreciated

DAY VAR WORD
TEMP_COUNT VAR WORD ' Count for 18 hrs
OVER_COUNT VAR WORD' Count for 6 hrs

DAY =0
TEMP_COUNT=0
OVER_COUNT=0


'MAIN PROGRAM HERE
'-------------------------------------

AGAIN:

GOSUB GET_ALARM
GOSUB GET_TEMP
GOSUB GET_TIME
gosub Get_Batt
@ SLEEP
PAUSE 200

GOTO AGAIN


END

' Interrupt handler
' ===========================
MYINT:

IF INTCON.1=1 Then
TEMP_COUNT=TEMP_COUNT+1
WHILE
TEMP_COUNT= > 64800 ' COUNT TO 18 HRS
OVER_COUNT= OVER_COUNT+1 ' IF 18HRS REACHED THEN START COUNT NEXT 6 HOURS
WEND
IF OVER_COUNT=21600 THEN
DAY = DAY +1
TEMP_COUNT=0 ' RESET COUNTERS
OVER_COUNT=0 ' RESET COUNTER
ENDIF
INTCON.1=0 ' Clear RB0 interrupt flag

mister_e
- 20th February 2005, 23:32
nested variable and if then... try this



second var byte
minute var byte
hours var byte
day var word
year var byte
clear

disable
Myint:
IF INTCON.1=1 Then
if second<60 then
second=second+1
else
second=0
if minute<60 then
minute = minute + 1
else
minute = 0
if hours < 24 then
hours = hours + 1
else
hours = 0
if day<365 then
day=day+1
else
day = 0
year = year + 1
endif
endif
endif
endif
endif
enable