If you use Timer2 for your clock it leaves Timer1 free to be used with hardware capture. Then you can use capture to read your IR signal.
Here's an example tested with the SLED-C4. It only needs to test for the TMR2IF flag to keep time, so no interrupts are used. And you have quite a few instruction cycles to do other things between clock updates.
Code:
@ DEVICE LVP_OFF,WDT_OFF,MCLR_OFF,XT_OSC
DEFINE OSC 4
DEFINE DEBUG_REG PORTB
DEFINE DEBUG_BIT 0
DEFINE DEBUG_BAUD 19200
DEFINE DEBUG_MODE 0 ' SLED-C4 serial mode = true
' setup vars for clock
Time VAR WORD ' accumulates TMR2 to PR2 match counts
Minutes VAR BYTE ' minutes
Hours VAR BYTE ' hours
Match VAR PIR1.1 ' TMR2 to PR2 match interrupt flag bit
PORTB.0=1 ' make sure SLED-C4 data input pin idles high
TRISB = %00001000 ' RB3 = CCP1 capture input, rest outputs
CMCON = 7 ' disable comparators
INTCON = 0 ' not using interupts. Just monitoring int flag bits
PAUSE 250 ' let SLED-C4 power-up
Time = 0 ' clear TMR2 to PR2 match counter
Hours = 10 ' set clock starting hour here
Minutes = 03 ' set clock starting minutes here
' set SLED-C4 start time
DEBUG "D", Hours DIG 1,Hours DIG 0,Minutes DIG 1,Minutes DIG 0
' TMR2 increments from 0 until it matches the PR2 register value
' and then resets to 0 (on the next increment cycle) so place a
' value in PR2 1 cycle short of what you want. Here we want 250 for
' 60mS, so we write 249 to PR2.
PR2 = 249 ' 249 +1 extra cycle for reset = 250*16*15*1uS=60mS
Match = 0 ' clear match flag
' setup & start TMR2
T2CON = %01110110 ' 1:16 prescale, 1:15 postscale, TMR2 on
Main:
' every 60mS the TMR2IF flag is set, and this routine is entered.
' Plenty of time to do other stuff.
IF Match THEN ' has TMR2 matched PR2? (should happen every 60mS)
Match = 0 ' yes. clear TMR2 to PR2 match flag bit
Time = Time + 1 ' increment 60mS count
IF Time = 1000 THEN ' has 60 seconds (1000*60mS) passed?
Time = 0 ' yes. clear count
Minutes = Minutes + 1 ' increment minute count
IF Minutes = 60 THEN ' have 60 minutes passed?
Minutes = 0 ' yes. roll-over minutes from 59 to 00
Hours = Hours + 1 ' update hour every 60 minutes
IF Hours = 24 THEN Hours = 0 ' roll-over hours from 24 to 00
ENDIF
' print new time only once every minute
DEBUG "D", Hours DIG 1,Hours DIG 0,Minutes DIG 1,Minutes DIG 0
ENDIF
ENDIF
GOTO Main
END
It's pretty decent at keeping time. Ran for 3 hours, and it was spot-on with my PC clock to the second.
Bookmarks